Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -72,7 +72,8 @@ def process_images(flat_img, persp_img, json_file):
|
|
| 72 |
|
| 73 |
# Load JSON
|
| 74 |
try:
|
| 75 |
-
|
|
|
|
| 76 |
except Exception as e:
|
| 77 |
print("JSON read error:", e)
|
| 78 |
return []
|
|
@@ -105,14 +106,19 @@ def process_images(flat_img, persp_img, json_file):
|
|
| 105 |
roi_corners_flat = get_rotated_rect_corners(roi_x, roi_y, roi_w, roi_h, roi_rot_deg)
|
| 106 |
roi_corners_persp = cv2.perspectiveTransform(roi_corners_flat.reshape(-1,1,2), H).reshape(-1,2)
|
| 107 |
|
| 108 |
-
# Draw ROI
|
|
|
|
| 109 |
persp_out = persp_img.copy()
|
|
|
|
| 110 |
cv2.polylines(persp_out, [roi_corners_persp.astype(int)], True, (0,255,0), 3)
|
|
|
|
|
|
|
| 111 |
|
| 112 |
-
#
|
| 113 |
-
cv2.
|
|
|
|
| 114 |
|
| 115 |
-
gallery_images.
|
| 116 |
|
| 117 |
return gallery_images
|
| 118 |
|
|
@@ -125,10 +131,10 @@ iface = gr.Interface(
|
|
| 125 |
gr.File(type="filepath", label="JSON File")
|
| 126 |
],
|
| 127 |
outputs=[
|
| 128 |
-
gr.Gallery(label="Detector
|
| 129 |
],
|
| 130 |
title="Feature Detection with ROI Projection",
|
| 131 |
-
description="Shows SIFT, ORB, BRISK, AKAZE, KAZE feature-based ROI projections
|
| 132 |
)
|
| 133 |
|
| 134 |
iface.launch()
|
|
|
|
| 72 |
|
| 73 |
# Load JSON
|
| 74 |
try:
|
| 75 |
+
with open(json_file.name, 'r') as f:
|
| 76 |
+
data = json.load(f)
|
| 77 |
except Exception as e:
|
| 78 |
print("JSON read error:", e)
|
| 79 |
return []
|
|
|
|
| 106 |
roi_corners_flat = get_rotated_rect_corners(roi_x, roi_y, roi_w, roi_h, roi_rot_deg)
|
| 107 |
roi_corners_persp = cv2.perspectiveTransform(roi_corners_flat.reshape(-1,1,2), H).reshape(-1,2)
|
| 108 |
|
| 109 |
+
# Draw ROI & label
|
| 110 |
+
flat_out = flat_img.copy()
|
| 111 |
persp_out = persp_img.copy()
|
| 112 |
+
cv2.polylines(flat_out, [roi_corners_flat.astype(int)], True, (255,0,0), 3)
|
| 113 |
cv2.polylines(persp_out, [roi_corners_persp.astype(int)], True, (0,255,0), 3)
|
| 114 |
+
cv2.putText(flat_out, det, (10,30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0,255,255), 2)
|
| 115 |
+
cv2.putText(persp_out, det, (10,30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0,255,255), 2)
|
| 116 |
|
| 117 |
+
# Convert to RGB for Gradio
|
| 118 |
+
flat_rgb = cv2.cvtColor(flat_out, cv2.COLOR_BGR2RGB)
|
| 119 |
+
persp_rgb = cv2.cvtColor(persp_out, cv2.COLOR_BGR2RGB)
|
| 120 |
|
| 121 |
+
gallery_images.extend([flat_rgb, persp_rgb])
|
| 122 |
|
| 123 |
return gallery_images
|
| 124 |
|
|
|
|
| 131 |
gr.File(type="filepath", label="JSON File")
|
| 132 |
],
|
| 133 |
outputs=[
|
| 134 |
+
gr.Gallery(label="Detector Results (Flat + Perspective per Detector)")
|
| 135 |
],
|
| 136 |
title="Feature Detection with ROI Projection",
|
| 137 |
+
description="Shows SIFT, ORB, BRISK, AKAZE, KAZE feature-based ROI projections. Each detector outputs Flat and Perspective images with labels."
|
| 138 |
)
|
| 139 |
|
| 140 |
iface.launch()
|