leptonica
leptonica copied to clipboard
get minarea-rotated box of a skew area
I want to get a compact box of the black pixs in the pic below:
It is easier to get horizontal boxes using leptonica like this, but it is not compact.
the pic below is what I want:
opencv provide a function: cv::minAreaRect to achieve this, but how can I implement it with leptonica?
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.
Thanks for your reply! I will have a try with leptonica, for I don't want to introduce other dependencies.