leptonica icon indicating copy to clipboard operation
leptonica copied to clipboard

get minarea-rotated box of a skew area

Open dorami123 opened this issue 10 months ago • 2 comments

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

dorami123 avatar Apr 08 '24 12:04 dorami123

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.

DanBloomberg avatar Apr 08 '24 20:04 DanBloomberg

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

dorami123 avatar Apr 09 '24 00:04 dorami123