add patch evluation

This commit is contained in:
unknown
2026-01-08 14:23:38 +08:00
parent dd04b337f0
commit 56bb77e1fd
8 changed files with 440 additions and 5 deletions
+19 -2
View File
@@ -446,7 +446,7 @@ class Stitcher:
n_boxes = 0
bk_thresh = 0 # initial black threshold
bk_thresh_step = 5
bk_thresh_max = 100
bk_thresh_max = 125
# Also include a low global V threshold to capture colored but dark tiles
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
@@ -503,7 +503,24 @@ class Stitcher:
cropped_boxes.append((nx0, ny0, nx1, ny1))
# sort boxes left-to-right, top-to-bottom (useful for grid)
cropped_boxes = sorted(cropped_boxes, key=lambda b: (b[1], b[0]))
# Use quantized y-coordinates to group boxes into rows, making sorting robust to noise
if len(cropped_boxes) > 0:
# Calculate row tolerance based on typical box height (use median height)
heights = [b[3] - b[1] for b in cropped_boxes]
median_height = np.median(heights) if heights else target_h
# Use a fraction of the box height as tolerance (e.g., 20% of box height)
row_tolerance = max(1, int(median_height * 0.2))
# Quantize y-coordinates to group boxes into rows
def get_row_key(box):
y = box[1] # y0 coordinate
# Round y to nearest multiple of row_tolerance to group into rows
quantized_y = (y // row_tolerance) * row_tolerance
return (quantized_y, box[0]) # Sort by quantized row, then by x
cropped_boxes = sorted(cropped_boxes, key=get_row_key)
else:
cropped_boxes = sorted(cropped_boxes, key=lambda b: (b[1], b[0]))
self.boxes = cropped_boxes
img_with_boxes = self.draw_boxes(img= img)