旋转框的相关函数_lookaroundd的博客-爱代码爱编程
1. cv2.minAreaRect(points)
该函数返回包含points的最小旋转矩形,参数points为需要包含的坐标点,返回值为旋转矩形center_x, center_y, w, h, theta
具体用法:
segmentation = np.array([[10, 20],
[30, 40],
[50, 60],
[70, 80]])
(center_x, center_y), (w, h), theta = cv2.minAreaRect(segmentation)
2. cv2.boxPoints(box)
计算旋转框的四个坐标点,输入矩形框box= ((center_x, center_y), (w, h),theta)
返回值为矩形框的四个顶点坐标
具体用法:
[x1,y1,x2,y2,x3,y3,x4,y4]cv2.boxPoints(((100,100),(50,100),0))
3. cv2.rotatedRectangleIntersection(box1, box2)
计算两个选状框的交点,输入box= ((center_x, center_y), (w, h),theta),
返回值为无序的交点坐标unoedered_intersection_points
4. cv2.convexHull(intersection_points, returnPoints=True)
坐标点排序
ordered_points = cv2.convexHull(intersection_points, returnPoints=True)
5. cv2.contourArea(ordered_points)
计算有序坐标点围成的多边形面积
6. 计算旋转框重叠面积的具体用法
#求交点 intersection_points= cv2.rotatedRectangleIntersection(r1, r2)[1] if int_pts is not None: #交点排序 order_pts = cv2.convexHull(intersection_points, returnPoints=True) #求交点围成的多边形面积 intersection_area = cv2.contourArea(ordered_points)