Home > other >  Python3 openCV to obtain minimum circumscribed rectangle image text area
Python3 openCV to obtain minimum circumscribed rectangle image text area

Time:09-24

Print (" thresh="thresh)
Coords=np. Column_stack (np) where (thresh & gt; 0))//access to thresh binary gray level images of white text area point
Print (" coords=", coords)

Min_rect=cv2. MinAreaRect (coords)//by point set for the smallest rectangle (contains the center coordinates of points, width and height, deflection Angle)
Print (" min_rec=", min_rect)
Box=cv2. BoxPoints (min_rect)//get the four of the smallest rectangle vertex coordinates,


But through this draw a rectangle function, draw the text area and the smallest rectangle of deviation is large, but access to the deflection Angle is right,

They don't understand what to do?

# according to four painting the original rectangle
Def drawRect (img, pt1 pt2, pt3, pt4, color, our lineWidth) :
Cv2. Line (img, the tuple (pt1), the tuple (pt2) that, color, our lineWidth)
Cv2. Line (img, the tuple (pt2) that, the tuple (pt3), color, our lineWidth)
Cv2. Line (img, the tuple (pt3), the tuple (pt4), color, our lineWidth)
Cv2. Line (img, the tuple (pt1), the tuple (pt4), color, our lineWidth)
Any way friends passing by, give a hand, to show just a little, thank you for your friend

With experimental problem screenshots:

CodePudding user response:

Problem solved? You this specific what went wrong, expected to be debugged to know

CodePudding user response:


No problem, the smallest rectangle should not wrong, but should do a conversion

CodePudding user response:

Because this problem is to find a paragraph of external rectangle, so use common graphic external rectangle is not applicable, use foundconter found that method is scattered small box, understand not want people to help

CodePudding user response:

Coords=coords [: : : - 1)
X, y coordinates exchange,

CodePudding user response:

I also encountered this problem, this is the center of rotation coordinates is wrong, you need to see the rectangular center coordinates is changed, or the coordinate system is changed, the hope can help you

CodePudding user response:

It felt like the xy swapped, and slant Angle in the right direction, size should be right

CodePudding user response:

Draw a rectangular script is made up of yourself, or where to find?
  • Related