Back to Adaptive Vision Library website

You are here: Start » Function Reference » Computer Vision » Barcodes » ReadSingleBarcode


Header: AVL.h
Namespace: avl
Module: Barcodes

Detects and recognizes a single barcode on the input image.

Applications: To be used as an easy all-in-one solution for typical barcode reading applications.


void avl::ReadSingleBarcode
	const avl::Image& inImage,
	atl::Optional<const avl::Rectangle2D&> inRoi,
	atl::Optional<const avl::CoordinateSystem2D&> inRoiAlignment,
	atl::Optional<avl::BarcodeFormat::Type> inBarcodeFormat,
	float inMinGradientLength,
	int inBaseBarWidth,
	int inDetectionScanCount,
	const int inReadingScanCount,
	const int inScanWidth,
	const float inMinStrength,
	const float inSmoothingStdDev,
	avl::Polarity::Type inPolarity,
	atl::Conditional<avl::Rectangle2D>& outBarcodePosition,
	atl::Conditional<atl::String>& outDecodedText,
	atl::Conditional<avl::BarcodeFormat::Type>& outBarcodeFormat,
	atl::Optional<atl::Conditional<avl::Polarity::Type>&> outBarcodePolarity = atl::NIL,
	atl::Optional<avl::Rectangle2D&> outAlignedRoi = atl::NIL,
	atl::Optional<atl::Array<avl::Rectangle2D>&> outBarcodeCandidates = atl::NIL,
	avl::Image& diagGradientImage,
	atl::Array<avl::Segment2D>& diagScheduledScanSegments


Name Type Range Default Description
Input value
inImage const Image& Input image
Input value
inRoi Optional<const Rectangle2D&> NIL Region of interest
Input value
inRoiAlignment Optional<const CoordinateSystem2D&> NIL Adjusts the region of interest to the position of the inspected object
Input value
inBarcodeFormat Optional<BarcodeFormat::Type> EAN13 Format of the barcode
Input value
inMinGradientLength float 0.0 - 8.0f Minimal gradient length of edge pixels used for detecting barcodes
Input value
inBaseBarWidth int 1 - 3 Estimated width of the thinnest bar
Input value
inDetectionScanCount int 1 - 5 Number of scan lines used in detecting barcode
Input value
inReadingScanCount const int 1 - 5 Number of parallel scans run until first successful read
Input value
inScanWidth const int 1 - 5 Width of the single scan
Input value
inMinStrength const float 0.0 - 5.0f Minimal strength of an extracted edge
Input value
inSmoothingStdDev const float 0.0 - 0.25f Standard deviation of the gaussian smoothing applied to the profile extracted in each scan
Input value
inPolarity Polarity::Type Dark Specifies whether code is darker or brighter than the background
Output value
outBarcodePosition Conditional<Rectangle2D>& Position of the found barcode
Output value
outDecodedText Conditional<String>& Decoded barcode content or nothing if all of the scans failed
Output value
outBarcodeFormat Conditional<BarcodeFormat::Type>& Decoded barcode format or nothing if all of the scans failed
Output value
outBarcodePolarity Optional<Conditional<Polarity::Type>&> NIL Decoded barcode polarity or nothing if all of the scans failed
Output value
outAlignedRoi Optional<Rectangle2D&> NIL Input ROI after transformation (in the image coordinates)
Output value
outBarcodeCandidates Optional<Array<Rectangle2D>&> NIL Places with high gradient values that are further investigated
Diagnostic input
diagGradientImage Image& Image of gradient directions
Diagnostic input
diagScheduledScanSegments Array<Segment2D>& Scheduled scan segments

Optional Outputs

The computation of following outputs can be switched off by passing value atl::NIL to these parameters: outBarcodePolarity, outAlignedRoi, outBarcodeCandidates.

Read more about Optional Outputs.


This filter works as a composition of DetectSingleBarcode and RecognizeBarcode filters.


  • Connect inImage with the output of your image acquisition filter.
  • Select inBarcodeFormat according to the type of codes you want to read. If you choose the wrong format, the codes will not be recognized. Setting its value to Auto can increase the computation time considerably. Furthermore, the Auto value causes detection of UPC-A codes as EAN-13 codes.
  • If the image quality is low, increase inMinGradientLength or increase inSmoothingStdDev. The diagGradientImage output shows how this affects an intermediate image.
  • If the image resolution is high, increase inBaseBarWidth or resize/downsample the input image.


Rotated barcode.

Low quality barcode printed on plastic foil.

Barcode on package wrapped in plastic foil.

Barcode in a blurry image.

Barcode on standard 330ml can.

Barcode on reflective and wrapped surface.

EAN-13 with add-on 2 used to indicate a book edition.

EAN-13 with add-on 5 to give a suggestion for the price.


Minimal bar width requirement

To provide precise detection of the barcode width of the thinnest bar should be at least 1.5 pixels.

Depending on the barcode format guard or start/end code patterns must be readable.

Pharmacode usage

The pharmacode barcode type can be read correctly in both directions. To get results from both directions use a Pharmacode and PharmacodeInversed barcode types.

Before decoding a Pharmacode the code orientation angle is normalized to a range from -45° to 135° what makes the code decoding more stable

Results of reading using a different Pharmacode directions: Pharmacode = 23 and PharmacodeInversed = 16.

Using a relative coordinate systems

Read more about Local Coordinate Systems in Machine Vision Guide: Local Coordinate Systems.

Hardware Acceleration

This operation supports automatic parallelization for multicore and multiprocessor systems.

See Also

  • DecodeBarcode – Translates an array of bar widths to sequence of digits or text in accordance to the selected barcode standard.
  • RecognizeBarcode – Extracts information from a barcode located on the input image at a given position.