Spaces:
Running on Zero
Running on Zero
Enlarge the images to click on
Browse files- click3r/demo/app.py +10 -3
click3r/demo/app.py
CHANGED
|
@@ -64,6 +64,7 @@ from click3r.demo.views import prepare_model_view
|
|
| 64 |
from click3r.demo.results import ReconstructionResult
|
| 65 |
|
| 66 |
DEBUG = False
|
|
|
|
| 67 |
# Optional comparison models are imported lazily by their load functions.
|
| 68 |
VGGT_MODEL_NAME = "facebook/VGGT-1B"
|
| 69 |
PI3_MODEL_NAME = "yyfz233/Pi3X"
|
|
@@ -1260,6 +1261,12 @@ def get_pair_color_rgba(pair_index):
|
|
| 1260 |
return [int(c * 255) for c in rgba]
|
| 1261 |
|
| 1262 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1263 |
def add_crop_region_overlay(image, target_size=224):
|
| 1264 |
"""
|
| 1265 |
Add semi-transparent overlay to show regions that will be cropped out.
|
|
@@ -1275,7 +1282,7 @@ def add_crop_region_overlay(image, target_size=224):
|
|
| 1275 |
if image is None:
|
| 1276 |
return None
|
| 1277 |
|
| 1278 |
-
img_copy = image.
|
| 1279 |
W, H = img_copy.size
|
| 1280 |
|
| 1281 |
# Calculate resize and crop according to DUSt3R's logic
|
|
@@ -1657,7 +1664,7 @@ def handle_img1_click(evt: gr.SelectData):
|
|
| 1657 |
|
| 1658 |
# Convert to normalized coordinates
|
| 1659 |
if _session()["current_image_pair"][0]:
|
| 1660 |
-
width, height = _session()["current_image_pair"][0]
|
| 1661 |
x_norm = x_pixel / width
|
| 1662 |
y_norm = y_pixel / height
|
| 1663 |
debug_log(
|
|
@@ -1712,7 +1719,7 @@ def handle_img2_click(evt: gr.SelectData):
|
|
| 1712 |
|
| 1713 |
# Convert to normalized coordinates
|
| 1714 |
if _session()["current_image_pair"][1]:
|
| 1715 |
-
width, height = _session()["current_image_pair"][1]
|
| 1716 |
x_norm = x_pixel / width
|
| 1717 |
y_norm = y_pixel / height
|
| 1718 |
debug_log(
|
|
|
|
| 64 |
from click3r.demo.results import ReconstructionResult
|
| 65 |
|
| 66 |
DEBUG = False
|
| 67 |
+
DISPLAY_LONG_SIDE = 640 # Pixels; small inputs would otherwise be hard to click.
|
| 68 |
# Optional comparison models are imported lazily by their load functions.
|
| 69 |
VGGT_MODEL_NAME = "facebook/VGGT-1B"
|
| 70 |
PI3_MODEL_NAME = "yyfz233/Pi3X"
|
|
|
|
| 1261 |
return [int(c * 255) for c in rgba]
|
| 1262 |
|
| 1263 |
|
| 1264 |
+
def display_size(image):
|
| 1265 |
+
"""Size an image is shown at; clicks are stored as normalized coordinates."""
|
| 1266 |
+
scale = DISPLAY_LONG_SIDE / max(image.size)
|
| 1267 |
+
return round(image.width * scale), round(image.height * scale)
|
| 1268 |
+
|
| 1269 |
+
|
| 1270 |
def add_crop_region_overlay(image, target_size=224):
|
| 1271 |
"""
|
| 1272 |
Add semi-transparent overlay to show regions that will be cropped out.
|
|
|
|
| 1282 |
if image is None:
|
| 1283 |
return None
|
| 1284 |
|
| 1285 |
+
img_copy = image.resize(display_size(image), Image.LANCZOS)
|
| 1286 |
W, H = img_copy.size
|
| 1287 |
|
| 1288 |
# Calculate resize and crop according to DUSt3R's logic
|
|
|
|
| 1664 |
|
| 1665 |
# Convert to normalized coordinates
|
| 1666 |
if _session()["current_image_pair"][0]:
|
| 1667 |
+
width, height = display_size(_session()["current_image_pair"][0])
|
| 1668 |
x_norm = x_pixel / width
|
| 1669 |
y_norm = y_pixel / height
|
| 1670 |
debug_log(
|
|
|
|
| 1719 |
|
| 1720 |
# Convert to normalized coordinates
|
| 1721 |
if _session()["current_image_pair"][1]:
|
| 1722 |
+
width, height = display_size(_session()["current_image_pair"][1])
|
| 1723 |
x_norm = x_pixel / width
|
| 1724 |
y_norm = y_pixel / height
|
| 1725 |
debug_log(
|