normalize-bbox
Sun Apr 16 2023 10:35:09 GMT+0000 (Coordinated Universal Time)
Saved by
@mehla99_shubham
#python
######## scaled data #############
def normalize_bbox(bboxes,img):
# removing the fist and last coordinates
bboxes= bboxes[1:-1]
# Define the new image size
new_width = 100
new_height = 100
original_width,original_height = img.size
# Calculate the scaling factors
x_scale = new_width / original_width
y_scale = new_height / original_height
#parsing the bboxes
new_bboxes = []
for bbox in bboxes:
x1,y1,x2,y2 = bbox
# Normalize the bounding box coordinates
new_x1 = int(x1 * x_scale)
new_y1 = int(y1 * y_scale)
new_x2 = int(x2 * x_scale)
new_y2 = int(y2 * y_scale)
new_bbox = new_x1,new_y1,new_x2,new_y2
new_bboxes.append(new_bbox)
return new_bboxes
content_copyCOPY
Comments