github-actions[bot] commited on
Commit
cbefdd1
Β·
1 Parent(s): 41bcbe9

deploy: backend bundle from 25123cd352c0b00039208dfa89272649fdd3d269

Browse files
Code/Backend/api_server.py CHANGED
@@ -964,6 +964,7 @@ async def card_info_endpoint(request: CardInfoRequest) -> CardInfoResponse:
964
  raw_text = ocr_result.get("raw_text")
965
 
966
  if not ocr_name:
 
967
  return CardInfoResponse(
968
  found=False,
969
  lookup_confidence=0.0,
@@ -983,6 +984,7 @@ async def card_info_endpoint(request: CardInfoRequest) -> CardInfoResponse:
983
  )
984
 
985
  if card is None:
 
986
  return CardInfoResponse(
987
  found=False,
988
  lookup_confidence=0.3,
 
964
  raw_text = ocr_result.get("raw_text")
965
 
966
  if not ocr_name:
967
+ print(f"[card-info] ocr_failed β€” raw_text: {repr(raw_text)}")
968
  return CardInfoResponse(
969
  found=False,
970
  lookup_confidence=0.0,
 
984
  )
985
 
986
  if card is None:
987
+ print(f"[card-info] not_found β€” name={repr(ocr_name)} number={repr(ocr_number)} hp={repr(ocr_hp)}")
988
  return CardInfoResponse(
989
  found=False,
990
  lookup_confidence=0.3,
Code/Backend/src/ocr/card_ocr.py CHANGED
@@ -62,6 +62,17 @@ class CardOCR:
62
  raw_text = f"{name_text} | {number_text} | {hp_text}"
63
 
64
  name = self._parse_name(name_text)
 
 
 
 
 
 
 
 
 
 
 
65
  collector_number, set_total = self._parse_collector_number(number_text)
66
  hp = self._parse_hp(hp_text)
67
 
@@ -148,8 +159,13 @@ class CardOCR:
148
  if _card_shaped(w, h):
149
  return self._correct_orientation(_apply_crop(x, y, w, h))
150
 
151
- # ── Fallback ─────────────────────────────────────────────────────
152
- return self._correct_orientation(img)
 
 
 
 
 
153
 
154
  def _correct_orientation(self, card: np.ndarray) -> np.ndarray:
155
  """
 
62
  raw_text = f"{name_text} | {number_text} | {hp_text}"
63
 
64
  name = self._parse_name(name_text)
65
+
66
+ # Fallback: if the standard name crop returned nothing, try a taller
67
+ # region (top 25%, full width) β€” handles cards where the name banner
68
+ # sits lower or the card crop is slightly mis-aligned.
69
+ if name is None:
70
+ h_c, w_c = card_img.shape[:2]
71
+ wide_crop = card_img[0 : int(h_c * 0.25), :]
72
+ wide_text = self._run_ocr(self._preprocess_name(wide_crop), psm=11)
73
+ name = self._parse_name(wide_text)
74
+ if name:
75
+ raw_text = f"{name_text}[wide:{wide_text}] | {number_text} | {hp_text}"
76
  collector_number, set_total = self._parse_collector_number(number_text)
77
  hp = self._parse_hp(hp_text)
78
 
 
159
  if _card_shaped(w, h):
160
  return self._correct_orientation(_apply_crop(x, y, w, h))
161
 
162
+ # ── Fallback: centre crop ─────────────────────────────────────────
163
+ # Neither strategy found a card-shaped region. Most phone photos
164
+ # place the card near the centre; strip the outer margins to remove
165
+ # the status bar, navigation UI, and table background.
166
+ cy, cx = int(img_h * 0.12), int(img_w * 0.05)
167
+ centre = img[cy: img_h - cy, cx: img_w - cx]
168
+ return self._correct_orientation(centre)
169
 
170
  def _correct_orientation(self, card: np.ndarray) -> np.ndarray:
171
  """