# C++

`OPENALPRDLLEXPORT`

***namespace***`alpr`

Enums

***enum***`AlprHardwareAcceleration`

*Values:*

***enumerator***`ALPR_CPU`

***enumerator***`ALPRNVIDIAGPU`

***class***`Alpr`

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](http://doc.openalpr.com/api.html#_CPPv4N4alpr24AlprHardwareAccelerationE) *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](http://doc.openalpr.com/api.html#classalpr_1_1AlprStream) 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**](http://doc.openalpr.com/api.html#_CPPv4N4alpr11AlprResultsE) `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**](http://doc.openalpr.com/api.html#_CPPv4N4alpr11AlprResultsE) `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**](http://doc.openalpr.com/api.html#_CPPv4N4alpr11AlprResultsE) `recognize`(std::vector\<char> *imageBytes*, std::vector<[AlprRegionOfInterest](http://doc.openalpr.com/api.html#_CPPv4N4alpr20AlprRegionOfInterestE)> *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**](http://doc.openalpr.com/api.html#_CPPv4N4alpr11AlprResultsE) `recognize`(unsigned char \**pixelData*, int *bytesPerPixel*, int *imgWidth*, int *imgHeight*, std::vector<[AlprRegionOfInterest](http://doc.openalpr.com/api.html#_CPPv4N4alpr20AlprRegionOfInterestE)> *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**](http://doc.openalpr.com/api.html#_CPPv4N4alpr11AlprResultsE)**>** `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**](http://doc.openalpr.com/api.html#_CPPv4N4alpr11AlprResultsE)**>** `recognize_batch`(unsigned char \*\**pixelData*, int *bytesPerPixel*, int *imgWidth*, int *imgHeight*, int *num\_images*, std::vector\<std::vector<[AlprRegionOfInterest](http://doc.openalpr.com/api.html#_CPPv4N4alpr20AlprRegionOfInterestE)>> *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](http://doc.openalpr.com/api.html#_CPPv4N4alpr11AlprResultsE)> *results*)

**std::string** `toJson`(*const* [AlprResults](http://doc.openalpr.com/api.html#_CPPv4N4alpr11AlprResultsE) *results*)

Deprecated: Converts the AlprResult object to JSON Use the toJson/fromJson on the [AlprResults](http://doc.openalpr.com/api.html#classalpr_1_1AlprResults) and [AlprPlateResult](http://doc.openalpr.com/api.html#classalpr_1_1AlprPlateResult) classes

**Returna properly formatted JSON string describing the ALPR resultsParameters**

* `results`: an [AlprResults](http://doc.openalpr.com/api.html#classalpr_1_1AlprResults) object to convert to JSON

**std::string** `toJson`(*const* [AlprPlateResult](http://doc.openalpr.com/api.html#_CPPv4N4alpr15AlprPlateResultE) *result*)

[**AlprResults**](http://doc.openalpr.com/api.html#_CPPv4N4alpr11AlprResultsE) `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`

***struct***`AlprCoordinate`

Public Members

**int** `x`

**int** `y`

***struct***`AlprPlate`\
\&#xNAN;*#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.

***class***`AlprPlateResult`

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**](http://doc.openalpr.com/api.html#_CPPv4N4alpr9AlprPlateE) `bestPlate`

the best plate is the topNPlate with the highest confidence

**std::vector<**[**AlprPlate**](http://doc.openalpr.com/api.html#_CPPv4N4alpr9AlprPlateE)**>** `topNPlates`

A list of possible plate number permutations.

**float** `processingtimems`

The processing time for this plate.

[**AlprCoordinate**](http://doc.openalpr.com/api.html#_CPPv4N4alpr14AlprCoordinateE) `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**](http://doc.openalpr.com/api.html#_CPPv4N4alpr20AlprRegionOfInterestE) `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**](http://doc.openalpr.com/api.html#_CPPv4N4alpr15AlprPlateResultE) `fromJson`(std::string *json\_string*)

Rebuilds this object from a JSON string.

***class***`AlprRegionOfInterest`\
\&#xNAN;*#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`

***class***`AlprResults`

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**](http://doc.openalpr.com/api.html#_CPPv4N4alpr15AlprPlateResultE)**>** `plates`

An array of plate results.

**std::vector<**[**AlprRegionOfInterest**](http://doc.openalpr.com/api.html#_CPPv4N4alpr20AlprRegionOfInterestE)**>** `regionsOfInterest`

The regions of interest provided when requesting recognition.

**Public Static Functions**

[**AlprResults**](http://doc.openalpr.com/api.html#_CPPv4N4alpr11AlprResultsE) `fromJson`(std::string *json\_string*)

Rebuilds this object from a JSON string.
