DanBloomberg / leptonica

Leptonica is an open source library containing software that is broadly useful for image processing and image analysis applications. The official github repository for Leptonica is: danbloomberg/leptonica. See leptonica.org for more documentation.
Other
1.72k stars 384 forks source link

get minarea-rotated box of a skew area #741

Open dorami123 opened 3 months ago

dorami123 commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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