IbrahimHasani commited on
Commit
bc74179
1 Parent(s): ab46ec6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -10
app.py CHANGED
@@ -71,6 +71,23 @@ def unified_matching_plot2(image0, image1, kpts0, kpts1, mkpts0, mkpts1, color,
71
 
72
  return img
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  # Main functions
75
  def detect_and_crop(target_image, query_image, threshold=0.5, nms_threshold=0.3):
76
  target_sizes = torch.Tensor([target_image.size[::-1]])
@@ -187,20 +204,21 @@ iface = gr.Interface(
187
  gr.Image(type="pil", label="Upload a Query Image (Poster)"),
188
  gr.Image(type="pil", label="Upload a Target Image (Media)"),
189
  gr.Slider(minimum=0, maximum=100, step=1, value=50, label="Threshold"),
190
- gr.CheckboxGroup(choices=[0.33, 0.66, 1.0], value=[0.33, 0.66, 1.0], label="Scale Factors")
191
  ],
192
  outputs=[
193
- gr.JSON(label="Result")
 
194
  ],
195
- title="Object Detection in Image",
196
  description="""
197
- **Instructions:**
198
-
199
- 1. **Upload a Query Image (Poster)**: Select an image file that contains the object you want to detect.
200
- 2. **Upload a Target Image (Media)**: Select an image file where you want to detect the object.
201
- 3. **Set Threshold**: Adjust the slider to set the threshold for object detection.
202
- 4. **Set Scale Factors**: Select the scale factors for image pyramid.
203
- 5. **View Results**: The result will show whether the object is present in the image along with additional details.
204
  """
205
  )
206
 
 
71
 
72
  return img
73
 
74
+ def stitch_images(images):
75
+ """Stitches a list of images vertically."""
76
+ if not images:
77
+ return Image.new('RGB', (100, 100), color='gray')
78
+
79
+ max_width = max([img.width for img in images])
80
+ total_height = sum(img.height for img in images)
81
+
82
+ composite = Image.new('RGB', (max_width, total_height))
83
+
84
+ y_offset = 0
85
+ for img in images:
86
+ composite.paste(img, (0, y_offset))
87
+ y_offset += img.height
88
+
89
+ return composite
90
+
91
  # Main functions
92
  def detect_and_crop(target_image, query_image, threshold=0.5, nms_threshold=0.3):
93
  target_sizes = torch.Tensor([target_image.size[::-1]])
 
204
  gr.Image(type="pil", label="Upload a Query Image (Poster)"),
205
  gr.Image(type="pil", label="Upload a Target Image (Media)"),
206
  gr.Slider(minimum=0, maximum=100, step=1, value=50, label="Threshold"),
207
+ gr.CheckboxGroup(choices=["0.33", "0.66", "1.0"], value=["0.33", "0.66", "1.0"], label="Scale Factors"),
208
  ],
209
  outputs=[
210
+ gr.Label(label="Object Presence"),
211
+ gr.Image(type="pil", label="Detected Bounding Boxes"),
212
  ],
213
+ title="Object Detection in Images",
214
  description="""
215
+ This application allows you to check if an object in a query image (poster) is present in a target image (media).
216
+ Steps:
217
+ 1. Upload a Query Image (Poster)
218
+ 2. Upload a Target Image (Media)
219
+ 3. Set Threshold
220
+ 4. Set Scale Factors
221
+ 5. View Results
222
  """
223
  )
224