DetectBarCodePositions

#include "BIBRW1D.H"

 

BarCodePositionStruct * CALLBACK DetectBarCodePositions (
HANDLE    hDIB,
LPRECT            pRect,
BYTE                 nDilationSize,
UINT                 iMinimalBarNumber,
double                dMinimalSideLenghtRatio,
double                dMaxDistanceRatio,
UINT                 iEnlargePercent,
double                dMaxAngleDifference,
int *                    iBarCodeNum,
int *                    iErrorCode)

Description

The DetectBarCodePositions function searches for barcodes within the region of the input image specified in the parameters and returns the number of found barcodes and the position, orientation and the number of detected bars of each of them. Barcode position is the “smallest” rectangle containing the whole barcode. Returned Orientation is the orientation of the barcode, but this function only searches and does not decode the barcodes, so orientation is not periodical with 360 degrees, but 180 degrees. Because the DetectBarCodePosition function doesn’t decode the barcode therefore it can't decide whether or not it's left to right or right to left coded at the detected angle. Exact orientation can be determined by the decoding functions. The DetectBarCodePositions function finds a given barcode on an image only if the barcode is completely contained within the input parameters, and each bar is a different region. The bars cannot be connected.

For more information see Barcode Searching.

Parameters

HDIB

hDIB

Handle of the input DIB.

LPRECT

pRect

A rectangle specifying the area of the image where the barcode is. If all of the pRect values are zero, or pRect is NULL, the whole image is scanned.

BYTE

nDilationSize

If the barcode is very noisy, contains holes, inlet bumps, etc., a binary dilation can be used. This parameter specifies the size of the dilation matrix.

UINT

iMinimalBarNumber

Minimal bar number of barcodes to detect. The bar number is the number of Bars that the detected Barcode is consisting of. This value might be interesting in case of not being able to decode a detected barcode. Based on this value, you should be able to filter out invalid barcodes assuming that he is aware of how large barcode he is expecting on the image to scan. This might be even more useful in case of detecting barcode types which are always consisting of a specified number of Bars such as EAN types.

double

dMinimalSideLenghtRatio

Barcode bars are usually long and thin rectangles. This parameter specifies the minimal ratio of longer and shorter side of the smallest outscribed rectangle of a region that is determined as a bar.

double

dMaxDistanceRatio

This parameter specifies the maximal distance between two neighbouring bars. A given bar can be determined as a part of a barcode if the neighbouring bars are not farer than the width of the given bar multiplied by dMaxDistanceRatio.

UINT

iEnlargePercent

The returned position rectangle of a given barcode is computed by the bars of it. The smallest outscribed rectangle’s left coordinate is the smallest x value of the bar pixels, right coordinate is the smallest right value, etc. If after position detection the barcode has to be decoded, the rectangle must be greater than the smallest rectangle due to the criterias of the barcodes to decode, so during rectangle computation each bar are enlarged by iEnlargePercent.

double

dMaxAngleDifference

This parameter specifies the maximal angle difference between two neighbouring bars. For a given bar and it’s neighbour bar angle difference is defined as the angle difference between the bar’s normal vector and the line connecting the centroids of the two bars. Normal vector of a bar is a vector that starts from the centroid of a bar, and it’s direction is perpendicular to the bar direction. Centroid is the centerpoint of a bar.

int *

iBarCodeNum

iBarCodeNum is an integer buffer where the number of detected bars is to written out. The buffer must be allocated and freed up by the user.

int *

iErrorCode

iErrorCode is an integer buffer where the code of occurred error is to written out. The buffer must be allocated and freed up by the user. For possible values see Barcode Error codes.

Return values

This function returns an array of BarCodePositionStruct values. The returned array contains iBarCodeNum number of values. The array is allocated by the function but has to be freed up by the user (GlobalFree). Use GlobalLock to access the array values. For more information about BarCodePositionStruct see the Constant Values and Structures section.

Programming notes

Requirements

Header :     Declared in BIBrw1d.h; include BIBrw1d.h.

Library :    Use BIBrw1d.lib  (32 bit version) or BIBrw1dx.lib (64 bit version).

DLLs :       BIBrw1d.dll  (32 bit version) or BIBrw1dx.dll (64 bit version).