QR Code and Barcode Detection
API reference for detecting and decoding QR codes, barcodes, and other graphical codes.GraphicalCodeDetector
Base class for graphical code detection and decoding.Methods
detect
Detects graphical code in image and returns the quadrangle containing the code.Grayscale or color (BGR) image containing (or not) graphical code
Output vector of vertices of the minimum-area quadrangle containing the code
true if a code is detected
decode
Decodes graphical code once it’s found by the detect() method.Grayscale or color (BGR) image containing graphical code
Quadrangle vertices found by detect() method
Optional output image containing binarized code
detectAndDecode
Both detects and decodes graphical code.Grayscale or color (BGR) image containing graphical code
Optional output array of vertices of the found graphical code quadrangle
Optional output image containing binarized code
detectMulti
Detects multiple graphical codes in image.Grayscale or color (BGR) image
Output vector of vector of vertices of the minimum-area quadrangles containing the codes
true if at least one code is detected
decodeMulti
Decodes multiple graphical codes.Grayscale or color (BGR) image containing graphical codes
Vector of quadrangle vertices found by detect() method
UTF8-encoded output vector of strings or empty vector if codes cannot be decoded
Optional output vector of images containing binarized codes
true if at least one code is decoded
detectAndDecodeMulti
Both detects and decodes multiple graphical codes.UTF8-encoded output vector of strings or empty vector if codes cannot be decoded
If there are QR codes encoded with Structured Append mode and all are detected and decoded correctly, the method writes the full message to the position corresponding to the 0-th code in the sequence. The rest of the QR codes from the same sequence have empty strings.
QRCodeDetector
QR code detector and decoder.Constructor
Methods
setEpsX
Sets the epsilon used during horizontal scan of QR code stop marker detection.Epsilon neighborhood for determining the horizontal pattern of the scheme 1:1:3:1:1 according to QR code standard
setEpsY
Sets the epsilon used during vertical scan of QR code stop marker detection.Epsilon neighborhood for determining the vertical pattern of the scheme 1:1:3:1:1 according to QR code standard
setUseAlignmentMarkers
Enables or disables use of alignment markers to improve corner position.Flag to enable alignment markers (enabled by default)
decodeCurved
Decodes QR code on a curved surface once found by detect().Grayscale or color (BGR) image containing QR code
Quadrangle vertices found by detect() method
Optional output image containing rectified and binarized QR code
detectAndDecodeCurved
Both detects and decodes QR code on a curved surface.getEncoding
Returns the encoding type for the decoded info from the latest decode call.Index of the previously decoded QR code. For single code detection, use 0.
Example Usage
- C++
- Python
QRCodeEncoder
QR code encoder for generating QR codes.Constructor
Use the staticcreate() method.
Enums
EncodeMode
CorrectionLevel
ECIEncodings
Params Structure
Methods
encode
Generates QR code from input string.Input string to encode
Generated QR code image
encodeStructuredAppend
Generates QR code in Structured Append mode, splitting the message over multiple QR codes.Input string to encode
Vector of generated QR code images
Example Usage
- C++
- Python
BarcodeDetector
Barcode detector and decoder. Inherits from GraphicalCodeDetector.Constructor
Prototxt file path for the super resolution model (optional)
Model file path for the super resolution model (optional)
Methods
decodeWithType
Decodes barcode in image once found by detect().Grayscale or color (BGR) image containing barcode
Vector of rotated rectangle vertices found by detect(). Order: bottomLeft, topLeft, topRight, bottomRight.
UTF8-encoded output vector of strings or empty if codes cannot be decoded
Vector of strings specifying the type of barcodes (e.g., “EAN_13”, “CODE_128”)
true if at least one valid barcode is found
detectAndDecodeWithType
Both detects and decodes barcode.Grayscale or color (BGR) image containing barcode
UTF8-encoded output vector of strings
Vector of strings specifying the barcode types
Optional output vector of vertices of the found barcode rectangle
true if at least one valid barcode is found
setDownsamplingThreshold
Sets detector downsampling threshold.Downsampling limit to apply (default 512). The detect method resizes the input image to this limit if the smallest dimension is greater than the threshold.
getDownsamplingThreshold
Gets detector downsampling threshold.setDetectorScales
Sets detector box filter sizes.Box filter sizes relative to minimum dimension of the image (default [0.01, 0.03, 0.06, 0.08])
Filter sizes directly correlate with the expected line widths for a barcode. If the downsampling limit is increased, filter sizes need to be adjusted inversely.
getDetectorScales
Gets detector box filter sizes.Output parameter for returning the sizes
setGradientThreshold
Sets detector gradient magnitude threshold.Gradient magnitude threshold (default 64). Values between 16 and 1024 generally work.
getGradientThreshold
Gets detector gradient magnitude threshold.Example Usage
- C++
- Python
Supported Barcode Types
The BarcodeDetector supports various 1D and 2D barcode formats:- EAN-8, EAN-13
- UPC-A, UPC-E
- Code 39, Code 93, Code 128
- ITF (Interleaved 2 of 5)
- Codabar
- QR Code
- DataMatrix
- PDF417
