C++

OPENALPRDLLEXPORT

namespacealpr

Enums

enumAlprHardwareAcceleration

Values:

enumeratorALPR_CPU

enumeratorALPRNVIDIAGPU

classAlpr

Public Functions

Alpr(const std::string country, const std::string configFile, const std::string runtimeDir, const std::string licenseKey)

Initialize the OpenALPR library. This operation should be performed once per thread.

Parameters

  • country: The country used for recognition (e.g., us for North American, eu for European, br for Brazil, etc.)

  • configFile: The path to the openalpr.conf file. Default is /etc/openalpr/openalpr.conf

  • runtimeDir: The path to the runtime_data directory. Default is /usr/share/openalpr/runtime_data/

  • licenseKey: The OpenALPR commercial license key

~Alpr()

Alpr(const std::string country, const std::string configFile = "", const std::string runtimeDir = "")

Deprecated - Legacy constructor to support existing symbols.

Alpr(const std::string country, const std::string configFile, const std::string runtimeDir, const std::string licenseKey, AlprHardwareAcceleration acceleration_type, int gpu_id = 0, int batch_size = 10)

Initialize the OpenALPR library. This operation should be performed once per thread. Overrides the configuration in openalpr.conf to set GPU usage explicitly

Parameters

  • country: The country used for recognition (e.g., us for North American, eu for European, br for Brazil, etc.)

  • configFile: The path to the openalpr.conf file. Default is /etc/openalpr/openalpr.conf

  • runtimeDir: The path to the runtime_data directory. Default is /usr/share/openalpr/runtime_data/

  • licenseKey: The OpenALPR commercial license key

  • acceleration_type: Nvidia GPU or CPU

  • gpu_id: The ID of the GPU to use. Default=0

  • batch_size: The number of images to process on the GPU simultaneously. Default=10

void setCountry(std::string country)

Set the country used for plate recognition

Parameters

  • country: Country code (e.g., us, eu, in, etc.)

void setPrewarp(std::string prewarp_config)

Deprecated. This function no longer functions. Since version 2.4.101, the accuracy at angles has improved that setting a prewarp value is no longer used. The parameter has a detrimental affect on both performance and accuracy. Simple image rotation in AlprStream can be handled with gstreamer parameters.

Parameters

  • prewarp_config: A specially constructed string produced by the openalpr_calibrate utility

void setMask(unsigned char *pixelData, int bytesPerPixel, int imgWidth, int imgHeight)

Update the detection mask without reloading the library. The detection mask is used to improve processing efficiency (by ignoring areas for recognition) and to reduce false positives (by disqualifying plates found in areas where there could not be plates).

The Mask is simply a black/white image that should match the input resolution of the images. If it does not match, it will be stretched to fit. The white portions are areas that should be included for processing and the black areas will be ignored.

Parameters

  • pixelData: raw image bytes for BGR channels

  • bytesPerPixel: Number of bytes for each pixel (e.g., 3)

  • imgWidth: Width of the image in pixels

  • imgHeight: Height of the image in pixels

void setDetectRegion(bool detectRegion)

Deprecated:

Enables/disables detection of state/province for applicable countries

Parameters

  • detectRegion: true to enable region detection, false to disable

void setTopN(int topN)

Set the maximum number of plate candidates to return

Parameters

  • topN: an integer specifying the maximum possible plate results to return (default: 10)

void setDefaultRegion(std::string region)

Specify a region to use when applying patterns. For example, if the camera is installed in Germany, and 90% of the license plates will be German plates, using a pattern of “de” would try to match the results against the German plate patterns and improve accuracy.

Parameters

  • region: The state/province to use as the default for pattern matching (e.g., md for USA/Maryland, be for Europe/Belgium).

AlprResults recognize(std::string filepath)

Recognize from an image on disk. The file should be an image in an encoded format such as JPG, PNG, BMP, GIF, etc.

ReturnThe results of the ALPR recognition for this imageParameters

  • filepath: Location of the file on disk (e.g., /tmp/image.jpg)

AlprResults recognize(std::vector<char> imageBytes)

Recognize from byte data representing an encoded image (e.g., BMP, PNG, JPG, GIF etc).

ReturnThe results of the ALPR recognition for this imageParameters

  • imageBytes: array of bytes for the image

AlprResults recognize(std::vector<char> imageBytes, std::vector<AlprRegionOfInterest> regionsOfInterest)

Recognize from byte data representing an encoded image (e.g., BMP, PNG, JPG, GIF etc).

ReturnThe results of the ALPR recognition for this imageParameters

  • imageBytes: Image bytes for the encoded image

  • regionsOfInterest: an array of regions to recognize. Areas not covered by a region of interest would be ignored. You may pass an empty array to scan the entire image.

AlprResults recognize(unsigned char *pixelData, int bytesPerPixel, int imgWidth, int imgHeight, std::vector<AlprRegionOfInterest> regionsOfInterest)

Recognize from raw pixel data.

ReturnThe results of the ALPR recognition for this imageParameters

  • pixelData: raw image bytes for BGR channels

  • bytesPerPixel: Number of bytes for each pixel (e.g., 3)

  • imgWidth: Width of the image in pixels

  • imgHeight: Height of the image in pixels

  • regionsOfInterest: an array of regions to recognize. Areas not covered by a region of interest would be ignored. You may pass an empty array to scan the entire image.

std::vector<AlprResults> recognize_batch(std::vector<std::vector<char>> imageBytes)

Recognize a batch of images from byte data representing encoded images (e.g., BMP, PNG, JPG, GIF etc).

ReturnThe results of the ALPR recognition for this imageParameters

  • imageBytes: An array of encoded image bytes

std::vector<AlprResults> recognize_batch(unsigned char **pixelData, int bytesPerPixel, int imgWidth, int imgHeight, int num_images, std::vector<std::vector<AlprRegionOfInterest>> regionsOfInterest)

Recognize a batch of images from raw pixel data. Batch processing is recommended when using a GPU for processing. Sending a batch of images allows the GPU to process them in parallel improving the overall efficiency.

ReturnThe results of the ALPR recognition for this imageParameters

  • pixelData: raw image bytes for BGR channels

  • bytesPerPixel: Number of bytes for each pixel (e.g., 3)

  • imgWidth: Width of the image in pixels

  • imgHeight: Height of the image in pixels

  • num_images: The number of images in the batch

  • regionsOfInterest: an array of regions to recognize. Areas not covered by a region of interest would be ignored. You may pass an empty array to scan the entire image.

bool isLoaded()

Verifies whether the OpenALPR instance was properly loaded

**Return**true if the engine is ready to use, false otherwise

bool getUseGpu()

int getGpuBatchSize()

int getGpuId()

Config *getConfig()

Public Static Functions

std::string toJson(const std::vector<AlprResults> results)

std::string toJson(const AlprResults results)

Deprecated: Converts the AlprResult object to JSON Use the toJson/fromJson on the AlprResults and AlprPlateResult classes

Returna properly formatted JSON string describing the ALPR resultsParameters

std::string toJson(const AlprPlateResult result)

AlprResults fromJson(std::string json)

std::string getVersion()

Gets the current version of the OpenALPR software

**Return**A version string (e.g., 2.4.102)

Private Members

AlprImpl *impl

structAlprCoordinate

Public Members

int x

int y

structAlprPlate #include <alpr.h>

An individual plate result.

Public Members

std::string characters

The string characters of the plate (e.g., ABC123)

float overall_confidence

The confidence score from 0-100.

bool matches_template

Whether the plate matches a template for the province.

classAlprPlateResult

Public Functions

AlprPlateResult()

~AlprPlateResult()

std::string toJson(bool serialize_crop = false)

Exports this object to a JSON representation.

Public Members

int requested_topn

The number requested is always >= the topNPlates count.

std::string country

The country (training data code) that was used to recognize the plate.

AlprPlate bestPlate

the best plate is the topNPlate with the highest confidence

std::vector<AlprPlate> topNPlates

A list of possible plate number permutations.

float processingtimems

The processing time for this plate.

AlprCoordinate plate_points[4]

the X/Y coordinates of the corners of the plate (clock-wise from top-left)

int plate_index

The index of the plate if there were multiple plates returned.

std::string region

When province detection is enabled, this returns the region (e.g., md).

int regionConfidence

The confidence for the detected region (0-100)

AlprRegionOfInterest vehicle_region

A bounding box where the car is likely to be found.

std::vector<unsigned char> platecropjpeg

A cropped image (encoded as a JPEG) for the plate.

Public Static Functions

AlprPlateResult fromJson(std::string json_string)

Rebuilds this object from a JSON string.

classAlprRegionOfInterest #include <alpr.h>

Specifies a region of interest to restrict the area that OpenALPR analyzes. The region(s) must be rectangular. The x,y positions are specified in pixels and correspond to the top left corners of the rectangle. The width and height are also specified in pixels. The coordinate system origin (0,0) is the top left of the image

Public Functions

AlprRegionOfInterest()

AlprRegionOfInterest(int x, int y, int width, int height)

Public Members

int x

int y

int width

int height

classAlprResults

Public Functions

AlprResults()

~AlprResults()

std::string toJson(bool serialize_crop = false)

Exports this object to a JSON representation.

Public Members

int64_t epoch_time

The time (in epoch ms) when the image for this image was captured.

int64_t frame_number

The relative frame number for this image.

int img_width int img_height

float totalprocessingtime_ms

The total processing time for detecting and recognizing all plates in the image.

std::string image_uuid

A globally unique ID for this image.

bool error

True if an error occurred during processing, false otherwise.

std::string error_message

An error message if there was an error processing.

std::vector<AlprPlateResult> plates

An array of plate results.

std::vector<AlprRegionOfInterest> regionsOfInterest

The regions of interest provided when requesting recognition.

Public Static Functions

AlprResults fromJson(std::string json_string)

Rebuilds this object from a JSON string.