How to detect vehicle license plates in photos in Ruby

Detecting license plates and their numbers can be very useful, and today we will be looking at how to accomplish this task quickly and easily using one of our APIs. The first thing we shall do is add this line of code to our Gemfile:

gem 'cloudmersive-image-recognition-api-client', '~> 1.3.2'

Then call the function recognize_detect_vehicle_license_plates:

# load the gem
require 'cloudmersive-image-recognition-api-client'
# setup authorization
CloudmersiveImageRecognitionApiClient.configure do |config|
# Configure API key authorization: Apikey
config.api_key['Apikey'] = 'YOUR API KEY'
# Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
#config.api_key_prefix['Apikey'] = 'Bearer'
api_instance = CloudmersiveImageRecognitionApiClient::RecognizeApi.newimage_file ="/path/to/file") # File | Image file to perform the operation on. Common file formats such as PNG, JPEG are supported.begin
#Detect vehicle license plates in an image
result = api_instance.recognize_detect_vehicle_license_plates(image_file)
p result
rescue CloudmersiveImageRecognitionApiClient::ApiError => e
puts "Exception when calling RecognizeApi->recognize_detect_vehicle_license_plates: #{e}"

And we are all set. Let’s look at an example image:

Our results will look like this:

"Successful": true,
"DetectedLicensePlates": [
"LocationX": 561,
"LocationY": 451,
"Width": 65,
"Height": 32,
"LicensePlateText_BestMatch": "RTBB221",
"LicensePlateText_RunnerUp": "RBB22",
"LicensePlateRecognitionConfidenceLevel": 0.8885029602050781
"DetectedLicensePlateCount": 1

Notice that a lot of useful information is provided in the response, including the location and size and two possibilities for the license number along with its confidence in the results.

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

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