liceHow to detect vehicle license plates in photos in Java
License plate recognition has a plethora of useful applications, but is usually locked behind the steep challenge of setting up a photo processing AI and then training it. Today, we will be skipping this difficult and time-consuming process, and should have our license plate recognition ready to go in just a few minutes using just a little Java and an API.
First we need to add references to Maven POM so that we can dynamically compile our library using Jitpack.
Repository Reference:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Dependency Reference:
<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v2.75</version>
</dependency>
</dependencies>
Now we call recognizeDetectVehicleLicensePlates, and let our API go to work for us.
// Import classes://import com.cloudmersive.client.invoker.ApiClient;//import com.cloudmersive.client.invoker.ApiException;//import com.cloudmersive.client.invoker.Configuration;//import com.cloudmersive.client.invoker.auth.*;//import com.cloudmersive.client.RecognizeApi;ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: ApikeyApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");Apikey.setApiKey("YOUR API KEY");// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.setApiKeyPrefix("Token");RecognizeApi apiInstance = new RecognizeApi();File imageFile = new File("/path/to/file"); // File | Image file to perform the operation on. Common file formats such as PNG, JPEG are supported.try {VehicleLicensePlateDetectionResult result = apiInstance.recognizeDetectVehicleLicensePlates(imageFile);System.out.println(result);} catch (ApiException e) {System.err.println("Exception when calling RecognizeApi#recognizeDetectVehicleLicensePlates");e.printStackTrace();}
And it’s really just as simple as that. Our response will be given in this format:
{
"Successful": true,
"DetectedLicensePlates": [
{
"LicensePlateText_BestMatch": "string",
"LicensePlateText_RunnerUp": "string",
"LocationX": 0,
"LocationY": 0,
"Width": 0,
"Height": 0,
"LicensePlateRecognitionConfidenceLevel": 0
}
],
"DetectedLicensePlateCount": 0
}