Skip to content
Snippets Groups Projects
Commit e6081e03 authored by Mahmoud Ahmed Ali's avatar Mahmoud Ahmed Ali
Browse files

Add 2d bbox file

parent 3cbf4149
No related branches found
No related tags found
No related merge requests found
import math
import numpy as np
import json
def bbox_2d(data_sample):
center = data_sample['bbox']['center']
size = data_sample['bbox']['size']
bbox_res = []
top_left_x, top_left_y = center[0] - (size[0] / 2), center[1] - (size[1] / 2)
bbox_res.append(top_left_x)
bbox_res.append(top_left_y)
bottom_right_x, bottom_right_y = center[0] + (size[0] / 2), center[1] + (size[1] / 2)
bbox_res.append(bottom_right_x)
bbox_res.append(bottom_right_y)
return bbox_res
def generate_2d_bbox(data_name):
cont1, cont2, cont3 = 0, 0, 0
num_arr = 0
for p in range(4995):
with open(f"{data_name}/Bbox_2d/{p}.json", 'r') as f:
data = json.load(f)
for i in range(len(data)):
if data[i]['id'] == 4:
cont1 += 1
bbox = bbox_2d(data[i])
np.savetxt(f'{data_name}/Bbox/Banana/{p}.txt', np.array(bbox).reshape((1, 4))) # save
elif data[i]['id'] == 5:
cont2 += 1
bbox = bbox_2d(data[i])
np.savetxt(f'{data_name}/Bbox/Orange/{p}.txt', np.array(bbox).reshape((1, 4))) # save
elif data[i]['id'] == 6:
cont3 += 1
bbox = bbox_2d(data[i])
np.savetxt(f'{data_name}/Bbox/Pear/{p}.txt', np.array(bbox).reshape((1, 4))) # save
else:
continue
print(cont1, cont2, cont3)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment