Skip to content

Commit

Permalink
ITF: fix detection regression
Browse files Browse the repository at this point in the history
introduced in e3672fd

Add test image that checks for support of slanted (non-perpendicular)
scanned symbols.
  • Loading branch information
axxel committed Nov 5, 2024
1 parent 308f820 commit 8d9aecc
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 9 deletions.
16 changes: 10 additions & 6 deletions core/src/oned/ODITFReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,35 @@ Barcode ITFReader::decodePattern(int rowNumber, PatternView& next, std::unique_p
txt.reserve(20);

while (next.isValid()) {
threshold = NarrowWideThreshold(next);
if (!threshold.isValid())
// look for end-of-symbol
if (next[3] > threshold.space * 3)
break;

BarAndSpace<int> digits, numWide;
bool bad = false;
for (int i = 0; i < 10; ++i) {
if (next[i] > threshold[i] * 2)
break;
bad |= next[i] > threshold[i] * 3 || next[i] < threshold[i] / 3;
numWide[i] += next[i] > threshold[i];
digits[i] += weights[i/2] * (next[i] > threshold[i]);
}

if (numWide.bar != 2 || numWide.space != 2)
if (bad || numWide.bar != 2 || numWide.space != 2)
break;

for (int i = 0; i < 2; ++i)
txt.push_back(ToDigit(digits[i] == 11 ? 0 : digits[i]));

// update threshold to support scanning slanted symbols (scanned non-perpendicular)
threshold = NarrowWideThreshold(next);

next.skipSymbol();
}

next = next.subView(0, 3);

// Check quiet zone size
if (!next.isValid() || !(next.isAtLastBar() || next[3] > minQuietZone * (threshold.bar + threshold.space) / 3))
if (!next.isValid() || !threshold.isValid()
|| !(next.isAtLastBar() || next[3] > minQuietZone * (threshold.bar + threshold.space) / 3))
return {};

// Check stop pattern
Expand Down
6 changes: 3 additions & 3 deletions test/blackbox/BlackboxTestRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,9 @@ int runBlackBoxTests(const fs::path& testPathPrefix, const std::set<std::string>
{ 3, 5, 180 },
}, ReaderOptions().setEanAddOnSymbol(EanAddOnSymbol::Require));

runTests("itf-1", "ITF", 12, {
{ 11, 12, 0 },
{ 11, 12, 180 },
runTests("itf-1", "ITF", 14, {
{ 13, 14, 0 },
{ 13, 14, 180 },
});

runTests("itf-2", "ITF", 6, {
Expand Down
Binary file added test/samples/itf-1/1-slanted.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/samples/itf-1/1-slanted.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
30712345000010
Binary file added test/samples/itf-1/with-tail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/samples/itf-1/with-tail.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
00123456

0 comments on commit 8d9aecc

Please sign in to comment.