python-opencv计算重叠矩形面积IOU

import cv2
import numpy as np
def calc_riou(r1,r2):
    r1=np.array(r1)
    r2=np.array(r2)
    rect1 = ((r1[0],r1[1]),(r1[2],r1[3]),r1[4])
    rect2 = ((r2[0],r2[1]),(r2[2],r2[3]),r2[4])
    int_pts = cv2.rotatedRectangleIntersection(rect1, rect2)[1]
    if int_pts is not None:
        order_pts = cv2.convexHull(int_pts, returnPoints=True)
        int_area = cv2.contourArea(order_pts)
    else:
        int_area=0
    return int_area
if __name__ == '__main__':
    bbox1=np.array([100,50,20,10,360],dtype=np.float)
    bbox2=np.array([100,50,20,10,0],dtype=np.float)
    print("riou ",calc_riou(bbox1,bbox2))

计算boundingbox之间的重合面积

最后一个维度是角度(degree)

你可能感兴趣的:(深度视觉目标检测,Python,python,opencv)