Skip to content

Commit 8fb2f81

Browse files
committed
ITF: support shorter ITF symbols (2, 3 or 4 depending on heuristic)
If we are looking only for ITF symbols, the minimum length is now 4 instead of 6. If the symbol covers the whole image, this gets halved, so 2 or 3 respectively. This fixes #853 without introducing any false positive for our sample data-set.
1 parent fc42827 commit 8fb2f81

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

core/src/oned/ODITFReader.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace ZXing::OneD {
1515

1616
Barcode ITFReader::decodePattern(int rowNumber, PatternView& next, std::unique_ptr<DecodingState>&) const
1717
{
18-
const int minCharCount = 6;
18+
const int minCharCount = _opts.formats().count() == 1 ? 4 : 6; // if we are only looking for ITF, we accept shorter symbols
1919
const int minQuietZone = 6; // spec requires 10
2020

2121
next = FindLeftGuard(next, 4 + minCharCount/2 + 3, FixedPattern<4, 4>{1, 1, 1, 1}, minQuietZone);
@@ -33,6 +33,8 @@ Barcode ITFReader::decodePattern(int rowNumber, PatternView& next, std::unique_p
3333

3434
constexpr int weights[] = {1, 2, 4, 7, 0};
3535
int xStart = next.pixelsInFront();
36+
bool startsAtFirstBar = next.isAtFirstBar();
37+
3638
next = next.subView(4, 10);
3739

3840
std::string txt;
@@ -62,17 +64,18 @@ Barcode ITFReader::decodePattern(int rowNumber, PatternView& next, std::unique_p
6264

6365
next = next.subView(0, 3);
6466

65-
if (Size(txt) < minCharCount || !next.isValid())
66-
return {};
67-
6867
// Check quiet zone size
69-
if (!(next.isAtLastBar() || next[3] > minQuietZone * (threshold.bar + threshold.space) / 3))
68+
if (!next.isValid() || !(next.isAtLastBar() || next[3] > minQuietZone * (threshold.bar + threshold.space) / 3))
7069
return {};
7170

7271
// Check stop pattern
7372
if (next[0] < threshold[0] || next[1] > threshold[1] || next[2] > threshold[2])
7473
return {};
7574

75+
// Check min length depending on whether the code covers the complete image or not
76+
if (Size(txt) < (startsAtFirstBar && next.isAtLastBar() ? (minCharCount / 2) : minCharCount))
77+
return {};
78+
7679
Error error = _opts.validateITFCheckSum() && !GTIN::IsCheckDigitValid(txt) ? ChecksumError() : Error();
7780

7881
// Symbology identifier ISO/IEC 16390:2007 Annex C Table C.1

test/blackbox/BlackboxTestRunner.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,9 +464,9 @@ int runBlackBoxTests(const fs::path& testPathPrefix, const std::set<std::string>
464464
{ 3, 5, 180 },
465465
}, ReaderOptions().setEanAddOnSymbol(EanAddOnSymbol::Require));
466466

467-
runTests("itf-1", "ITF", 11, {
468-
{ 10, 11, 0 },
469-
{ 10, 11, 180 },
467+
runTests("itf-1", "ITF", 12, {
468+
{ 11, 12, 0 },
469+
{ 11, 12, 180 },
470470
});
471471

472472
runTests("itf-2", "ITF", 6, {

test/samples/itf-1/#853.png

178 Bytes
Loading

test/samples/itf-1/#853.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1515

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy