abhinavvvvv commited on
Commit
1f05ed6
·
1 Parent(s): a9446ed
Files changed (1) hide show
  1. app/ocr_engine.py +10 -31
app/ocr_engine.py CHANGED
@@ -20,41 +20,20 @@ class OCREngine:
20
  if img is None:
21
  return []
22
 
23
- img = cv2.resize(img, None, fx=0.7, fy=0.7)
24
-
25
- result = self.ocr.predict(img)
26
 
27
  lines = []
28
 
29
- if isinstance(result, list):
30
- for item in result:
31
-
32
- # Case 1: nested dict with "res"
33
- if isinstance(item, dict) and "res" in item:
34
- for sub in item["res"]:
35
- text = sub.get("text", "")
36
- score = sub.get("score", 0.0)
37
- if text:
38
- lines.append({
39
- "text": text,
40
- "confidence": float(score)
41
- })
42
-
43
- # Case 2: flat dict
44
- elif isinstance(item, dict) and "text" in item:
45
  lines.append({
46
- "text": item["text"],
47
- "confidence": float(item.get("score", 0.0))
48
  })
49
 
50
- # Case 3: old tuple format
51
- elif isinstance(item, list):
52
- for sub in item:
53
- if isinstance(sub, list) and len(sub) == 2:
54
- text, score = sub[1]
55
- lines.append({
56
- "text": text,
57
- "confidence": float(score)
58
- })
59
-
60
  return lines
 
20
  if img is None:
21
  return []
22
 
23
+ # Do NOT resize aggressively
24
+ result = self.ocr.ocr(img)
 
25
 
26
  lines = []
27
 
28
+ if result and isinstance(result, list) and len(result) > 0:
29
+ for line in result[0]:
30
+ text = line[1][0]
31
+ score = float(line[1][1])
32
+
33
+ if text.strip():
 
 
 
 
 
 
 
 
 
 
34
  lines.append({
35
+ "text": text,
36
+ "confidence": score
37
  })
38
 
 
 
 
 
 
 
 
 
 
 
39
  return lines