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

get minarea-rotated box of a skew area #741

Open
dorami123 opened this issue Apr 8, 2024 · 2 comments
Open

get minarea-rotated box of a skew area #741

dorami123 opened this issue Apr 8, 2024 · 2 comments

Comments

@dorami123
Copy link

I want to get a compact box of the black pixs in the pic below:
areas
It is easier to get horizontal boxes using leptonica like this, but it is not compact.
bounded_areas

the pic below is what I want:
bounded_areas_minbox
opencv provide a function: cv::minAreaRect to achieve this, but how can I implement it with leptonica?
image

@DanBloomberg
Copy link
Owner

Cute!

Sorry, but leptonica doesn't support rotated boxes. An unrotated box has 4 parameters (e.g, UL and LR corners, or UL corner, width and height); a rotated box has 5 because it also has to specify the rotation angle.

You could find the rotation angle for each box separately by choosing rotation angles as with the skew detection function, and doing the search, finding the angle that minimizes the area of the bounding rectangle.

The only data structure in leptonica that can be used to hold arbitrary quadrilaterals is a Pta, where 4 points are used to store each quad. This is used in some functions in boxfunc4.c, but it doesn't directly help with rotated rectangles.

@dorami123
Copy link
Author

Thanks for your reply!
I will have a try with leptonica, for I don't want to introduce other dependencies.

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

No branches or pull requests

2 participants