我可以提供一段示例代码:
import cv2 import numpy as np
读取图片
img = cv2.imread('image.jpg')
定义检测框
detect_box = (100, 100, 200, 200)
获取检测框中的图片
roi = img[detect_box[1]:detect_box[3], detect_box[0]:detect_box[2]]
计算交并比
iou = np.sum(roi) / (np.sum(img) + np.sum(roi) - np.sum(roi))
输出交并比
p