Another improvement of the C++ port of the PDF417 Detector

37 views
Skip to first unread message

hfneubauer-home

unread,
Feb 26, 2013, 3:09:12 PM2/26/13
to zx...@googlegroups.com
Hi all,

hereby I commit the latest version of the PDF417 DetectorPD.cpp. As the origin I took the latest commit of "DetectorPD.cpp" in the GIT trunk of Christoph Schulz, not my own Windows CE version. Here is the difference: (the added codeparts are printed in bold letters)




Ref<BitMatrix> Detector::specialGrid(Ref<BitMatrix> image,
                                     
int dimensionX,
                                     
int dimensionY,
                                     
DecodeHints const& hints)
{
 
int x,y,yy,col,BarCount = 0;
 
bool IsBar = false;

 
int dimensionXOrg = image->getWidth();
 
int dimensionYNew = hints.getTryHarder() ? dimensionY * 2 : dimensionY;
 
Ref<BitMatrix> bits(new BitMatrix(dimensionX, dimensionYNew));
  std
::vector<int> BarWidths(dimensionX,0);
 
for (y = 0; y < dimensionY; y++) {
   
for(col=0;col<dimensionX;col++)
     
BarWidths[col]=0;
   
/*...*/

   
   
//* Now find the bars where the symbols start. Normally each symbol consists of 4 bars + 4 spaces.
   
//* But we know the number of symbols per line, and we want to know the starting points of
   
//* the symbols more exactly.
   
BarCount++;
   
int NumberOfSymbolsPerLine = dimensionX / MODULES_IN_SYMBOL;
   
int len_cw = NumberOfSymbolsPerLine != 0 ? dimensionXOrg / NumberOfSymbolsPerLine : dimensionXOrg;
   
int sum;
    std
::vector<int> starts_symbols(NumberOfSymbolsPerLine,0);
    std
::vector<int> sums_bars(BarCount,0);

 
  /**
     * 2013-02-21 hfn: if the number of bars/spaces is eight times the number of symbols
     * (codewords) per line, as expected, we now assume that every symbol consists of eight
     * bars/spaces; without the following "if....else" block, maybe an accurate code image
     * would not be decoded because of perspective distortion. Therefore:
     **/

   
if(BarCount == 8 * NumberOfSymbolsPerLine) {
     
for(yy=0;yy<NumberOfSymbolsPerLine;yy++) {
        starts_symbols
[yy] = (yy + 1) * 8;
     
}
   
}
   
else {
 
    for(x=0,sum=0;x<BarCount;x++) {
        sum
+=BarWidths[x];
        sums_bars
[x]=sum % len_cw;
        yy
= len_cw - sums_bars[x];
       
if(yy < sums_bars[x])
          sums_bars
[x] = yy;
     
}
     
//* Search the positions where the symbols begin. Each codeword begins with a black bar and
     
//* ends with a space (white bar).
      yy
= 0;
     
for(x=3;x<BarCount;x+=2) {
       
if(sums_bars[x] < sums_bars[x-2] && (x >= BarCount - 2 || sums_bars[x] < sums_bars[x+2])
         
&& yy < NumberOfSymbolsPerLine) {
          starts_symbols
[yy++] = x + 1;
       
}
     
}
    }
#if (defined DEBUG && defined _WIN32)
   
/* ... */
#endif

The reason is that, without this difference, sometimes it happens that - although the image seems accurate, PDF417 cod is not detected because of perspective distorsion.

With this change, now with the resulting Windows CE code, we now have yet very good PDF417 detection results.

Regards hfn
DetectorPD.cpp
Reply all
Reply to author
Forward
0 new messages