IOU计算并可视化

def Cal_IOU(rect1,rect2):
    '''
    rect1=[x00,y00,x01,y01]
    rect2=[x10,y10,x11,y11]
    '''
    max_left_topx=max(rect1[0],rect2[0])
    max_left_topy=max(rect1[1],rect2[1])
    min_right_downx=min(rect1[2],rect1[2])
    min_right_downy=min(rect1[3],rect1[3])
    if max_left_topx>=min_right_downx or max_left_topy>=min_right_downy:
        return 0
    area=(min_right_downx-max_left_topx)*(min_right_downy-max_left_topy)
    S=(rect1[2]-rect1[0])*(rect1[3]-rect1[1])+(rect2[2]-rect2[0])*(rect2[3]-rect2[1])-area
    result= round((area/S),3)
    return [result,max_left_topx,max_left_topy]
import cv2
import numpy as np
numpy=[[0]*256]*256
numpy=np.array(numpy)
print(numpy)
cv2.imwrite("./numpy.jpg",numpy)

# cv2.rectangle()
[[0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 ..., 
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]]





True
numpy=cv2.imread("./numpy.jpg")
rec1=[0,0,100,100]
rect1=cv2.rectangle(numpy,(rec1[0],rec1[1]),(rec1[2],rec1[3]),(0,0,255),1)
cv2.putText(rect1,"S1",(rec1[0]+50,rec1[1]+50),cv2.FONT_HERSHEY_SIMPLEX,0.4,(0,0,255),1)
rec2=[50,50,150,150]
rect2=cv2.rectangle(rect1,(rec2[0],rec2[1]),(rec2[2],rec2[3]),(0,255,0),1)
cv2.putText(rect1,"S2",(rec2[0]+50,rec2[1]+50),cv2.FONT_HERSHEY_SIMPLEX,0.4,(0,255,0),1)
rec3=[60,60,170,170]
rect3=cv2.rectangle(rect2,(rec3[0],rec3[1]),(rec3[2],rec3[3]),(255,0,0),1)
cv2.putText(rect1,"S3",(rec3[0]+50,rec3[1]+50),cv2.FONT_HERSHEY_SIMPLEX,0.4,(255,0,0),1)
result_12=Cal_IOU(rec1,rec2)
cv2.putText(rect3,"IOU_12="+str(result_12[0]),(result_12[1]+30,result_12[2]+30),cv2.FONT_HERSHEY_SIMPLEX,0.4,(0,0,255),1)
result_23=Cal_IOU(rec2,rec3)
cv2.putText(rect3,"IOU_23="+str(result_23[0]),(result_23[1]+30,result_23[2]+30),cv2.FONT_HERSHEY_SIMPLEX,0.4,(0,255,0),1)
result_13=Cal_IOU(rec1,rec3)
cv2.putText(rect3,"IOU_13="+str(result_13[0]),(result_13[1]+70,result_13[2]+70),cv2.FONT_HERSHEY_SIMPLEX,0.4,(255,0,0),1)
# print(result)
cv2.imshow("rect.png",rect3)
cv2.waitKey(0)
cv2.destroyAllWindows()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值