Hikity commited on
Commit
c5a4ecc
·
1 Parent(s): 0a96cf6

fix: OCR rupee-symbol-misread-as-8 denomination fix + frozen ₹2000 regression test

Browse files
app/currency_detector.py CHANGED
@@ -459,8 +459,16 @@ class CurrencyDetector:
459
  counts, word_hits = {}, set()
460
  words = cls._ocr_words(ocr_items)
461
  for tok in words:
462
- stripped = tok.lstrip("₹RS").strip() or tok
463
- for cand in {tok, stripped}:
 
 
 
 
 
 
 
 
464
  if cand.isdigit() and int(cand) in candidates:
465
  counts[int(cand)] = counts.get(int(cand), 0) + 1
466
  break
 
459
  counts, word_hits = {}, set()
460
  words = cls._ocr_words(ocr_items)
461
  for tok in words:
462
+ stripped = tok.lstrip("₹RS8").strip() or tok
463
+ # EasyOCR frequently misreads the ₹ glyph as a leading "8" digit
464
+ # (measured on a real ₹2000 note: "₹2000" -> "82000") — a plain
465
+ # .lstrip("₹RS") can't catch that since "8" is a real digit, so
466
+ # try stripping one leading "8" specifically when what remains is
467
+ # itself a valid denomination length.
468
+ variants = {tok, stripped}
469
+ if tok.isdigit() and tok.startswith("8") and len(tok) > 1:
470
+ variants.add(tok[1:])
471
+ for cand in variants:
472
  if cand.isdigit() and int(cand) in candidates:
473
  counts[int(cand)] = counts.get(int(cand), 0) + 1
474
  break
test/Rs2000note.webp ADDED
test_currency_v2.py CHANGED
@@ -29,6 +29,7 @@ GEN_DIR = os.path.join(TEST_DIR, "generated")
29
  REAL = os.path.join(TEST_DIR, "reaal_200rs_1.png")
30
  FAKE1 = os.path.join(TEST_DIR, "fake1.jpg")
31
  FAKE2 = os.path.join(TEST_DIR, "fake2.jpg")
 
32
 
33
  GENUINE_VERDICTS = {"LIKELY_GENUINE", "GENUINE_FEATURES"}
34
  FAKE_VERDICTS = {"LIKELY_COUNTERFEIT", "SUSPECT_FEATURES"}
@@ -100,6 +101,10 @@ CASES = [
100
  ("real_partial", os.path.join(GEN_DIR, "real_partial.png"), None, FAKE_VERDICTS, True),
101
  # a ₹30 note does not exist — must never clear as genuine
102
  ("prop_30_note", os.path.join(GEN_DIR, "prop_30_note.png"), None, GENUINE_VERDICTS, False),
 
 
 
 
103
  ]
104
 
105
 
 
29
  REAL = os.path.join(TEST_DIR, "reaal_200rs_1.png")
30
  FAKE1 = os.path.join(TEST_DIR, "fake1.jpg")
31
  FAKE2 = os.path.join(TEST_DIR, "fake2.jpg")
32
+ REAL_2000 = os.path.join(TEST_DIR, "Rs2000note.webp")
33
 
34
  GENUINE_VERDICTS = {"LIKELY_GENUINE", "GENUINE_FEATURES"}
35
  FAKE_VERDICTS = {"LIKELY_COUNTERFEIT", "SUSPECT_FEATURES"}
 
101
  ("real_partial", os.path.join(GEN_DIR, "real_partial.png"), None, FAKE_VERDICTS, True),
102
  # a ₹30 note does not exist — must never clear as genuine
103
  ("prop_30_note", os.path.join(GEN_DIR, "prop_30_note.png"), None, GENUINE_VERDICTS, False),
104
+ # genuine ₹2000 (withdrawn denomination) at low resolution — the
105
+ # denomination is often unreadable via OCR on this exact photo (borderline
106
+ # confidence), which is fine: it must NEVER read as counterfeit either way
107
+ ("real_2000", REAL_2000, None, FAKE_VERDICTS, True),
108
  ]
109
 
110