Use python opencv to return the minimum bounding rectangle of the point set cnt. The function used is cv2.minAreaRect(cnt) . cnt is the array or vector of points of the minimum bounding rectangle required. This point set is indefinite.
For example: draw a minimum circumscribed rectangle of an arbitrary quadrilateral, where cnt represents the coordinates of the four vertices of the quad (there are 4 points in the point set)
Cnt = np.array([[x1,y1],[x2,y2],[x3,y3],[x4,y4]]) # must be in the form of array
Rect = cv2.minAreaRect(cnt) # Get the minimum bounding rectangle (center (x, y), (width, height), rotation angle)
box = cv2.cv.BoxPoints(rect) # cv2.boxPoints(rect) for OpenCV 3.x Get the 4 vertices of the minimum bounding rectangle
box = np.int0(box)
The function cv2.minAreaRect() returns a Box2D structure rect: (the center of the smallest circumscribed rectangle (x, y), (width, height), rotation angle).
But to draw this rectangle, we need the four vertex coordinates of the rectangle, obtained by the function cv2.cv.BoxPoints(), box:[ [x0,y0], [x1,y1 ], [x2,y2], [x3,y3] ]
The correspondence between the four vertex sequences, the center coordinates, the width, the height, and the rotation angle (in the form of degrees, not the number of radians) of the minimum circumscribed rectangle is as follows:
Note: The rotation angle θ is the angle between the counterclockwise rotation of the horizontal axis (x-axis) and the first edge of the encountered rectangle. And the side length of this side is width, and the other side length is height. That is to say, here, width and height are not defined by length.
In opencv, the coordinate system origin is in the upper left corner, relative to the x-axis, the counterclockwise rotation angle is negative, and the clockwise rotation angle is positive. Here, θ ∈ (-90 degrees, 0).
---------------------
OF: lanyuelvyun
Source: CSDN
Original: https://blog.csdn.net/lanyuelvyun/article/details/76614872
Copyright Notice: This article is the original article of the blogger, please attach the blog post link!
1. Method: Use python opencv to return the minimum bounding rectangle of the point set cnt, the function used is cv2.minAreaRect(cnt), cnt is the point set array or vector (the coordinates of the poin...
opencv finds the angle of the smallest rectangle minAreaRect Recently, I tried the test license plate recognition, and encountered a problem during the process of finding the smallest rectangle. How t...
The minAreaRect() function returns the attention points of the rectangle The minAreaRect() function is mainly used to return the minimum containing rectangle of a certain contour, which can be slanted...
//!computes the minimal rotated rectangle for a set of points RotatedRect MinareArect (InputArray Points); / / Calculate the minimum external rectangle of some list points, with angle information C++:...
There are two types of border rectangleStraight boundary rectangleAnd rotation of border rectangle。 Straight boundary rectangle: A straight rectangular (rectangle is without rotation). Does it not con...
Put the result first The test picture was stolen from:address (2333) In fact, just one line of key code: Here is the simple and rude code~~...
There are two types of bounding rectangles: Straight bounding rectangle Rotated bounding rectangle Straight bounding rectangle Check whether the image contains rectangles, butDoes not consider the rot...
The basic steps for drawing a circumscribing rectangle using cvMinAreaRect2 are: CvBox2D rect=cvMinAreaRect2(contourSeq, storage4maxcontour); CvPoint2D32f rect_pts0[4]; cvBoxPoints(rect, rect_pts0); E...