Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -77,7 +77,10 @@ def add_title(img_bgr, title):
|
|
| 77 |
return np.vstack([bar, img_bgr])
|
| 78 |
|
| 79 |
def parse_xml_roi_points(xml_path):
|
| 80 |
-
"""Parse XML, return list of polygons (Nx2 points)."""
|
|
|
|
|
|
|
|
|
|
| 81 |
polys = []
|
| 82 |
try:
|
| 83 |
tree = ET.parse(xml_path)
|
|
@@ -106,13 +109,15 @@ def parse_xml_roi_points(xml_path):
|
|
| 106 |
def homography_all_detectors(flat_file, persp_file, json_file, xml_file):
|
| 107 |
flat_img = cv2.imread(flat_file)
|
| 108 |
persp_img = cv2.imread(persp_file)
|
| 109 |
-
|
|
|
|
|
|
|
| 110 |
roi = mockup["printAreas"][0]
|
| 111 |
roi_x, roi_y = roi["position"]["x"], roi["position"]["y"]
|
| 112 |
roi_w, roi_h = roi["width"], roi["height"]
|
| 113 |
roi_rot_deg = roi["rotation"]
|
| 114 |
|
| 115 |
-
xml_polys = parse_xml_roi_points(xml_file
|
| 116 |
|
| 117 |
flat_gray = preprocess_gray_clahe(flat_img)
|
| 118 |
persp_gray = preprocess_gray_clahe(persp_img)
|
|
@@ -165,11 +170,14 @@ def homography_all_detectors(flat_file, persp_file, json_file, xml_file):
|
|
| 165 |
results.append((cv2.cvtColor(composite, cv2.COLOR_BGR2RGB), f"{method} Grid"))
|
| 166 |
download_files.append(file_name)
|
| 167 |
|
| 168 |
-
# pad list with "" instead of None (to avoid Gradio error)
|
| 169 |
while len(download_files) < 5:
|
| 170 |
-
download_files.append(
|
| 171 |
-
|
| 172 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
|
| 174 |
# ---------------- Gradio UI ----------------
|
| 175 |
iface = gr.Interface(
|
|
@@ -191,4 +199,4 @@ iface = gr.Interface(
|
|
| 191 |
title="Homography ROI vs XML ROI",
|
| 192 |
description="Each detector produces one 2×2 grid: Flat, Matches, Homography ROI, Ground Truth ROI."
|
| 193 |
)
|
| 194 |
-
iface.launch()
|
|
|
|
| 77 |
return np.vstack([bar, img_bgr])
|
| 78 |
|
| 79 |
def parse_xml_roi_points(xml_path):
|
| 80 |
+
"""Parse your XML structure, return list of polygons (Nx2 points)."""
|
| 81 |
+
if xml_path is None:
|
| 82 |
+
return None
|
| 83 |
+
|
| 84 |
polys = []
|
| 85 |
try:
|
| 86 |
tree = ET.parse(xml_path)
|
|
|
|
| 109 |
def homography_all_detectors(flat_file, persp_file, json_file, xml_file):
|
| 110 |
flat_img = cv2.imread(flat_file)
|
| 111 |
persp_img = cv2.imread(persp_file)
|
| 112 |
+
|
| 113 |
+
# FIX: Use the file paths directly (no .name needed)
|
| 114 |
+
mockup = json.load(open(json_file))
|
| 115 |
roi = mockup["printAreas"][0]
|
| 116 |
roi_x, roi_y = roi["position"]["x"], roi["position"]["y"]
|
| 117 |
roi_w, roi_h = roi["width"], roi["height"]
|
| 118 |
roi_rot_deg = roi["rotation"]
|
| 119 |
|
| 120 |
+
xml_polys = parse_xml_roi_points(xml_file) if xml_file else None
|
| 121 |
|
| 122 |
flat_gray = preprocess_gray_clahe(flat_img)
|
| 123 |
persp_gray = preprocess_gray_clahe(persp_img)
|
|
|
|
| 170 |
results.append((cv2.cvtColor(composite, cv2.COLOR_BGR2RGB), f"{method} Grid"))
|
| 171 |
download_files.append(file_name)
|
| 172 |
|
|
|
|
| 173 |
while len(download_files) < 5:
|
| 174 |
+
download_files.append(None)
|
| 175 |
+
|
| 176 |
+
# Return the results in the correct format
|
| 177 |
+
gallery_output = results
|
| 178 |
+
file_outputs = download_files[:5]
|
| 179 |
+
|
| 180 |
+
return [gallery_output] + file_outputs
|
| 181 |
|
| 182 |
# ---------------- Gradio UI ----------------
|
| 183 |
iface = gr.Interface(
|
|
|
|
| 199 |
title="Homography ROI vs XML ROI",
|
| 200 |
description="Each detector produces one 2×2 grid: Flat, Matches, Homography ROI, Ground Truth ROI."
|
| 201 |
)
|
| 202 |
+
iface.launch()
|