def intersection_area_convex(rect1,rect2):
r1 = cv2.rotatedRectangleIntersection(rect1, rect2)
if r1[1] is None:
return 0
order_points=cv2.convexHull(r1[1],returnPoints=True)
area = cv2.contourArea(order_points)
return area
and
for i in range(100):
x1,y1,w1,h1,angle1,x2,y2,w2,h2,angle2=np.random.randint(1,300,10)
result1=intersection_area( ((x1,y1),(w1,h1),angle1),((x2,y2),(w2,h2),angle2) )
result2=intersection_area_convex( ((x1,y1),(w1,h1),angle1),((x2,y2),(w2,h2),angle2) )
print(result1==result2)
def intersection_area(rect1,rect2): r1 = cv2.rotatedRectangleIntersection(rect1, rect2) if r1[1] is None: return 0
order_points=cv2.convexHull(r1[1],returnPoints=True)
def intersection_area_convex(rect1,rect2): r1 = cv2.rotatedRectangleIntersection(rect1, rect2) if r1[1] is None: return 0 order_points=cv2.convexHull(r1[1],returnPoints=True) area = cv2.contourArea(order_points) return area
and
always output true