Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -211,9 +211,13 @@ def to_dxf(contours):
|
|
| 211 |
doc = ezdxf.new()
|
| 212 |
msp = doc.modelspace()
|
| 213 |
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
|
| 218 |
doc.saveas("./outputs/out.dxf")
|
| 219 |
return "./outputs/out.dxf"
|
|
@@ -226,11 +230,9 @@ def smooth_contours(contour):
|
|
| 226 |
def scale_image(image: np.ndarray, scale_factor: float) -> np.ndarray:
|
| 227 |
"""
|
| 228 |
Resize image by scaling both width and height by the same factor.
|
| 229 |
-
|
| 230 |
Args:
|
| 231 |
image: Input numpy image
|
| 232 |
scale_factor: Factor to scale the image (e.g., 0.5 for half size, 2 for double size)
|
| 233 |
-
|
| 234 |
Returns:
|
| 235 |
np.ndarray: Resized image
|
| 236 |
"""
|
|
@@ -302,7 +304,7 @@ def predict(image, offset_inches):
|
|
| 302 |
scaling_box_coords,
|
| 303 |
orig_size,
|
| 304 |
processed_size,
|
| 305 |
-
expansion_factor=1.
|
| 306 |
)
|
| 307 |
objects_mask = resize_img(objects_mask, (image.shape[1], image.shape[0]))
|
| 308 |
|
|
|
|
| 211 |
doc = ezdxf.new()
|
| 212 |
msp = doc.modelspace()
|
| 213 |
|
| 214 |
+
try:
|
| 215 |
+
for contour in contours:
|
| 216 |
+
points = [(point[0][0], point[0][1]) for point in contour]
|
| 217 |
+
msp.add_lwpolyline(points, close=True) # Add a polyline for each contour
|
| 218 |
+
except Exception as e:
|
| 219 |
+
raise gr.Error(f"Unable to generate DXF: {e}")
|
| 220 |
+
|
| 221 |
|
| 222 |
doc.saveas("./outputs/out.dxf")
|
| 223 |
return "./outputs/out.dxf"
|
|
|
|
| 230 |
def scale_image(image: np.ndarray, scale_factor: float) -> np.ndarray:
|
| 231 |
"""
|
| 232 |
Resize image by scaling both width and height by the same factor.
|
|
|
|
| 233 |
Args:
|
| 234 |
image: Input numpy image
|
| 235 |
scale_factor: Factor to scale the image (e.g., 0.5 for half size, 2 for double size)
|
|
|
|
| 236 |
Returns:
|
| 237 |
np.ndarray: Resized image
|
| 238 |
"""
|
|
|
|
| 304 |
scaling_box_coords,
|
| 305 |
orig_size,
|
| 306 |
processed_size,
|
| 307 |
+
expansion_factor=1.2,
|
| 308 |
)
|
| 309 |
objects_mask = resize_img(objects_mask, (image.shape[1], image.shape[0]))
|
| 310 |
|