Alessio Grancini
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -230,6 +230,7 @@ def get_bbox_from_mask(mask):
|
|
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,10 +250,13 @@ def get_detection_data(image_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,6 +273,8 @@ def get_detection_data(image_data):
|
|
269 |
"distance": depth_value
|
270 |
})
|
271 |
|
|
|
|
|
272 |
response = {
|
273 |
"detections": detections,
|
274 |
"segmentation_url": save_image_to_url(image_segmentation),
|
@@ -276,7 +282,7 @@ def get_detection_data(image_data):
|
|
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]
|
280 |
}
|
281 |
return response
|
282 |
|
@@ -285,6 +291,7 @@ def get_detection_data(image_data):
|
|
285 |
return {"error": str(e)}
|
286 |
|
287 |
|
|
|
288 |
def cancel():
|
289 |
CANCEL_PROCESSING = True
|
290 |
|
|
|
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 |
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 |
"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 |
"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 |
return {"error": str(e)}
|
292 |
|
293 |
|
294 |
+
|
295 |
def cancel():
|
296 |
CANCEL_PROCESSING = True
|
297 |
|