|
static PIX * | pixGenerateBarcodeMask (PIX *pixs, l_int32 maxspace, l_int32 nwidth, l_int32 nheight) |
|
static NUMA * | pixAverageRasterScans (PIX *pixs, l_int32 nscans) |
|
static l_int32 | numaGetCrossingDistances (NUMA *nas, NUMA **pnaedist, NUMA **pnaodist, l_float32 *pmindist, l_float32 *pmaxdist) |
|
static NUMA * | numaLocatePeakRanges (NUMA *nas, l_float32 minfirst, l_float32 minsep, l_float32 maxmin) |
|
static NUMA * | numaGetPeakCentroids (NUMA *nahist, NUMA *narange) |
|
static NUMA * | numaGetPeakWidthLUT (NUMA *narange, NUMA *nacent) |
|
static l_int32 | numaEvalBestWidthAndShift (NUMA *nas, l_int32 nwidth, l_int32 nshift, l_float32 minwidth, l_float32 maxwidth, l_float32 *pbestwidth, l_float32 *pbestshift, l_float32 *pbestscore) |
|
static l_int32 | numaEvalSyncError (NUMA *nas, l_int32 ifirst, l_int32 ilast, l_float32 width, l_float32 shift, l_float32 *pscore, NUMA **pnad) |
|
SARRAY * | pixProcessBarcodes (PIX *pixs, l_int32 format, l_int32 method, SARRAY **psaw, l_int32 debugflag) |
|
PIXA * | pixExtractBarcodes (PIX *pixs, l_int32 debugflag) |
|
SARRAY * | pixReadBarcodes (PIXA *pixa, l_int32 format, l_int32 method, SARRAY **psaw, l_int32 debugflag) |
|
NUMA * | pixReadBarcodeWidths (PIX *pixs, l_int32 method, l_int32 debugflag) |
|
BOXA * | pixLocateBarcodes (PIX *pixs, l_int32 thresh, PIX **ppixb, PIX **ppixm) |
|
PIX * | pixDeskewBarcode (PIX *pixs, PIX *pixb, BOX *box, l_int32 margin, l_int32 threshold, l_float32 *pangle, l_float32 *pconf) |
|
NUMA * | pixExtractBarcodeWidths1 (PIX *pixs, l_float32 thresh, l_float32 binfract, NUMA **pnaehist, NUMA **pnaohist, l_int32 debugflag) |
|
NUMA * | pixExtractBarcodeWidths2 (PIX *pixs, l_float32 thresh, l_float32 *pwidth, NUMA **pnac, l_int32 debugflag) |
|
NUMA * | pixExtractBarcodeCrossings (PIX *pixs, l_float32 thresh, l_int32 debugflag) |
|
NUMA * | numaQuantizeCrossingsByWidth (NUMA *nas, l_float32 binfract, NUMA **pnaehist, NUMA **pnaohist, l_int32 debugflag) |
|
NUMA * | numaQuantizeCrossingsByWindow (NUMA *nas, l_float32 ratio, l_float32 *pwidth, l_float32 *pfirstloc, NUMA **pnac, l_int32 debugflag) |
|
Basic operations to locate and identify the line widths
in 1D barcodes.
Top level
SARRAY *pixProcessBarcodes()
Next levels
PIXA *pixExtractBarcodes()
SARRAY *pixReadBarcodes()
l_int32 pixReadBarcodeWidths()
Location
BOXA *pixLocateBarcodes()
static PIX *pixGenerateBarcodeMask()
Extraction and deskew
PIXA *pixDeskewBarcodes()
Process to get line widths
NUMA *pixExtractBarcodeWidths1()
NUMA *pixExtractBarcodeWidths2()
NUMA *pixExtractBarcodeCrossings()
Average adjacent rasters
static NUMA *pixAverageRasterScans()
Signal processing for barcode widths
NUMA *numaQuantizeCrossingsByWidth()
static l_int32 numaGetCrossingDistances()
static NUMA *numaLocatePeakRanges()
static NUMA *numaGetPeakCentroids()
static NUMA *numaGetPeakWidthLUT()
NUMA *numaQuantizeCrossingsByWindow()
static l_int32 numaEvalBestWidthAndShift()
static l_int32 numaEvalSyncError()
NOTE CAREFULLY: This is "early beta" code. It has not been tuned
to work robustly on a large database of barcode images. I'm putting
it out so that people can play with it, find out how it breaks, and
contribute decoders for other barcode formats. Both the functional
interfaces and ABI will almost certainly change in the coming
few months. The actual decoder, in bardecode.c, at present only
works on the following codes: Code I2of5, Code 2of5, Code 39, Code 93
Codabar and UPCA. To add another barcode format, it is necessary
to make changes in readbarcode.h and bardecode.c.
The program prog/barcodetest shows how to run from the top level
(image --> decoded data).
Definition in file readbarcode.c.
static l_int32 numaEvalBestWidthAndShift |
( |
NUMA * |
nas, |
|
|
l_int32 |
nwidth, |
|
|
l_int32 |
nshift, |
|
|
l_float32 |
minwidth, |
|
|
l_float32 |
maxwidth, |
|
|
l_float32 * |
pbestwidth, |
|
|
l_float32 * |
pbestshift, |
|
|
l_float32 * |
pbestscore |
|
) |
| |
|
static |
numaEvalBestWidthAndShift()
- Parameters
-
[in] | nas | numa of crossing locations |
[in] | nwidth | number of widths to consider |
[in] | nshift | number of shifts to consider for each width |
[in] | minwidth | smallest width to consider |
[in] | maxwidth | largest width to consider |
[out] | pbestwidth | best size of window |
[out] | pbestshift | best shift for the window |
[out] | pbestscore | [optional] average squared error of dist of crossing signal from the center of the window |
- Returns
- 0 if OK, 1 on error
Notes:
(1) This does a linear sweep of widths, evaluating at nshift
shifts for each width, finding the (width, shift) pair that
gives the minimum score.
Definition at line 1379 of file readbarcode.c.
References lept_stderr(), and numaEvalSyncError().
Referenced by numaQuantizeCrossingsByWindow().
static l_int32 numaEvalSyncError |
( |
NUMA * |
nas, |
|
|
l_int32 |
ifirst, |
|
|
l_int32 |
ilast, |
|
|
l_float32 |
width, |
|
|
l_float32 |
shift, |
|
|
l_float32 * |
pscore, |
|
|
NUMA ** |
pnad |
|
) |
| |
|
static |
numaEvalSyncError()
- Parameters
-
[in] | nas | numa of crossing locations |
[in] | ifirst | first crossing to use |
[in] | ilast | last crossing to use; use 0 for all crossings |
[in] | width | size of window |
[in] | shift | of center of window w/rt first crossing |
[out] | pscore | [optional] average squared error of dist of crossing signal from the center of the window |
[out] | pnad | [optional] numa of 1s and 0s for crossings |
- Returns
- 0 if OK, 1 on error
Notes:
(1) The score is computed only on the part of the signal from the
ifirst to ilast crossings. Use 0 for both of these to
use all the crossings. The score is normalized for
the number of crossings and with half-width of the window.
(2) The optional return nad is a sequence of 0s and 1s, where a '1'
indicates a crossing in the window.
Definition at line 1451 of file readbarcode.c.
References numaCreate(), numaDestroy(), numaGetCount(), numaGetFValue(), numaGetIValue(), numaSetCount(), and numaSetValue().
Referenced by numaEvalBestWidthAndShift(), and numaQuantizeCrossingsByWindow().
static l_int32 numaGetCrossingDistances |
( |
NUMA * |
nas, |
|
|
NUMA ** |
pnaedist, |
|
|
NUMA ** |
pnaodist, |
|
|
l_float32 * |
pmindist, |
|
|
l_float32 * |
pmaxdist |
|
) |
| |
|
static |
numaGetCrossingDistances()
- Parameters
-
[in] | nas | numa of crossing locations |
[out] | pnaedist | [optional] even distances between crossings |
[out] | pnaodist | [optional] odd distances between crossings |
[out] | pmindist | [optional] min distance between crossings |
[out] | pmaxdist | [optional] max distance between crossings |
- Returns
- 0 if OK, 1 on error
Definition at line 1001 of file readbarcode.c.
References numaAddNumber(), numaCopy(), numaCreate(), numaDestroy(), numaGetCount(), numaGetFValue(), numaHistogramGetValFromRank(), numaJoin(), and numaMakeHistogram().
Referenced by numaQuantizeCrossingsByWidth(), and numaQuantizeCrossingsByWindow().
static NUMA * numaGetPeakWidthLUT |
( |
NUMA * |
narange, |
|
|
NUMA * |
nacent |
|
) |
| |
|
static |
numaGetPeakWidthLUT()
- Parameters
-
[in] | narange | numa of x-val ranges for the histogram width peaks |
[in] | nacent | numa of centroids of each peak – up to 4 |
- Returns
- nalut lookup table from the width of a bar to one of the four integerized barcode units, or NULL on error
Notes:
(1) This generates the lookup table that maps from a sequence of widths
(in some units) to the integerized barcode units (1, 2, 3, 4),
which are the output integer widths between transitions.
(2) The smallest width can be lost in float roundoff. To avoid
losing it, we expand the peak range of the smallest width.
Definition at line 1189 of file readbarcode.c.
References L_NOCOPY, numaCreate(), numaGetCount(), numaGetFArray(), numaGetIValue(), numaGetMax(), numaSetCount(), and numaSetValue().
static NUMA * numaLocatePeakRanges |
( |
NUMA * |
nas, |
|
|
l_float32 |
minfirst, |
|
|
l_float32 |
minsep, |
|
|
l_float32 |
maxmin |
|
) |
| |
|
static |
numaLocatePeakRanges()
- Parameters
-
[in] | nas | numa of histogram of crossing widths |
[in] | minfirst | min location of center of first peak |
[in] | minsep | min separation between peak range centers |
[in] | maxmin | max allowed value for min histo value between peaks |
- Returns
- nad ranges for each peak found, in pairs, or NULL on error
Notes:
(1) Units of minsep are the index into nas.
This puts useful constraints on peak-finding.
(2) If maxmin == 0.0, the value of nas[i] must go to 0.0 (or less)
between peaks.
(3) All calculations are done in units of the index into nas.
The resulting ranges are therefore integers.
(4) The output nad gives pairs of range values for successive peaks.
Any location [i] for which maxmin = nas[i] = 0.0 will NOT be
included in a peak range. This works fine for histograms where
if nas[i] == 0.0, it means that there are no samples at [i].
(5) For barcodes, when this is used on a histogram of barcode
widths, use maxmin = 0.0. This requires that there is at
least one histogram bin corresponding to a width value between
adjacent peak ranges that is unpopulated, making the separation
of the histogram peaks unambiguous.
Definition at line 1089 of file readbarcode.c.
References numaAddNumber(), numaCreate(), numaGetCount(), numaGetFValue(), and numaSetValue().
NUMA* numaQuantizeCrossingsByWidth |
( |
NUMA * |
nas, |
|
|
l_float32 |
binfract, |
|
|
NUMA ** |
pnaehist, |
|
|
NUMA ** |
pnaohist, |
|
|
l_int32 |
debugflag |
|
) |
| |
numaQuantizeCrossingsByWidth()
- Parameters
-
[in] | nas | numa of crossing locations, in pixel units |
[in] | binfract | histo binsize as a fraction of minsize; e.g., 0.25 |
[out] | pnaehist | [optional] histo of even (black) bar widths |
[out] | pnaohist | [optional] histo of odd (white) bar widths |
[in] | debugflag | 1 to generate plots of histograms of bar widths |
- Returns
- nad sequence of widths, in unit sizes, or NULL on error
Notes:
(1) This first computes the histogram of black and white bar widths,
binned in appropriate units. There should be well-defined
peaks, each corresponding to a specific width. The sequence
of barcode widths (namely, the integers from the set {1,2,3,4})
is returned.
(2) The optional returned histograms are binned in width units
that are inversely proportional to binfract. For example,
if binfract = 0.25, there are 4.0 bins in the distance of
the width of the narrowest bar.
Definition at line 848 of file readbarcode.c.
References gplotCreate(), lept_mkdir(), numaDestroy(), numaGetCount(), numaGetCrossingDistances(), and numaMakeHistogramClipped().
NUMA* numaQuantizeCrossingsByWindow |
( |
NUMA * |
nas, |
|
|
l_float32 |
ratio, |
|
|
l_float32 * |
pwidth, |
|
|
l_float32 * |
pfirstloc, |
|
|
NUMA ** |
pnac, |
|
|
l_int32 |
debugflag |
|
) |
| |
numaQuantizeCrossingsByWindow()
- Parameters
-
[in] | nas | numa of crossing locations |
[in] | ratio | of max window size over min window size in search; typ. 2.0 |
[out] | pwidth | [optional] best window width |
[out] | pfirstloc | [optional] center of window for first xing |
[out] | pnac | [optional] array of window crossings (0, 1, 2) |
[in] | debugflag | 1 to generate various plots of intermediate results |
- Returns
- nad sequence of widths, in unit sizes, or NULL on error
Notes:
(1) The minimum size of the window is set by the minimum
distance between zero crossings.
(2) The optional return signal nac is a sequence of 0s, 1s,
and perhaps a few 2s, giving the number of crossings in each window.
On the occasion where there is a '2', it is interpreted as
ending two runs: the previous one and another one that has length 1.
Definition at line 1279 of file readbarcode.c.
References numaAddNumber(), numaCreate(), numaDestroy(), numaEvalBestWidthAndShift(), numaEvalSyncError(), numaGetCount(), numaGetCrossingDistances(), numaGetFValue(), and numaGetIValue().
NUMA* pixExtractBarcodeWidths1 |
( |
PIX * |
pixs, |
|
|
l_float32 |
thresh, |
|
|
l_float32 |
binfract, |
|
|
NUMA ** |
pnaehist, |
|
|
NUMA ** |
pnaohist, |
|
|
l_int32 |
debugflag |
|
) |
| |
pixExtractBarcodeWidths1()
- Parameters
-
[in] | pixs | input image; 8 bpp |
[in] | thresh | estimated pixel threshold for crossing white <--> black; typ. ~120 |
[in] | binfract | histo binsize as a fraction of minsize; e.g., 0.25 |
[out] | pnaehist | [optional] histogram of black widths; NULL ok |
[out] | pnaohist | [optional] histogram of white widths; NULL ok |
[in] | debugflag | use 1 to generate debug output |
- Returns
- nad numa of barcode widths in encoded integer units, or NULL on error
Notes:
(1) The widths are alternating black/white, starting with black
and ending with black.
(2) This method uses the widths of the bars directly, in terms
of the (float) number of pixels between transitions.
The histograms of these widths for black and white bars is
generated and interpreted.
Definition at line 628 of file readbarcode.c.
NUMA* pixExtractBarcodeWidths2 |
( |
PIX * |
pixs, |
|
|
l_float32 |
thresh, |
|
|
l_float32 * |
pwidth, |
|
|
NUMA ** |
pnac, |
|
|
l_int32 |
debugflag |
|
) |
| |
pixExtractBarcodeWidths2()
- Parameters
-
[in] | pixs | input image; 8 bpp |
[in] | thresh | estimated pixel threshold for crossing white <--> black; typ. ~120 |
[out] | pwidth | [optional] best decoding window width, in pixels |
[out] | pnac | [optional] number of transitions in each window |
[in] | debugflag | use 1 to generate debug output |
- Returns
- nad numa of barcode widths in encoded integer units, or NULL on error
Notes:
(1) The widths are alternating black/white, starting with black
and ending with black.
(2) The optional best decoding window width is the width of the window
that is used to make a decision about whether a transition occurs.
It is approximately the average width in pixels of the narrowest
white and black bars (i.e., those corresponding to unit width).
(3) The optional return signal nac is a sequence of 0s, 1s,
and perhaps a few 2s, giving the number of crossings in each window.
On the occasion where there is a '2', it is interpreted as
as ending two runs: the previous one and another one that has length 1.
Definition at line 682 of file readbarcode.c.