Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -787,7 +787,10 @@ def predict_with_paper(image, paper_size, offset,offset_unit, finger_clearance=F
|
|
787 |
logger.info(f"Paper size: {paper_size}")
|
788 |
|
789 |
if offset_unit == "inches":
|
790 |
-
offset
|
|
|
|
|
|
|
791 |
edge_radius = None
|
792 |
if edge_radius is None or edge_radius == 0:
|
793 |
edge_radius = 0.0001
|
@@ -838,13 +841,13 @@ def predict_with_paper(image, paper_size, offset,offset_unit, finger_clearance=F
|
|
838 |
rounded_mask = objects_mask.copy()
|
839 |
|
840 |
# Apply dilation for offset
|
841 |
-
if
|
842 |
-
offset_pixels = (float(
|
843 |
kernel = np.ones((int(offset_pixels), int(offset_pixels)), np.uint8)
|
844 |
dilated_mask = cv2.dilate(rounded_mask, kernel)
|
845 |
else:
|
846 |
dilated_mask = rounded_mask.copy()
|
847 |
-
|
848 |
# Save original dilated mask for output
|
849 |
Image.fromarray(dilated_mask).save("./outputs/scaled_mask_original.jpg")
|
850 |
dilated_mask_orig = dilated_mask.copy()
|
|
|
787 |
logger.info(f"Paper size: {paper_size}")
|
788 |
|
789 |
if offset_unit == "inches":
|
790 |
+
offset_mm = offset * 25.4 # Convert to mm for internal calculations
|
791 |
+
else:
|
792 |
+
offset_mm = offset
|
793 |
+
|
794 |
edge_radius = None
|
795 |
if edge_radius is None or edge_radius == 0:
|
796 |
edge_radius = 0.0001
|
|
|
841 |
rounded_mask = objects_mask.copy()
|
842 |
|
843 |
# Apply dilation for offset
|
844 |
+
if offset_mm > 0:
|
845 |
+
offset_pixels = (float(offset_mm) / scaling_factor # Remove the *2 +1 which was causing excessive dilation
|
846 |
kernel = np.ones((int(offset_pixels), int(offset_pixels)), np.uint8)
|
847 |
dilated_mask = cv2.dilate(rounded_mask, kernel)
|
848 |
else:
|
849 |
dilated_mask = rounded_mask.copy()
|
850 |
+
|
851 |
# Save original dilated mask for output
|
852 |
Image.fromarray(dilated_mask).save("./outputs/scaled_mask_original.jpg")
|
853 |
dilated_mask_orig = dilated_mask.copy()
|