Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -58,7 +58,7 @@ def homography_all_detectors(flat_file, persp_file, json_file, xml_file):
|
|
58 |
xml_points = parse_xml_points(xml_file.name)
|
59 |
|
60 |
methods = ["SIFT","ORB","BRISK","KAZE","AKAZE"]
|
61 |
-
|
62 |
download_files = []
|
63 |
|
64 |
for method in methods:
|
@@ -82,31 +82,32 @@ def homography_all_detectors(flat_file, persp_file, json_file, xml_file):
|
|
82 |
xml_mapped = cv2.perspectiveTransform(xml_points.reshape(-1,1,2),H).reshape(-1,2)
|
83 |
for px,py in xml_mapped: cv2.circle(xml_gt_img,(int(px),int(py)),5,(0,0,255),-1)
|
84 |
|
85 |
-
# Merge 2x2 grid (original
|
86 |
top = np.hstack([flat_img, match_img])
|
87 |
bottom = np.hstack([persp_roi, xml_gt_img])
|
88 |
combined_grid = np.vstack([top, bottom])
|
89 |
|
90 |
-
# Save combined grid
|
91 |
base_name = os.path.splitext(os.path.basename(persp_file))[0]
|
92 |
file_name = f"{base_name}_{method.lower()}.png"
|
93 |
cv2.imwrite(file_name, combined_grid)
|
94 |
-
|
95 |
download_files.append(file_name)
|
96 |
|
|
|
97 |
while len(download_files)<5: download_files.append(None)
|
98 |
-
return
|
99 |
|
100 |
iface = gr.Interface(
|
101 |
fn=homography_all_detectors,
|
102 |
inputs=[
|
103 |
-
gr.Image(label="Upload Flat Image",type="filepath"),
|
104 |
-
gr.Image(label="Upload Perspective Image",type="filepath"),
|
105 |
-
gr.File(label="Upload mockup.json",file_types=[".json"]),
|
106 |
-
gr.File(label="Upload XML file",file_types=[".xml"])
|
107 |
],
|
108 |
outputs=[
|
109 |
-
gr.Gallery(label="Results per Detector",show_label=True),
|
110 |
gr.File(label="Download SIFT Result"),
|
111 |
gr.File(label="Download ORB Result"),
|
112 |
gr.File(label="Download BRISK Result"),
|
@@ -114,7 +115,7 @@ iface = gr.Interface(
|
|
114 |
gr.File(label="Download AKAZE Result")
|
115 |
],
|
116 |
title="Homography ROI Projection with Feature Matching & XML GT",
|
117 |
-
description="
|
118 |
)
|
119 |
|
120 |
iface.launch()
|
|
|
58 |
xml_points = parse_xml_points(xml_file.name)
|
59 |
|
60 |
methods = ["SIFT","ORB","BRISK","KAZE","AKAZE"]
|
61 |
+
gallery_files = []
|
62 |
download_files = []
|
63 |
|
64 |
for method in methods:
|
|
|
82 |
xml_mapped = cv2.perspectiveTransform(xml_points.reshape(-1,1,2),H).reshape(-1,2)
|
83 |
for px,py in xml_mapped: cv2.circle(xml_gt_img,(int(px),int(py)),5,(0,0,255),-1)
|
84 |
|
85 |
+
# Merge 2x2 grid (original resolution)
|
86 |
top = np.hstack([flat_img, match_img])
|
87 |
bottom = np.hstack([persp_roi, xml_gt_img])
|
88 |
combined_grid = np.vstack([top, bottom])
|
89 |
|
90 |
+
# Save combined grid as file
|
91 |
base_name = os.path.splitext(os.path.basename(persp_file))[0]
|
92 |
file_name = f"{base_name}_{method.lower()}.png"
|
93 |
cv2.imwrite(file_name, combined_grid)
|
94 |
+
gallery_files.append(file_name)
|
95 |
download_files.append(file_name)
|
96 |
|
97 |
+
# Ensure 5 download slots
|
98 |
while len(download_files)<5: download_files.append(None)
|
99 |
+
return gallery_files, download_files[0], download_files[1], download_files[2], download_files[3], download_files[4]
|
100 |
|
101 |
iface = gr.Interface(
|
102 |
fn=homography_all_detectors,
|
103 |
inputs=[
|
104 |
+
gr.Image(label="Upload Flat Image", type="filepath"),
|
105 |
+
gr.Image(label="Upload Perspective Image", type="filepath"),
|
106 |
+
gr.File(label="Upload mockup.json", file_types=[".json"]),
|
107 |
+
gr.File(label="Upload XML file", file_types=[".xml"])
|
108 |
],
|
109 |
outputs=[
|
110 |
+
gr.Gallery(label="Results per Detector", show_label=True),
|
111 |
gr.File(label="Download SIFT Result"),
|
112 |
gr.File(label="Download ORB Result"),
|
113 |
gr.File(label="Download BRISK Result"),
|
|
|
115 |
gr.File(label="Download AKAZE Result")
|
116 |
],
|
117 |
title="Homography ROI Projection with Feature Matching & XML GT",
|
118 |
+
description="Shows 4 views per detector. Original resolution kept; click on Gallery images to open full."
|
119 |
)
|
120 |
|
121 |
iface.launch()
|