Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert OBB to BB #6527

Open
shanalikhan opened this issue Oct 16, 2024 · 1 comment
Open

Convert OBB to BB #6527

shanalikhan opened this issue Oct 16, 2024 · 1 comment

Comments

@shanalikhan
Copy link

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.

@heidi-humansignal
Copy link
Collaborator

heidi-humansignal commented Oct 16, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants