Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -182,14 +182,14 @@ def save_dxf_spline(inflated_contours, scaling_factor, height):
|
|
182 |
|
183 |
doc = ezdxf.new(units=0)
|
184 |
doc.units = ezdxf.units.IN
|
185 |
-
doc.header[
|
186 |
|
187 |
msp = doc.modelspace()
|
188 |
|
189 |
for contour in inflated_contours:
|
190 |
resampled_contour = resample_contour(contour)
|
191 |
points = [
|
192 |
-
(x * scaling_factor, (height - y)* scaling_factor)
|
193 |
for x, y in resampled_contour
|
194 |
]
|
195 |
if len(points) >= 3:
|
@@ -378,7 +378,7 @@ def predict(image, offset_inches):
|
|
378 |
objects_mask = resize_img(
|
379 |
objects_mask, (shrunked_img.shape[1], shrunked_img.shape[0])
|
380 |
)
|
381 |
-
offset_pixels = (offset_inches / scaling_factor)*2+1
|
382 |
dilated_mask = cv2.dilate(
|
383 |
objects_mask, np.ones((int(offset_pixels), int(offset_pixels)), np.uint8)
|
384 |
)
|
@@ -387,9 +387,18 @@ def predict(image, offset_inches):
|
|
387 |
# objects_mask_scaled = scale_image(objects_mask, scaling_factor)
|
388 |
Image.fromarray(dilated_mask).save("./outputs/scaled_mask_new.jpg")
|
389 |
outlines, contours = extract_outlines(dilated_mask)
|
|
|
|
|
|
|
390 |
dxf = save_dxf_spline(contours, scaling_factor, processed_size[0])
|
391 |
|
392 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
393 |
|
394 |
|
395 |
if __name__ == "__main__":
|
@@ -397,16 +406,19 @@ if __name__ == "__main__":
|
|
397 |
|
398 |
ifer = gr.Interface(
|
399 |
fn=predict,
|
400 |
-
inputs=[
|
|
|
|
|
|
|
401 |
outputs=[
|
402 |
gr.Image(label="Ouput Image"),
|
|
|
403 |
gr.File(label="DXF file"),
|
404 |
gr.Image(label="Mask"),
|
405 |
gr.Textbox(
|
406 |
label="Scaling Factor(mm)",
|
407 |
-
placeholder="Every pixel is equal to mentioned number in
|
408 |
),
|
409 |
-
gr.Image(label="Image used for calculating scaling factor"),
|
410 |
],
|
411 |
examples=[
|
412 |
["./examples/Test20.jpg", 0.075],
|
|
|
182 |
|
183 |
doc = ezdxf.new(units=0)
|
184 |
doc.units = ezdxf.units.IN
|
185 |
+
doc.header["$INSUNITS"] = ezdxf.units.IN
|
186 |
|
187 |
msp = doc.modelspace()
|
188 |
|
189 |
for contour in inflated_contours:
|
190 |
resampled_contour = resample_contour(contour)
|
191 |
points = [
|
192 |
+
(x * scaling_factor, (height - y) * scaling_factor)
|
193 |
for x, y in resampled_contour
|
194 |
]
|
195 |
if len(points) >= 3:
|
|
|
378 |
objects_mask = resize_img(
|
379 |
objects_mask, (shrunked_img.shape[1], shrunked_img.shape[0])
|
380 |
)
|
381 |
+
offset_pixels = (offset_inches / scaling_factor) * 2 + 1
|
382 |
dilated_mask = cv2.dilate(
|
383 |
objects_mask, np.ones((int(offset_pixels), int(offset_pixels)), np.uint8)
|
384 |
)
|
|
|
387 |
# objects_mask_scaled = scale_image(objects_mask, scaling_factor)
|
388 |
Image.fromarray(dilated_mask).save("./outputs/scaled_mask_new.jpg")
|
389 |
outlines, contours = extract_outlines(dilated_mask)
|
390 |
+
shrunked_img_contours = cv2.drawContours(
|
391 |
+
shrunked_img, contours, -1, (0, 0, 255), thickness=2
|
392 |
+
)
|
393 |
dxf = save_dxf_spline(contours, scaling_factor, processed_size[0])
|
394 |
|
395 |
+
return (
|
396 |
+
cv2.cvtColor(shrunked_img_contours, cv2.COLOR_BGR2RGB),
|
397 |
+
outlines,
|
398 |
+
dxf,
|
399 |
+
dilated_mask,
|
400 |
+
scaling_factor,
|
401 |
+
)
|
402 |
|
403 |
|
404 |
if __name__ == "__main__":
|
|
|
406 |
|
407 |
ifer = gr.Interface(
|
408 |
fn=predict,
|
409 |
+
inputs=[
|
410 |
+
gr.Image(label="Input Image"),
|
411 |
+
gr.Number(label="Offset value for Mask(inches)", value=0.075),
|
412 |
+
],
|
413 |
outputs=[
|
414 |
gr.Image(label="Ouput Image"),
|
415 |
+
gr.Image(label="Outlines of Objects"),
|
416 |
gr.File(label="DXF file"),
|
417 |
gr.Image(label="Mask"),
|
418 |
gr.Textbox(
|
419 |
label="Scaling Factor(mm)",
|
420 |
+
placeholder="Every pixel is equal to mentioned number in inches",
|
421 |
),
|
|
|
422 |
],
|
423 |
examples=[
|
424 |
["./examples/Test20.jpg", 0.075],
|