Skip to content

Commit bf9c9fc

Browse files
committed
fix: Remove longest digit fallback for OCR
It can erroneously identify unrelated numbers and doesn't make sense when `-ocr-match-regex` exists.
1 parent 3f91e09 commit bf9c9fc

2 files changed

Lines changed: 1 addition & 20 deletions

File tree

ocr.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ func parseOCRFixRegex(s string) *ocrFixRule {
105105
}
106106

107107
func extractReading(texts []string, matchRe *regexp.Regexp, fixRule *ocrFixRule) string {
108-
// First pass: apply fix rule if set, then match.
109108
for _, t := range texts {
110109
t = strings.TrimSpace(t)
111110
if fixRule != nil {
@@ -115,19 +114,7 @@ func extractReading(texts []string, matchRe *regexp.Regexp, fixRule *ocrFixRule)
115114
return t
116115
}
117116
}
118-
// Fallback: longest all-digit string.
119-
digitsOnly := regexp.MustCompile(`^\d+$`)
120-
best := ""
121-
for _, t := range texts {
122-
t = strings.TrimSpace(t)
123-
if fixRule != nil {
124-
t = fixRule.Pattern.ReplaceAllString(t, fixRule.Replacement)
125-
}
126-
if digitsOnly.MatchString(t) && len(t) > len(best) {
127-
best = t
128-
}
129-
}
130-
return best
117+
return ""
131118
}
132119

133120
func runOCR(imagePath string) (*ocrOutput, error) {

ocr_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ func TestExtractReading(t *testing.T) {
3333
matchRe: defaultMatchRe,
3434
want: "000354225",
3535
},
36-
{
37-
name: "fallback to longest digit string when no match",
38-
texts: []string{"12", "12345", "abc"},
39-
matchRe: defaultMatchRe,
40-
want: "12345",
41-
},
4236
{
4337
name: "no digits at all returns empty",
4438
texts: []string{"abc", "def"},

0 commit comments

Comments
 (0)