Barcode detection and decoding#

Classes#

Class cv::barcode::BarcodeDetector#

Collaboration diagram for cv::barcode::BarcodeDetector:

Public Member Functions#

Public Member Functions inherited from cv::GraphicalCodeDetector

Additional Inherited Members#

Protected Attributes inherited from cv::GraphicalCodeDetector

Return

Name

Description

Ptr< Impl >

p

Constructor & Destructor Documentation#

BarcodeDetector()#

cv::barcode::BarcodeDetector::BarcodeDetector()

Python:

cv.barcode.BarcodeDetector() -> <barcode_BarcodeDetector object>
cv.barcode.BarcodeDetector(super_resolution_model_path) -> <barcode_BarcodeDetector object>

Initialize the BarcodeDetector. Super resolution is disabled.

BarcodeDetector()#

cv::barcode::BarcodeDetector::BarcodeDetector(CV_WRAP_FILE_PATH const std::string & super_resolution_model_path)

Python:

cv.barcode.BarcodeDetector() -> <barcode_BarcodeDetector object>
cv.barcode.BarcodeDetector(super_resolution_model_path) -> <barcode_BarcodeDetector object>

Initialize the BarcodeDetector with a Super Resolution model.

Loads a Super Resolution DNN model in ONNX format, used to upscale small/low-quality barcode crops before decoding for better quality.

Note

Caffe models (sr.prototxt / sr.caffemodel) are no longer supported; convert the model to ONNX (a converted sr.onnx is available from WeChatCV/opencv_3rdparty).

Parameters

  • super_resolution_model_path — path to a single-file ONNX Super Resolution model.

~BarcodeDetector()#

cv::barcode::BarcodeDetector::~BarcodeDetector()

Member Function Documentation#

decodeWithType()#

bool cv::barcode::BarcodeDetector::decodeWithType(
InputArray img,
InputArray points,
std::vector< std::string > & decoded_info,
std::vector< std::string > & decoded_type )

Python:

cv.barcode.BarcodeDetector.decodeWithType(img, points) -> retval, decoded_info, decoded_type

Decodes barcode in image once it’s found by the detect() method.

Parameters

  • img — grayscale or color (BGR) image containing bar code.

  • points — vector of rotated rectangle vertices found by detect() method (or some other algorithm). For N detected barcodes, the dimensions of this array should be [N][4]. Order of four points in vector is bottomLeft, topLeft, topRight, bottomRight.

  • decoded_info — UTF8-encoded output vector of string or empty vector of string if the codes cannot be decoded.

  • decoded_type — vector strings, specifies the type of these barcodes

Returns

true if at least one valid barcode have been found

detectAndDecodeWithType()#

bool cv::barcode::BarcodeDetector::detectAndDecodeWithType(
InputArray img,
std::vector< std::string > & decoded_info,
std::vector< std::string > & decoded_type,
OutputArray points = noArray() )

Python:

cv.barcode.BarcodeDetector.detectAndDecodeWithType(img[, points]) -> retval, decoded_info, decoded_type, points

Both detects and decodes barcode.

Parameters

  • img — grayscale or color (BGR) image containing barcode.

  • decoded_info — UTF8-encoded output vector of string(s) or empty vector of string if the codes cannot be decoded.

  • decoded_type — vector of strings, specifies the type of these barcodes

  • points — optional output vector of vertices of the found barcode rectangle. Will be empty if not found.

Returns

true if at least one valid barcode have been found

Here is the call graph for this function:

cv::barcode::BarcodeDetector::detectAndDecodeWithType Node1 cv::barcode::BarcodeDetector ::detectAndDecodeWithType Node2 cv::noArray Node1->Node2

cv::barcode::BarcodeDetector::detectAndDecodeWithType Node1 cv::barcode::BarcodeDetector ::detectAndDecodeWithType Node2 cv::noArray Node1->Node2

getDetectorScales()#

void cv::barcode::BarcodeDetector::getDetectorScales(std::vector< float > & sizes)

Python:

cv.barcode.BarcodeDetector.getDetectorScales() -> sizes

Returns detector box filter sizes.

Parameters

  • sizes — output parameter for returning the sizes.

getDownsamplingThreshold()#

double cv::barcode::BarcodeDetector::getDownsamplingThreshold()

Python:

cv.barcode.BarcodeDetector.getDownsamplingThreshold() -> retval

Get detector downsampling threshold.

Returns

detector downsampling threshold

getGradientThreshold()#

double cv::barcode::BarcodeDetector::getGradientThreshold()

Python:

cv.barcode.BarcodeDetector.getGradientThreshold() -> retval

Get detector gradient magnitude threshold.

Returns

detector gradient magnitude threshold.

setDetectorScales()#

BarcodeDetector & cv::barcode::BarcodeDetector::setDetectorScales(const std::vector< float > & sizes)

Python:

cv.barcode.BarcodeDetector.setDetectorScales(sizes) -> retval

Set detector box filter sizes.

Adjusts the value and the number of box filters used in the detect step. The filter sizes directly correlate with the expected line widths for a barcode. Corresponds to expected barcode distance. If the downsampling limit is increased, filter sizes need to be adjusted in an inversely proportional way.

Parameters

  • sizes — box filter sizes, relative to minimum dimension of the image (default [0.01, 0.03, 0.06, 0.08])

setDownsamplingThreshold()#

BarcodeDetector & cv::barcode::BarcodeDetector::setDownsamplingThreshold(double thresh)

Python:

cv.barcode.BarcodeDetector.setDownsamplingThreshold(thresh) -> retval

Set detector downsampling threshold.

By default, the detect method resizes the input image to this limit if the smallest image size is is greater than the threshold. Increasing this value can improve detection accuracy and the number of results at the expense of performance. Correlates with detector scales. Setting this to a large value will disable downsampling.

Parameters

  • thresh — downsampling limit to apply (default 512)

setGradientThreshold()#

BarcodeDetector & cv::barcode::BarcodeDetector::setGradientThreshold(double thresh)

Python:

cv.barcode.BarcodeDetector.setGradientThreshold(thresh) -> retval

Set detector gradient magnitude threshold.

Sets the coherence threshold for detected bounding boxes. Increasing this value will generate a closer fitted bounding box width and can reduce false-positives. Values between 16 and 1024 generally work, while too high of a value will remove valid detections.

Parameters

  • thresh — gradient magnitude threshold (default 64).

Source file#

The documentation for this class was generated from the following file: