MCPcopy Create free account
hub / github.com/ChartGalaxy/ChartGalaxy / get_bboxes

Function get_bboxes

code_generation_benchmark/utils/utils_vis_bbox.py:80–109  ·  view source on GitHub ↗

Get bounding boxes from a JSON file. Args: json_path: str, path to the JSON file Returns: list of tuples: each tuple is (x_min, y_min, x_max, y_max)

(json_path)

Source from the content-addressed store, hash-verified

78 return result
79
80def get_bboxes(json_path):
81 """
82 Get bounding boxes from a JSON file.
83
84 Args:
85 json_path: str, path to the JSON file
86
87 Returns:
88 list of tuples: each tuple is (x_min, y_min, x_max, y_max)
89 """
90 import json
91 with open(json_path, 'r') as f:
92 data = json.load(f)
93 bb = data['bounding_box']
94 xx, yy, ww, hh = bb['x'], bb['y'], bb['width'], bb['height']
95
96 bboxes = []
97 def traverse_dict(d):
98 if isinstance(d, dict):
99 bb = d.get('bounding_box')
100 if bb:
101 x, y, w, h = bb['x'], bb['y'], bb['width'], bb['height']
102 bboxes.append(((x-xx)/ww, (y-yy)/hh, (x+w-xx)/ww, (y+h-yy)/hh))
103 traverse_dict(d.get('children', []))
104 elif isinstance(d, list):
105 for item in d:
106 traverse_dict(item)
107 traverse_dict(data)
108
109 return bboxes
110
111def vis_bboxes(json_path, image_path=None):
112 if not image_path:

Callers 1

vis_bboxesFunction · 0.85

Calls 1

traverse_dictFunction · 0.85

Tested by

no test coverage detected