mirror of
https://github.com/zxing/zxing.git
synced 2024-11-13 14:34:08 -08:00
Changes to fix high nbr of false positives. - Fixed up the quiet zone checks. - Validate that the barcode fills the viewfinder - Check that decoded barcode is min 6 digits git-svn-id: https://zxing.googlecode.com/svn/trunk@755 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
1e9123b0af
commit
85506667a7
|
@ -93,7 +93,11 @@ public class ITFReader extends AbstractOneDReader {
|
||||||
decodeMiddle(row, startRange[1], endRange[0], result);
|
decodeMiddle(row, startRange[1], endRange[0], result);
|
||||||
|
|
||||||
String resultString = result.toString();
|
String resultString = result.toString();
|
||||||
if (resultString.length() == 0 || resultString.length() % 2 == 1)
|
/**
|
||||||
|
* To avoid false positives with 2D barcodes, make
|
||||||
|
* an assumption that the decoded string must be at least 6 digits.
|
||||||
|
*/
|
||||||
|
if (resultString.length() < 6 || resultString.length() % 2 == 1)
|
||||||
throw ReaderException.getInstance();
|
throw ReaderException.getInstance();
|
||||||
|
|
||||||
return new Result(resultString,
|
return new Result(resultString,
|
||||||
|
@ -164,18 +168,56 @@ public class ITFReader extends AbstractOneDReader {
|
||||||
*/
|
*/
|
||||||
this.narrowLineWidth = (startPattern[1] - startPattern[0]) / 4;
|
this.narrowLineWidth = (startPattern[1] - startPattern[0]) / 4;
|
||||||
|
|
||||||
/**
|
validateQuietZone(row, startPattern[0]);
|
||||||
* The start & end patterns must be pre/post fixed by a quiet zone. This
|
|
||||||
* zone must be at least 10 times the width of a narrow line.
|
return startPattern;
|
||||||
*
|
}
|
||||||
* ref: http://www.barcode-1.net/i25code.html
|
|
||||||
*/
|
/**
|
||||||
if (this.narrowLineWidth * 10 > startPattern[0]) {
|
*
|
||||||
// Unable to find the quiet zone preceeding the start sequence.
|
*
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* The start & end patterns must be pre/post fixed by a quiet zone. This
|
||||||
|
* zone must be at least 10 times the width of a narrow line. Scan back until
|
||||||
|
* we either get to the start of the barcode or match the necessary number of
|
||||||
|
* quiet zone pixels.
|
||||||
|
*
|
||||||
|
* Note: Its assumed the row is reversed when using this method to find
|
||||||
|
* quiet zone after the end pattern.
|
||||||
|
*
|
||||||
|
* ref: http://www.barcode-1.net/i25code.html
|
||||||
|
*
|
||||||
|
* @param row - The bit array representing the scanned barcode.
|
||||||
|
* @param startPattern - The index into row of the start or end pattern.
|
||||||
|
* @throws ReaderException - If the quiet zone cannot be found, a ReaderException is thrown.
|
||||||
|
*/
|
||||||
|
private void validateQuietZone(BitArray row, int startPattern) throws ReaderException {
|
||||||
|
|
||||||
|
int quietCount=this.narrowLineWidth * 10; // expect to find this many pixels of quiet zone
|
||||||
|
|
||||||
|
int i=0;
|
||||||
|
for (i=startPattern-1; quietCount>0 && i>=0; i--)
|
||||||
|
{
|
||||||
|
if (row.get(i)==true)
|
||||||
|
break;
|
||||||
|
quietCount--;
|
||||||
|
}
|
||||||
|
if (quietCount!=0)
|
||||||
|
{
|
||||||
|
// Unable to find the necessary number of quiet zone pixels.
|
||||||
throw ReaderException.getInstance();
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
return startPattern;
|
if (i>this.narrowLineWidth*20)
|
||||||
|
{
|
||||||
|
// The distance from the image edge to the start of the quiet zone
|
||||||
|
// is twice the size of the quiet zone.
|
||||||
|
// This is unrealistic as the barcode should mostly fill the camera viewfinder.
|
||||||
|
// This implies that this is a false positive.
|
||||||
|
throw ReaderException.getInstance();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -234,10 +276,8 @@ public class ITFReader extends AbstractOneDReader {
|
||||||
*
|
*
|
||||||
* ref: http://www.barcode-1.net/i25code.html
|
* ref: http://www.barcode-1.net/i25code.html
|
||||||
*/
|
*/
|
||||||
if (this.narrowLineWidth * 10 > endPattern[0]) {
|
|
||||||
// Unable to find the quiet zone preceeding the start sequence.
|
validateQuietZone(row, endPattern[0]);
|
||||||
throw ReaderException.getInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now recalc the indicies of where the 'endblock' starts & stops to
|
// Now recalc the indicies of where the 'endblock' starts & stops to
|
||||||
// accomodate
|
// accomodate
|
||||||
|
|
Loading…
Reference in a new issue