I am drawing a line of vehicles on the image, how could I get the coordinates and bounds of each vehicle in the image, since I want to crop the these vehicles one by one from this image?
I found a snippet, but the values (x , y, width, height) seem to be like the global coordinates rather than the pixel position on the image.
def get_bounds(ob):
mat = ob.matrix_world
bbox = [mat * Vector(b) for b in ob.bound_box]
min_x = min(b.x for b in bbox)
max_x = max(b.x for b in bbox)
min_y = min(b.y for b in bbox)
max_y = max(b.y for b in bbox)
top_left = Vector((min_x, max_y))
bottom_right = Vector((max_x, min_y))
# make flat tuple, x y width height
return top_left.to_tuple() + tuple(map(abs, (top_left - bottom_right)))