Skip to content

Commit 2265db3

Browse files
committed
update parsing
1 parent f87b2fc commit 2265db3

1 file changed

Lines changed: 19 additions & 17 deletions

File tree

predicators/spot_utils/perception/utils/gemini_parsing.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,22 +83,24 @@ def parse_gemini_detection_response(
8383
json_str = response[start:end]
8484
detection_data = json.loads(json_str)
8585

86-
# Validate and normalize boxes
86+
# Validate and normalize boxes (Gemini uses [ymin, xmin, ymax, xmax])
8787
normalized_boxes = []
8888
for item in detection_data:
8989
box = item["box_2d"]
9090
if not isinstance(box, list) or len(box) != 4:
9191
raise ValueError(f"Invalid box format: {box}")
92-
92+
ymin, xmin, ymax, xmax = box
9393
if normalize and image_size:
94-
# Convert to normalized coordinates [0-1000]
95-
x1, y1, x2, y2 = box
96-
x1 = x1 * 1000 / image_size[0]
97-
y1 = y1 * 1000 / image_size[1]
98-
x2 = x2 * 1000 / image_size[0]
99-
y2 = y2 * 1000 / image_size[1]
100-
box = [x1, y1, x2, y2]
101-
94+
xmin = xmin * 1000 / image_size[0]
95+
xmax = xmax * 1000 / image_size[0]
96+
ymin = ymin * 1000 / image_size[1]
97+
ymax = ymax * 1000 / image_size[1]
98+
box = [
99+
_clamp(float(xmin), 0.0, 1000.0),
100+
_clamp(float(ymin), 0.0, 1000.0),
101+
_clamp(float(xmax), 0.0, 1000.0),
102+
_clamp(float(ymax), 0.0, 1000.0),
103+
]
102104
normalized_boxes.append({
103105
"box_2d": box,
104106
"label": str(item["label"])
@@ -137,15 +139,15 @@ def denormalize_box(
137139
"""Convert normalized box [0-1000] back to image coordinates.
138140
139141
Args:
140-
box: Normalized box coordinates [x1, y1, x2, y2]
142+
box: Normalized box coordinates [xmin, ymin, xmax, ymax]
141143
image_size: Size of the image (width, height)
142144
143145
Returns:
144146
Box coordinates in image space
145147
"""
146-
x1, y1, x2, y2 = box
147-
x1 = _clamp(float(x1), 0.0, 1000.0) * image_size[0] / 1000
148-
y1 = _clamp(float(y1), 0.0, 1000.0) * image_size[1] / 1000
149-
x2 = _clamp(float(x2), 0.0, 1000.0) * image_size[0] / 1000
150-
y2 = _clamp(float(y2), 0.0, 1000.0) * image_size[1] / 1000
151-
return [x1, y1, x2, y2]
148+
xmin, ymin, xmax, ymax = box
149+
xmin = _clamp(float(xmin), 0.0, 1000.0) * image_size[0] / 1000
150+
xmax = _clamp(float(xmax), 0.0, 1000.0) * image_size[0] / 1000
151+
ymin = _clamp(float(ymin), 0.0, 1000.0) * image_size[1] / 1000
152+
ymax = _clamp(float(ymax), 0.0, 1000.0) * image_size[1] / 1000
153+
return [xmin, ymin, xmax, ymax]

0 commit comments

Comments
 (0)