Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -71,7 +71,7 @@ def detect_and_match(img1_gray, img2_gray, method="SIFT", ratio_thresh=0.78):
|
|
| 71 |
good.append(m)
|
| 72 |
return kp1, kp2, good
|
| 73 |
|
| 74 |
-
# ---------------- Main Homography Function
|
| 75 |
def homography_all_detectors(flat_file, persp_file, json_file):
|
| 76 |
flat_img = cv2.imread(flat_file.name)
|
| 77 |
persp_img = cv2.imread(persp_file.name)
|
|
@@ -122,70 +122,30 @@ def homography_all_detectors(flat_file, persp_file, json_file):
|
|
| 122 |
gallery_images.append((result_rgb, f"{method} Result"))
|
| 123 |
download_files.append(file_name)
|
| 124 |
|
| 125 |
-
#
|
| 126 |
while len(download_files) < 5:
|
| 127 |
download_files.append(None)
|
| 128 |
|
| 129 |
-
# return: gallery + 5 files
|
| 130 |
return [gallery_images] + download_files[:5]
|
| 131 |
|
| 132 |
-
# ----------------
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
gr.Markdown("Upload flat & perspective images plus `mockup.json`. The gallery shows your uploads immediately, and detector results after you click **Run**. Download each result separately.")
|
| 154 |
-
|
| 155 |
-
with gr.Row():
|
| 156 |
-
flat_input = gr.File(label="Upload Flat Image", file_types=[".jpg", ".png", ".jpeg"])
|
| 157 |
-
persp_input = gr.File(label="Upload Perspective Image", file_types=[".jpg", ".png", ".jpeg"])
|
| 158 |
-
json_input = gr.File(label="Upload mockup.json", file_types=[".json"])
|
| 159 |
-
|
| 160 |
-
# Single gallery (used both for previews and results)
|
| 161 |
-
output_gallery = gr.Gallery(label="Gallery", show_label=True, columns=2, height=440)
|
| 162 |
-
|
| 163 |
-
# Individual download buttons (same as before)
|
| 164 |
-
download_sift = gr.File(label="Download SIFT Result")
|
| 165 |
-
download_orb = gr.File(label="Download ORB Result")
|
| 166 |
-
download_brisk = gr.File(label="Download BRISK Result")
|
| 167 |
-
download_kaze = gr.File(label="Download KAZE Result")
|
| 168 |
-
download_akaze = gr.File(label="Download AKAZE Result")
|
| 169 |
-
|
| 170 |
-
run_btn = gr.Button("Run Homography")
|
| 171 |
-
|
| 172 |
-
# Show previews in the SAME gallery as soon as files are uploaded/changed
|
| 173 |
-
flat_input.change(
|
| 174 |
-
preview_uploaded_gallery,
|
| 175 |
-
inputs=[flat_input, persp_input],
|
| 176 |
-
outputs=[output_gallery]
|
| 177 |
-
)
|
| 178 |
-
persp_input.change(
|
| 179 |
-
preview_uploaded_gallery,
|
| 180 |
-
inputs=[flat_input, persp_input],
|
| 181 |
-
outputs=[output_gallery]
|
| 182 |
-
)
|
| 183 |
-
|
| 184 |
-
# On run, compute and replace gallery with detector results + populate downloads
|
| 185 |
-
run_btn.click(
|
| 186 |
-
fn=homography_all_detectors,
|
| 187 |
-
inputs=[flat_input, persp_input, json_input],
|
| 188 |
-
outputs=[output_gallery, download_sift, download_orb, download_brisk, download_kaze, download_akaze]
|
| 189 |
-
)
|
| 190 |
-
|
| 191 |
-
demo.launch()
|
|
|
|
| 71 |
good.append(m)
|
| 72 |
return kp1, kp2, good
|
| 73 |
|
| 74 |
+
# ---------------- Main Homography Function ----------------
|
| 75 |
def homography_all_detectors(flat_file, persp_file, json_file):
|
| 76 |
flat_img = cv2.imread(flat_file.name)
|
| 77 |
persp_img = cv2.imread(persp_file.name)
|
|
|
|
| 122 |
gallery_images.append((result_rgb, f"{method} Result"))
|
| 123 |
download_files.append(file_name)
|
| 124 |
|
| 125 |
+
# return gallery + 5 download files (pad with None if less)
|
| 126 |
while len(download_files) < 5:
|
| 127 |
download_files.append(None)
|
| 128 |
|
|
|
|
| 129 |
return [gallery_images] + download_files[:5]
|
| 130 |
|
| 131 |
+
# ---------------- Gradio UI ----------------
|
| 132 |
+
iface = gr.Interface(
|
| 133 |
+
fn=homography_all_detectors,
|
| 134 |
+
inputs=[
|
| 135 |
+
gr.File(label="Upload Flat Image", file_types=[".jpg",".png",".jpeg"]),
|
| 136 |
+
gr.File(label="Upload Perspective Image", file_types=[".jpg",".png",".jpeg"]),
|
| 137 |
+
gr.File(label="Upload mockup.json", file_types=[".json"])
|
| 138 |
+
],
|
| 139 |
+
outputs=[
|
| 140 |
+
gr.Gallery(label="Results (per Detector)", show_label=True),
|
| 141 |
+
gr.File(label="Download SIFT Result"),
|
| 142 |
+
gr.File(label="Download ORB Result"),
|
| 143 |
+
gr.File(label="Download BRISK Result"),
|
| 144 |
+
gr.File(label="Download KAZE Result"),
|
| 145 |
+
gr.File(label="Download AKAZE Result")
|
| 146 |
+
],
|
| 147 |
+
title="Homography ROI Projection with Multiple Feature Detectors",
|
| 148 |
+
description="Upload flat & perspective images with mockup.json. The system will project ROI using SIFT, ORB, BRISK, KAZE, and AKAZE. Each result can be viewed and downloaded."
|
| 149 |
+
)
|
| 150 |
+
|
| 151 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|