Spaces:
Runtime error
Runtime error
Commit
•
12aac48
1
Parent(s):
cd7fffd
downsampled images and only overlay points at len=4
Browse files- app.py +11 -9
- warp_test_images/billboard.jpg +2 -2
- warp_test_images/billboard2.jpg +2 -2
- warp_test_images/test2.jpg +2 -2
- warp_test_images/venice.jpg +2 -2
app.py
CHANGED
@@ -60,7 +60,6 @@ def click_callback(img_path, evt: gr.SelectData):
|
|
60 |
# Save off a copy of the first input image
|
61 |
if len(roi_coords) == 0:
|
62 |
input_image = copy.copy(img)
|
63 |
-
display_image = copy.copy(input_image)
|
64 |
|
65 |
# Either create a new coordinate, or adjust the position of an existing coordinate
|
66 |
if len(roi_coords) < 4:
|
@@ -69,17 +68,20 @@ def click_callback(img_path, evt: gr.SelectData):
|
|
69 |
distances = [math.dist(evt.index, coord) for coord in roi_coords]
|
70 |
roi_coords[np.argmin(distances)] = evt.index
|
71 |
|
72 |
-
# Only overlay the bounding box if all four coordinates have been defined
|
73 |
if len(roi_coords) == 4:
|
|
|
|
|
74 |
# Overlay the corners of the ROI
|
75 |
pts = np.array(roi_coords, np.int32).reshape((-1, 1, 2))
|
76 |
cv2.polylines(display_image, [pts], True, (255, 255, 255), 2)
|
77 |
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
|
82 |
-
|
|
|
|
|
83 |
|
84 |
|
85 |
def clear_variables(*kwargs):
|
@@ -143,7 +145,7 @@ with gr.Blocks() as demo:
|
|
143 |
image_output = gr.Image(label="Cropped Warp", type="filepath", tool="editor", interactive=True)
|
144 |
slider_image_width = gr.Slider(label="Width", minimum=10, maximum=900, step=1)
|
145 |
slider_image_height = gr.Slider(label="Height", minimum=10, maximum=900, step=1)
|
146 |
-
json_t_matrix = gr.Numpy(label="
|
147 |
|
148 |
image_input.select(click_callback, image_input, [image_input, image_output, json_t_matrix, slider_image_width, slider_image_height])
|
149 |
image_input.clear(clear_variables)
|
@@ -152,5 +154,5 @@ with gr.Blocks() as demo:
|
|
152 |
slider_image_height.release(resize_image, [image_output, gr.State(None), slider_image_height], image_output)
|
153 |
|
154 |
demo.queue(concurrency_count=10, max_size=20)
|
155 |
-
demo.launch(inbrowser=True)
|
156 |
-
|
|
|
60 |
# Save off a copy of the first input image
|
61 |
if len(roi_coords) == 0:
|
62 |
input_image = copy.copy(img)
|
|
|
63 |
|
64 |
# Either create a new coordinate, or adjust the position of an existing coordinate
|
65 |
if len(roi_coords) < 4:
|
|
|
68 |
distances = [math.dist(evt.index, coord) for coord in roi_coords]
|
69 |
roi_coords[np.argmin(distances)] = evt.index
|
70 |
|
|
|
71 |
if len(roi_coords) == 4:
|
72 |
+
display_image = copy.copy(input_image)
|
73 |
+
|
74 |
# Overlay the corners of the ROI
|
75 |
pts = np.array(roi_coords, np.int32).reshape((-1, 1, 2))
|
76 |
cv2.polylines(display_image, [pts], True, (255, 255, 255), 2)
|
77 |
|
78 |
+
# Always overlay the location of the coordinates
|
79 |
+
for coord in roi_coords:
|
80 |
+
cv2.circle(display_image, coord, radius=5, color=(255, 0, 0), thickness=-1)
|
81 |
|
82 |
+
return display_image, *get_warped_image()
|
83 |
+
else:
|
84 |
+
return input_image, *get_warped_image()
|
85 |
|
86 |
|
87 |
def clear_variables(*kwargs):
|
|
|
145 |
image_output = gr.Image(label="Cropped Warp", type="filepath", tool="editor", interactive=True)
|
146 |
slider_image_width = gr.Slider(label="Width", minimum=10, maximum=900, step=1)
|
147 |
slider_image_height = gr.Slider(label="Height", minimum=10, maximum=900, step=1)
|
148 |
+
json_t_matrix = gr.Numpy(label="Transformation Matrix", row_count=3, col_count=3, headers=['', '', ''], interactive=False)
|
149 |
|
150 |
image_input.select(click_callback, image_input, [image_input, image_output, json_t_matrix, slider_image_width, slider_image_height])
|
151 |
image_input.clear(clear_variables)
|
|
|
154 |
slider_image_height.release(resize_image, [image_output, gr.State(None), slider_image_height], image_output)
|
155 |
|
156 |
demo.queue(concurrency_count=10, max_size=20)
|
157 |
+
# demo.launch(inbrowser=True)
|
158 |
+
demo.launch()
|
warp_test_images/billboard.jpg
CHANGED
![]() |
Git LFS Details
|
![]() |
Git LFS Details
|
warp_test_images/billboard2.jpg
CHANGED
![]() |
Git LFS Details
|
![]() |
Git LFS Details
|
warp_test_images/test2.jpg
CHANGED
![]() |
Git LFS Details
|
![]() |
Git LFS Details
|
warp_test_images/venice.jpg
CHANGED
![]() |
Git LFS Details
|
![]() |
Git LFS Details
|