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

fix: Fixed geometry utils for polygon <--> rbox conversions #700

Merged
merged 3 commits into from
Dec 13, 2021
Merged

Conversation

fg-mindee
Copy link
Contributor

@fg-mindee fg-mindee commented Dec 10, 2021

This PR introduces the following modifications:

  • fixes the cv2 conventions of angle orientation for polygon <--> rbox conversions
  • updates unittests

The following snippet:

import numpy as np
import matplotlib.pyplot as plt
from doctr.utils.geometry import rbbox_to_polygon

def plot_points(points):
    img = np.zeros((200, 150))
    for point in points.round().astype(int):
        img[point[1], point[0]] = 1
    plt.imshow(img); plt.show()


# Horizontal word rotated counter-clockwise by 45°
plot_points(rbbox_to_polygon((100, 100, 40, 10, 45.)))

was producing
before_rot

and now produces
now_rot

Additionally this snippet:

import numpy as np
import matplotlib.pyplot as plt
from doctr.utils.geometry import rbbox_to_polygon, fit_rbbox

angles = np.arange(-90, 91)
rboxes = [fit_rbbox(rbbox_to_polygon((100, 100, 40, 10, angle)))for angle in angles]
estimated_angles = [rbox[-1] for rbox in rboxes]
estimated_width = [rbox[2] for rbox in rboxes]

plt.plot(angles, estimated_angles, label="angles")
plt.plot(angles, estimated_width, label="width")
plt.xlabel("Anti-clockwise rotation")
plt.legend(loc="upper left")
plt.show()

used to yield:

before

and now yields (similar to before, we can't do more because of cv2):
now

Any feedback is welcome!

@fg-mindee fg-mindee added type: bug Something isn't working module: utils Related to doctr.utils labels Dec 10, 2021
@fg-mindee fg-mindee added this to the 0.5.0 milestone Dec 10, 2021
@fg-mindee fg-mindee self-assigned this Dec 10, 2021
@codecov
Copy link

codecov bot commented Dec 10, 2021

Codecov Report

Merging #700 (e6d9d04) into main (d67abd4) will increase coverage by 0.06%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #700      +/-   ##
==========================================
+ Coverage   96.01%   96.08%   +0.06%     
==========================================
  Files         124      124              
  Lines        4648     4648              
==========================================
+ Hits         4463     4466       +3     
+ Misses        185      182       -3     
Flag Coverage Δ
unittests 96.08% <100.00%> (+0.06%) ⬆️

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

Impacted Files Coverage Δ
doctr/utils/geometry.py 98.00% <100.00%> (ø)
doctr/models/detection/linknet/base.py 83.16% <0.00%> (-1.99%) ⬇️
...dels/detection/differentiable_binarization/base.py 92.22% <0.00%> (+2.77%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d67abd4...e6d9d04. Read the comment docs.

Copy link
Collaborator

@charlesmindee charlesmindee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@fg-mindee fg-mindee merged commit 2507a73 into main Dec 13, 2021
@fg-mindee fg-mindee deleted the geom-fix branch December 13, 2021 09:58
@fg-mindee fg-mindee added the ext: tests Related to tests folder label Dec 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ext: tests Related to tests folder module: utils Related to doctr.utils type: bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants