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

Adding support for cuboids and rotated boxes #2296

Merged
merged 8 commits into from Mar 4, 2023

Conversation

brimoor
Copy link
Contributor

@brimoor brimoor commented Nov 12, 2022

Resolves #1947
Resolves #1821

Adds Polyline.from_cuboid() and Polyline.from_rotated_box() factory methods that enable loading cuboids and rotated boxes into FiftyOne using natural representations of them.

We could also consider native Cuboid and RotatedBox types so that users could access the definitions of these shapes (particularly rotated boxes) in their native formats, but I think this is a reasonable starting place. And no App code required 🤗

Rotated boxes

import cv2
import numpy as np
import fiftyone as fo

def random_rotated_box():
    xc, yc = 0.2 + 0.6 * np.random.rand(2)
    w, h = 1.5 * (min(xc, yc, 1 - xc, 1 - yc)) * np.random.rand(2)
    theta = 2 * np.pi * np.random.rand()
    return fo.Polyline.from_rotated_box(xc, yc, w, h, theta, label="box")

filepath = "/tmp/image.png"
cv2.imwrite(filepath, np.full((16, 16, 3), 255, dtype=np.uint8))

dataset = fo.Dataset("rotated-boxes")
dataset.add_samples(
    [fo.Sample(filepath=filepath, box=random_rotated_box()) for _ in range(51)]
)

session = fo.launch_app(dataset)

rotated-bounding-boxes

Cuboids

import cv2
import numpy as np
import fiftyone as fo

def random_cuboid():
    x0, y0 = [0, 0.2] + 0.8 * np.random.rand(2)
    dx, dy = (min(0.8 - x0, y0 - 0.2)) * np.random.rand(2)
    x1, y1 = x0 + dx, y0 - dy
    w, h = (min(1 - x1, y1)) * np.random.rand(2)
    front = [(x0, y0), (x0 + w, y0), (x0 + w, y0 - h), (x0, y0 - h)]
    back = [(x1, y1), (x1 + w, y1), (x1 + w, y1 - h), (x1, y1 - h)]
    return fo.Polyline.from_cuboid(front + back, label="cuboid")

filepath = "/tmp/image.png"
cv2.imwrite(filepath, np.full((16, 16, 3), 255, dtype=np.uint8))

dataset = fo.Dataset("cuboids")
dataset.add_samples(
    [fo.Sample(filepath=filepath, cuboid=random_cuboid()) for _ in range(51)]
)

session = fo.launch_app(dataset)

cuboids

@brimoor brimoor added the feature Work on a feature request label Nov 12, 2022
@brimoor brimoor requested a review from a team November 12, 2022 04:28
@brimoor brimoor self-assigned this Nov 12, 2022
@brimoor brimoor changed the title Adding support for loading cuboids and rotated boxes Adding support for cuboids and rotated boxes Nov 12, 2022
@brimoor brimoor changed the title Adding support for cuboids and rotated boxes [HOLD] Adding support for cuboids and rotated boxes Jan 17, 2023
@brimoor brimoor changed the title [HOLD] Adding support for cuboids and rotated boxes Adding support for cuboids and rotated boxes Mar 4, 2023
@codecov
Copy link

codecov bot commented Mar 4, 2023

Codecov Report

Patch coverage has no change and project coverage change: +12.97 🎉

Comparison is base (f663778) 48.43% compared to head (c0f75ce) 61.41%.

❗ Current head c0f75ce differs from pull request most recent head 033c7a5. Consider uploading reports for the commit 033c7a5 to get more accurate results

Additional details and impacted files
@@             Coverage Diff              @@
##           develop    #2296       +/-   ##
============================================
+ Coverage    48.43%   61.41%   +12.97%     
============================================
  Files          234      256       +22     
  Lines        32009    42944    +10935     
  Branches       349      349               
============================================
+ Hits         15505    26374    +10869     
- Misses       16504    16570       +66     
Flag Coverage Δ
app 48.43% <ø> (ø)
python 99.39% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
tests/unittests/video_tests.py 99.87% <0.00%> (ø)
tests/unittests/similarity_tests.py 95.23% <0.00%> (ø)
tests/unittests/utils/openlabel.py 95.45% <0.00%> (ø)
tests/unittests/sample_tests.py 99.64% <0.00%> (ø)
tests/unittests/server_tests.py 100.00% <0.00%> (ø)
tests/unittests/label_tests.py 95.65% <0.00%> (ø)
tests/unittests/import_export_tests.py 99.84% <0.00%> (ø)
tests/unittests/dataset_tests.py 99.82% <0.00%> (ø)
tests/unittests/view_tests.py 99.85% <0.00%> (ø)
tests/unittests/evaluation_tests.py 99.81% <0.00%> (ø)
... and 12 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@brimoor brimoor merged commit 6531dd0 into develop Mar 4, 2023
@brimoor brimoor deleted the feature/cuboids-and-rotated-boxes branch March 4, 2023 18:42
@imanjra imanjra restored the feature/cuboids-and-rotated-boxes branch March 4, 2023 20:47
@imanjra imanjra deleted the feature/cuboids-and-rotated-boxes branch March 4, 2023 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Work on a feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FR] Add support for rendering 2D cuboids on images/videos [FR] Add support for rotated bounding boxes
1 participant