BBongiovanni commited on
Commit
12aac48
1 Parent(s): cd7fffd

downsampled images and only overlay points at len=4

Browse files
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
- # 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
 
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="Homography", row_count=3, col_count=3, headers=['', '', ''], interactive=False)
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
- # demo.launch()
 
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

  • SHA256: 41def982cb3a0ac8dfa67da2bb1612a038aefb31ef72ffc1519304159980b057
  • Pointer size: 131 Bytes
  • Size of remote file: 234 kB

Git LFS Details

  • SHA256: 691641704a872d13ee7a7c68148ce7f7f8d26b7ba7bebdee3e4bc8768f034018
  • Pointer size: 130 Bytes
  • Size of remote file: 47.1 kB
warp_test_images/billboard2.jpg CHANGED

Git LFS Details

  • SHA256: 4fbd82172664236ab0a2cf43ec5016ab80e1351363172adcc82408db6cf5ae41
  • Pointer size: 131 Bytes
  • Size of remote file: 124 kB

Git LFS Details

  • SHA256: f341d7e7f7ef4fdc64e3c8997e088a0fd651afa7e0ad9e191f6cfd4b2bffaa1d
  • Pointer size: 130 Bytes
  • Size of remote file: 18.9 kB
warp_test_images/test2.jpg CHANGED

Git LFS Details

  • SHA256: 833161b80bc6443d3f0986b71917867548ad5e212a3bc43b54c603b37df164a9
  • Pointer size: 131 Bytes
  • Size of remote file: 167 kB

Git LFS Details

  • SHA256: b08f7ee51102d1c6b9d2359a7965152e0b167f23ae8559955395fac9cabf094f
  • Pointer size: 130 Bytes
  • Size of remote file: 71 kB
warp_test_images/venice.jpg CHANGED

Git LFS Details

  • SHA256: 133d23d6a2781ec746177439f740cbe8e920c00b2a3df0ef97c6afd7cc7fd7fc
  • Pointer size: 131 Bytes
  • Size of remote file: 430 kB

Git LFS Details

  • SHA256: 9b579d75cf90fce4cea6761f8821ec2f9ca1c341a08ee6cc3fe34f39f4188682
  • Pointer size: 130 Bytes
  • Size of remote file: 80.7 kB