dcorcoran commited on
Commit
3854a46
Β·
1 Parent(s): 0032e86

Adjusted OCR cropping regions

Browse files
Files changed (1) hide show
  1. app/services/ocr_service.py +9 -9
app/services/ocr_service.py CHANGED
@@ -43,7 +43,7 @@ class OCRService:
43
  w, h = image.size
44
 
45
  # Crop to the top left of the card
46
- top_left = image.crop((0.06 * w, 0.03 * h, 0.16 * w, 0.06 * h))
47
 
48
  # Preprocesss the cropped region
49
  top_left = self._preprocess(top_left, scale=3)
@@ -66,15 +66,15 @@ class OCRService:
66
  # Name field β€” skip "Basic Pokemon" line at very top, just grab name row
67
  # Evolved cards have an evolution picture in the top-left (~0–25% width), so the name starts further right. Basic cards start near the left edge.
68
  if evolved:
69
- name_region = image.crop((0.20 * w, 0.06 * h, 0.60 * w, 0.10 * h))
70
  else:
71
- name_region = image.crop((0.05 * w, 0.06 * h, 0.60 * w, 0.10 * h))
72
 
73
  # HP field β€” top right, large number + "HP" text
74
- hp_region = image.crop((0.65 * w, 0.06 * h, 0.97 * w, 0.10 * h))
75
 
76
  # Length/Weight β€” bar sits just above the moves section
77
- length_weight_region = image.crop((0.12 * w, 0.55 * h, 0.85 * w, 0.56 * h))
78
 
79
  # Moves field β€” middle to lower section
80
  moves_region = image.crop((0.02 * w, 0.52 * h, 0.98 * w, 0.88 * h))
@@ -237,11 +237,11 @@ class OCRService:
237
  draw = ImageDraw.Draw(vis)
238
 
239
  regions = {
240
- "Name": (0.20 * w if evolved else 0.05 * w, 0.06 * h, 0.60 * w, 0.10 * h),
241
- "HP": (0.65 * w, 0.06 * h, 0.97 * w, 0.10 * h),
242
- "Length/Weight": (0.12 * w, 0.55 * h, 0.85 * w, 0.56 * h),
243
  "Moves": (0.02 * w, 0.57 * h, 0.98 * w, 0.88 * h),
244
- "is_evolved": (0.06 * w, 0.03 * h, 0.16 * w, 0.06 * h)
245
  }
246
  colors = {
247
  "Name": "red",
 
43
  w, h = image.size
44
 
45
  # Crop to the top left of the card
46
+ top_left = image.crop((0.07 * w, 0.04 * h, 0.18 * w, 0.07 * h))
47
 
48
  # Preprocesss the cropped region
49
  top_left = self._preprocess(top_left, scale=3)
 
66
  # Name field β€” skip "Basic Pokemon" line at very top, just grab name row
67
  # Evolved cards have an evolution picture in the top-left (~0–25% width), so the name starts further right. Basic cards start near the left edge.
68
  if evolved:
69
+ name_region = image.crop((0.20 * w, 0.06 * h, 0.62 * w, 0.11 * h))
70
  else:
71
+ name_region = image.crop((0.07 * w, 0.06 * h, 0.62 * w, 0.11 * h))
72
 
73
  # HP field β€” top right, large number + "HP" text
74
+ hp_region = image.crop((0.64 * w, 0.06 * h, 0.85 * w, 0.11 * h))
75
 
76
  # Length/Weight β€” bar sits just above the moves section
77
+ length_weight_region = image.crop((0.125 * w, 0.53 * h, 0.86 * w, 0.57 * h))
78
 
79
  # Moves field β€” middle to lower section
80
  moves_region = image.crop((0.02 * w, 0.52 * h, 0.98 * w, 0.88 * h))
 
237
  draw = ImageDraw.Draw(vis)
238
 
239
  regions = {
240
+ "Name": (0.20 * w if evolved else 0.07 * w, 0.06 * h, 0.62 * w, 0.11 * h),
241
+ "HP": (0.64 * w, 0.06 * h, 0.85 * w, 0.11 * h),
242
+ "Length/Weight": (0.125 * w, 0.53 * h, 0.86 * w, 0.57 * h),
243
  "Moves": (0.02 * w, 0.57 * h, 0.98 * w, 0.88 * h),
244
+ "is_evolved": (0.07 * w, 0.04 * h, 0.18 * w, 0.07 * h)
245
  }
246
  colors = {
247
  "Name": "red",