Sign in

How to detect vehicle license plates in photos using C# in .NET Framework

Manually extracting vehicle license plate information is an easy but time-consuming process. Automating this process is generally a bit more difficult, requiring experience with AI deep learning and a good deal of processing power. Instead, how about we get some results in just a couple of minutes.

First, go to your Package Manager console and run the following snippet to install our API client:

Install-Package Cloudmersive.APIClient.NET.ImageRecognition -Version 1.3.5

Now let’s call the RecognizeDetectVehicleLicensePlates function using the following code:

using System;
using System.Diagnostics;
using Cloudmersive.APIClient.NET.ImageRecognition.Api;
using Cloudmersive.APIClient.NET.ImageRecognition.Client;
using Cloudmersive.APIClient.NET.ImageRecognition.Model;
namespace Example
{
public class RecognizeDetectVehicleLicensePlatesExample
{
public void main()
{
// Configure API key authorization: Apikey
Configuration.Default.AddApiKey("Apikey", "YOUR_API_KEY");
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// Configuration.Default.AddApiKeyPrefix("Apikey", "Bearer");
var apiInstance = new RecognizeApi();
var imageFile = new System.IO.Stream(); // System.IO.Stream | Image file to perform the operation on. Common file formats such as PNG, JPEG are supported.
try
{
// Detect vehicle license plates in an image
VehicleLicensePlateDetectionResult result = apiInstance.RecognizeDetectVehicleLicensePlates(imageFile);
Debug.WriteLine(result);
}
catch (Exception e)
{
Debug.Print("Exception when calling RecognizeApi.RecognizeDetectVehicleLicensePlates: " + e.Message );
}
}
}
}

And it’s as simple as that! Let’s try it out with the following image:

Image for post
Image for post

And here is our response:

{
"Successful": true,
"DetectedLicensePlates": [
{
"LicensePlateText_BestMatch": "P033086",
"LicensePlateText_RunnerUp": "033086",
"LocationX": 215,
"LocationY": 276,
"Width": 94,
"Height": 51,
"LicensePlateRecognitionConfidenceLevel": 0.8478269958496094
}
],
"DetectedLicensePlateCount": 1
}

Along with whether the function was successful, we are given the number of plates present, their locations, two guesses at the text of each plate, and confidence levels for said text.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store