change formatting

This commit is contained in:
Florian Förster 2026-01-06 08:06:28 +01:00
parent aea65430e0
commit c169d6d1cf

View File

@ -104,7 +104,7 @@ def measure_length(
heightA = np.linalg.norm(tr - br) heightA = np.linalg.norm(tr - br)
heightB = np.linalg.norm(tl - bl) heightB = np.linalg.norm(tl - bl)
max_height = int(max(heightA, heightB)) max_height = int(max(heightA, heightB))
if max_width < 100 or max_height < 100: if max_width < 100 or max_height < 100:
continue continue
@ -123,16 +123,21 @@ def measure_length(
offset = 20 offset = 20
dst = np.array([ dst = np.array(
[offset, offset], [
[max_width - 1 + offset, offset], [offset, offset],
[max_width - 1 + offset, max_height - 1 + offset], [max_width - 1 + offset, offset],
[offset, max_height - 1 + offset] [max_width - 1 + offset, max_height - 1 + offset],
], dtype="float32") [offset, max_height - 1 + offset],
],
dtype="float32",
)
M = cv2.getPerspectiveTransform(box, dst) M = cv2.getPerspectiveTransform(box, dst)
warped = cv2.warpPerspective(orig, M, (max_width + 2 * offset, max_height + 2 * offset)) warped = cv2.warpPerspective(
orig, M, (max_width + 2 * offset, max_height + 2 * offset)
)
gray_warped = cv2.cvtColor(warped, cv2.COLOR_BGR2GRAY) gray_warped = cv2.cvtColor(warped, cv2.COLOR_BGR2GRAY)
_, binary_warped = cv2.threshold(gray_warped, 80, 255, cv2.THRESH_BINARY) _, binary_warped = cv2.threshold(gray_warped, 80, 255, cv2.THRESH_BINARY)
pixel_count = np.sum(binary_warped == 0) pixel_count = np.sum(binary_warped == 0)
@ -141,7 +146,9 @@ def measure_length(
[ [
f"{dimB:.3f}".replace(".", ","), f"{dimB:.3f}".replace(".", ","),
f"{dimA:.3f}".replace(".", ","), f"{dimA:.3f}".replace(".", ","),
f"{pixel_count / pixels_per_metric_X / pixels_per_metric_Y:.1f}".replace(".", ","), f"{pixel_count / pixels_per_metric_X / pixels_per_metric_Y:.1f}".replace(
".", ","
),
] ]
) )