Alessio Grancini
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -230,7 +230,6 @@ def get_bbox_from_mask(mask):
|
|
| 230 |
@spaces.GPU
|
| 231 |
def get_detection_data(image_data):
|
| 232 |
try:
|
| 233 |
-
# Decode base64 image
|
| 234 |
if isinstance(image_data, dict):
|
| 235 |
nested_dict = image_data.get("image", {}).get("image", {})
|
| 236 |
full_data_url = nested_dict.get("data", "")
|
|
@@ -250,13 +249,10 @@ def get_detection_data(image_data):
|
|
| 250 |
img = np.array(img)
|
| 251 |
img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
|
| 252 |
|
| 253 |
-
# Run detection
|
| 254 |
image = utils.resize(img)
|
| 255 |
image_segmentation, objects_data = img_seg.predict(image)
|
| 256 |
depthmap, depth_colormap = depth_estimator.make_prediction(image)
|
| 257 |
|
| 258 |
-
print("✅ Detected Objects:", objects_data) # Log detected objects
|
| 259 |
-
|
| 260 |
detections = []
|
| 261 |
for obj in objects_data:
|
| 262 |
cls_id, cls_name, center, mask, _ = obj
|
|
@@ -273,8 +269,6 @@ def get_detection_data(image_data):
|
|
| 273 |
"distance": depth_value
|
| 274 |
})
|
| 275 |
|
| 276 |
-
print("✅ Processed Detections:", detections) # Log final detections
|
| 277 |
-
|
| 278 |
response = {
|
| 279 |
"detections": detections,
|
| 280 |
"segmentation_url": save_image_to_url(image_segmentation),
|
|
@@ -282,7 +276,7 @@ def get_detection_data(image_data):
|
|
| 282 |
"distance_url": save_image_to_url(utils.draw_depth_info(image, depthmap, objects_data)),
|
| 283 |
"point_cloud_url": save_plot_to_url(utils.generate_obj_pcd(depthmap, objects_data)),
|
| 284 |
"camera_matrix": get_camera_matrix(depth_estimator),
|
| 285 |
-
"camera_position": [0, 0, 0]
|
| 286 |
}
|
| 287 |
return response
|
| 288 |
|
|
@@ -291,7 +285,6 @@ def get_detection_data(image_data):
|
|
| 291 |
return {"error": str(e)}
|
| 292 |
|
| 293 |
|
| 294 |
-
|
| 295 |
def cancel():
|
| 296 |
CANCEL_PROCESSING = True
|
| 297 |
|
|
@@ -420,4 +413,4 @@ if __name__ == "__main__":
|
|
| 420 |
options_checkbox_vid.change(update_segmentation_options, options_checkbox_vid, [])
|
| 421 |
conf_thres_vid.change(update_confidence_threshold, conf_thres_vid, [])
|
| 422 |
|
| 423 |
-
my_app.queue(max_size=20).launch(share=True) # Add share=True here
|
|
|
|
| 230 |
@spaces.GPU
|
| 231 |
def get_detection_data(image_data):
|
| 232 |
try:
|
|
|
|
| 233 |
if isinstance(image_data, dict):
|
| 234 |
nested_dict = image_data.get("image", {}).get("image", {})
|
| 235 |
full_data_url = nested_dict.get("data", "")
|
|
|
|
| 249 |
img = np.array(img)
|
| 250 |
img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
|
| 251 |
|
|
|
|
| 252 |
image = utils.resize(img)
|
| 253 |
image_segmentation, objects_data = img_seg.predict(image)
|
| 254 |
depthmap, depth_colormap = depth_estimator.make_prediction(image)
|
| 255 |
|
|
|
|
|
|
|
| 256 |
detections = []
|
| 257 |
for obj in objects_data:
|
| 258 |
cls_id, cls_name, center, mask, _ = obj
|
|
|
|
| 269 |
"distance": depth_value
|
| 270 |
})
|
| 271 |
|
|
|
|
|
|
|
| 272 |
response = {
|
| 273 |
"detections": detections,
|
| 274 |
"segmentation_url": save_image_to_url(image_segmentation),
|
|
|
|
| 276 |
"distance_url": save_image_to_url(utils.draw_depth_info(image, depthmap, objects_data)),
|
| 277 |
"point_cloud_url": save_plot_to_url(utils.generate_obj_pcd(depthmap, objects_data)),
|
| 278 |
"camera_matrix": get_camera_matrix(depth_estimator),
|
| 279 |
+
"camera_position": [0, 0, 0] # Assumed at origin based on camera intrinsics
|
| 280 |
}
|
| 281 |
return response
|
| 282 |
|
|
|
|
| 285 |
return {"error": str(e)}
|
| 286 |
|
| 287 |
|
|
|
|
| 288 |
def cancel():
|
| 289 |
CANCEL_PROCESSING = True
|
| 290 |
|
|
|
|
| 413 |
options_checkbox_vid.change(update_segmentation_options, options_checkbox_vid, [])
|
| 414 |
conf_thres_vid.change(update_confidence_threshold, conf_thres_vid, [])
|
| 415 |
|
| 416 |
+
my_app.queue(max_size=20).launch(share=True) # Add share=True here
|