Apply changes to meet customer specification #27

Merged
foefl merged 14 commits from main_adapted into main 2026-01-07 09:30:57 +00:00
Showing only changes of commit aea65430e0 - Show all commits

View File

@ -97,15 +97,16 @@ def measure_length(
box = cast(npt.NDArray[np.float32], perspective.order_points(box))
(tl, tr, br, bl) = box
(tltrX, tltrY) = midpoint(tl, tr)
(blbrX, blbrY) = midpoint(bl, br)
(tlblX, tlblY) = midpoint(tl, bl)
(trbrX, trbrY) = midpoint(tr, br)
dA = dist.euclidean((tltrX, tltrY), (blbrX, blbrY))
dB = dist.euclidean((tlblX, tlblY), (trbrX, trbrY))
widthA = np.linalg.norm(br - bl)
widthB = np.linalg.norm(tr - tl)
max_width = int(max(widthA, widthB))
if dA < 100 or dB < 100:
heightA = np.linalg.norm(tr - br)
heightB = np.linalg.norm(tl - bl)
max_height = int(max(heightA, heightB))
if max_width < 100 or max_height < 100:
continue
is_duplicate = any(
@ -117,14 +118,30 @@ def measure_length(
accepted_boxes.append(rbox)
filtered_cnts.append(c)
dimA = dA / pixels_per_metric_Y
dimB = dB / pixels_per_metric_X
dimA = max_width / pixels_per_metric_Y
dimB = max_height / pixels_per_metric_X
offset = 20
dst = np.array([
[offset, offset],
[max_width - 1 + offset, offset],
[max_width - 1 + offset, max_height - 1 + offset],
[offset, max_height - 1 + offset]
], dtype="float32")
M = cv2.getPerspectiveTransform(box, dst)
warped = cv2.warpPerspective(orig, M, (max_width + 2 * offset, max_height + 2 * offset))
gray_warped = cv2.cvtColor(warped, cv2.COLOR_BGR2GRAY)
_, binary_warped = cv2.threshold(gray_warped, 80, 255, cv2.THRESH_BINARY)
pixel_count = np.sum(binary_warped == 0)
data_csv.extend(
[
f"{dimB:.3f}".replace(".", ","),
f"{dimA:.3f}".replace(".", ","),
f"{dimA * dimB:.1f}".replace(".", ","),
f"{pixel_count / pixels_per_metric_X / pixels_per_metric_Y:.1f}".replace(".", ","),
]
)