David Ko commited on
Commit
e95c1b8
ยท
1 Parent(s): cdc5e33

Fix: Update add_detected_objects to handle bbox as list or dict

Browse files
Files changed (1) hide show
  1. api.py +19 -5
api.py CHANGED
@@ -667,11 +667,25 @@ def add_detected_objects():
667
  object_id = f"{image_id}_{str(uuid.uuid4())[:8]}"
668
 
669
  # ๋ฐ”์šด๋”ฉ ๋ฐ•์Šค ์ •๋ณด ์ถ”์ถœ
670
- bbox = obj.get('bbox', {})
671
- x1 = bbox.get('x', 0)
672
- y1 = bbox.get('y', 0)
673
- width = bbox.get('width', 0)
674
- height = bbox.get('height', 0)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
675
 
676
  # ๋ฐ”์šด๋”ฉ ๋ฐ•์Šค๋ฅผ ์ด๋ฏธ์ง€ ์ขŒํ‘œ๋กœ ๋ณ€ํ™˜
677
  x1_px = int(x1 * image_width)
 
667
  object_id = f"{image_id}_{str(uuid.uuid4())[:8]}"
668
 
669
  # ๋ฐ”์šด๋”ฉ ๋ฐ•์Šค ์ •๋ณด ์ถ”์ถœ
670
+ bbox = obj.get('bbox', [])
671
+
672
+ # ๋ฆฌ์ŠคํŠธ ํ˜•ํƒœ์˜ bbox [x1, y1, x2, y2] ์ฒ˜๋ฆฌ
673
+ if isinstance(bbox, list) and len(bbox) >= 4:
674
+ x1 = bbox[0] / image_width # ์ •๊ทœํ™”๋œ ์ขŒํ‘œ๋กœ ๋ณ€ํ™˜
675
+ y1 = bbox[1] / image_height
676
+ x2 = bbox[2] / image_width
677
+ y2 = bbox[3] / image_height
678
+ width = x2 - x1
679
+ height = y2 - y1
680
+ # ๋”•์…”๋„ˆ๋ฆฌ ํ˜•ํƒœ์˜ bbox {'x': x, 'y': y, 'width': width, 'height': height} ์ฒ˜๋ฆฌ
681
+ elif isinstance(bbox, dict):
682
+ x1 = bbox.get('x', 0)
683
+ y1 = bbox.get('y', 0)
684
+ width = bbox.get('width', 0)
685
+ height = bbox.get('height', 0)
686
+ else:
687
+ # ๊ธฐ๋ณธ๊ฐ’ ์„ค์ •
688
+ x1, y1, width, height = 0, 0, 0, 0
689
 
690
  # ๋ฐ”์šด๋”ฉ ๋ฐ•์Šค๋ฅผ ์ด๋ฏธ์ง€ ์ขŒํ‘œ๋กœ ๋ณ€ํ™˜
691
  x1_px = int(x1 * image_width)