Skip to content

barcode_BarcodeDetector

objdetectclassOpenCV 5.0.0
import { barcode_BarcodeDetector } from '@banou/opencv-wasm'

Use after await initOpenCV(). See the initialization and named imports guide.

ARGUMENTSConstructor or factory
CLASSbarcode_BarcodeDetector
RETURN TYPEOwned native handle
Call structure. A void return can still write to destination arguments. The parameter descriptions define inputs, outputs and ownership.

Native object: release it with using or delete(). Factories can return null; check before calling methods. Inherits GraphicalCodeDetector.

barcode barcode detector value in the OpenCV API.

Constructors and members

static new

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 https://github.com/WeChatCV/opencv_3rdparty/tree/wechat_qrcode).

new(super_resolution_model_path: EmbindString): barcode_BarcodeDetector;
2 available overloads
new(): barcode_BarcodeDetector;
new(super_resolution_model_path: EmbindString): barcode_BarcodeDetector;
super_resolution_model_path

path to a single-file ONNX Super Resolution model.

Returns

The barcode_BarcodeDetector result.

clone

Create another handle to the same native object. This retains the object without copying its pixels or algorithm state; dispose both handles separately.

clone(): this;
Returns

The this result.

decodeWithType

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

decodeWithType(img: Mat, points: Mat, decoded_info: StringVector, decoded_type: StringVector): boolean;
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<Point2f> is bottomLeft, topLeft, topRight, bottomRight.

decoded_info

Output destination, filled by the native operation. UTF8-encoded output vector of string or empty vector of string if the codes cannot be decoded.

decoded_type

Output destination, filled by the native operation. vector strings, specifies the type of these barcodes

Returns

true if at least one valid barcode have been found

detectAndDecodeWithType

Both detects and decodes barcode

detectAndDecodeWithType(img: Mat, decoded_info: StringVector, decoded_type: StringVector, points: Mat): boolean;
2 available overloads
detectAndDecodeWithType(img: Mat, decoded_info: StringVector, decoded_type: StringVector): boolean;
detectAndDecodeWithType(img: Mat, decoded_info: StringVector, decoded_type: StringVector, points: Mat): boolean;
img

grayscale or color (BGR) image containing barcode.

decoded_info

Output destination, filled by the native operation. UTF8-encoded output vector of string(s) or empty vector of string if the codes cannot be decoded.

decoded_type

Output destination, filled by the native operation. vector of strings, specifies the type of these barcodes

points

Output destination, filled by the native operation. 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

getDownsamplingThreshold

Get detector downsampling threshold.

getDownsamplingThreshold(): number;
Returns

detector downsampling threshold

setDownsamplingThreshold

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.

See: setDetectorScales

setDownsamplingThreshold(thresh: number): barcode_BarcodeDetector;
thresh

downsampling limit to apply (default 512)

Returns

The barcode_BarcodeDetector result.

getDetectorScales

Returns detector box filter sizes.

getDetectorScales(sizes: FloatVector): void;
sizes

Output destination, filled by the native operation. output parameter for returning the sizes.

setDetectorScales

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.

setDetectorScales(sizes: FloatVector): barcode_BarcodeDetector;
sizes

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

Returns

The barcode_BarcodeDetector result.

getGradientThreshold

Get detector gradient magnitude threshold.

getGradientThreshold(): number;
Returns

detector gradient magnitude threshold.

setGradientThreshold

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.

setGradientThreshold(thresh: number): barcode_BarcodeDetector;
thresh

gradient magnitude threshold (default 64).

Returns

The barcode_BarcodeDetector result.

These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.