PaulMartrenchar commited on
Commit
104b989
·
1 Parent(s): 1a0667a
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -169,17 +169,21 @@ def detect_cards_and_sum(image, game):
169
  crop_margin_left = int(w / 7)
170
  crop_size = int(w / 3)
171
 
172
- # Map cropped region back to original card coordinates
173
- crop_tl = np.array([crop_margin_left, crop_margin_top]) # Remove the 1
174
- crop_br = np.array([crop_margin_left + crop_size, crop_margin_top + crop_size]) # Remove the 1
 
 
 
 
175
 
176
  # Inverse perspective transform to get points in original image
177
  M_inv = cv2.getPerspectiveTransform(
178
  np.array([[0, 0], [dst_w-1, 0], [dst_w-1, dst_h-1], [0, dst_h-1]], dtype="float32"),
179
  order_points(box)
180
  )
181
- crop_tl_orig = cv2.perspectiveTransform(crop_tl[np.newaxis, np.newaxis, :], M_inv)
182
- crop_br_orig = cv2.perspectiveTransform(crop_br[np.newaxis, np.newaxis, :], M_inv)
183
 
184
  # Draw rectangle around cropped region in original image
185
  cv2.rectangle(
@@ -188,7 +192,6 @@ def detect_cards_and_sum(image, game):
188
  tuple(crop_br_orig[0][0].astype(int)),
189
  (255, 0, 0), 2
190
  )
191
-
192
  # --- Draw value near the card ---
193
  moments = cv2.moments(box)
194
  if moments["m00"] != 0:
 
169
  crop_margin_left = int(w / 7)
170
  crop_size = int(w / 3)
171
 
172
+ # Define crop region points (without homogeneous coordinate)
173
+ crop_tl = np.array([crop_margin_left, crop_margin_top], dtype="float32")
174
+ crop_br = np.array([crop_margin_left + crop_size, crop_margin_top + crop_size], dtype="float32")
175
+
176
+ # Reshape for perspectiveTransform: (N, 1, 2)
177
+ crop_tl_reshaped = crop_tl.reshape(-1, 1, 2)
178
+ crop_br_reshaped = crop_br.reshape(-1, 1, 2)
179
 
180
  # Inverse perspective transform to get points in original image
181
  M_inv = cv2.getPerspectiveTransform(
182
  np.array([[0, 0], [dst_w-1, 0], [dst_w-1, dst_h-1], [0, dst_h-1]], dtype="float32"),
183
  order_points(box)
184
  )
185
+ crop_tl_orig = cv2.perspectiveTransform(crop_tl_reshaped, M_inv)
186
+ crop_br_orig = cv2.perspectiveTransform(crop_br_reshaped, M_inv)
187
 
188
  # Draw rectangle around cropped region in original image
189
  cv2.rectangle(
 
192
  tuple(crop_br_orig[0][0].astype(int)),
193
  (255, 0, 0), 2
194
  )
 
195
  # --- Draw value near the card ---
196
  moments = cv2.moments(box)
197
  if moments["m00"] != 0: