Open shanalikhan opened 3 weeks ago
Hello,
Try this script and let me know how this goes for you. This should give you start for converting to Bounding boxes format
import json
def obb_to_bb(points):
# Extract x and y coordinates from the points
x_coords = [p[0] for p in points]
y_coords = [p[1] for p in points]
# Calculate bounding box values
xmin = min(x_coords)
xmax = max(x_coords)
ymin = min(y_coords)
ymax = max(y_coords)
return xmin, ymin, xmax, ymax
# Load your exported annotations
with open('export.json', 'r') as f:
data = json.load(f)
# Iterate through tasks and annotations
for task in data:
for annotation in task.get('annotations', []):
for result in annotation.get('result', []):
if result['type'] == 'polygonlabels':
points = result['value']['points']
# Convert the polygon to bounding box
xmin, ymin, xmax, ymax = obb_to_bb(points)
# Update the result to use rectangle labels
result['type'] = 'rectanglelabels'
result['value'] = {
'x': xmin,
'y': ymin,
'width': xmax - xmin,
'height': ymax - ymin,
'rectanglelabels': result['value']['polygonlabels']
}
# Save the updated annotations
with open('export_bb.json', 'w') as f:
json.dump(data, f, indent=4)
Thank you, Abu
Comment by Abubakar Saad Workflow Run
Is your feature request related to a problem? Please describe. Downloaded OBB format images dataset and looking to switch to BB to train other models (other than Yolo) that requires BB.
Describe the solution you'd like Any script, either UI or CLI based is possible to convert it to BB
Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.
Additional context Add any other context or screenshots about the feature request here.