python - 如何计算两幅图像的交集?
问题描述
我尝试计算两个不同大小的图像的交集(IOU);我从这里找到了这个 python 代码:
def IoU(box1, box2):
"""
Returns the Intersection over Union (IoU) between box1 and box2
Arguments:
box1: coordinates: (x1, y1, x2, y2)
box2: coordinates: (x1, y1, x2, y2)
"""
# Calculate the intersection area of the two boxes.
xi1 = max(box1[0], box2[0])
yi1 = max(box1[1], box2[1])
xi2 = min(box1[2], box2[2])
yi2 = min(box1[3], box2[3])
area_of_intersection = (xi2 - xi1) * (yi2 - yi1)
# Calculate the union area of the two boxes
# A U B = A + B - A ∩ B
A = (box1[2] - box1[0]) * (box1[3] - box1[1])
B = (box2[2] - box2[0]) * (box2[3] - box2[1])
union_area = A + B - area_of_intersection
intersection_over_union = area_of_intersection/ union_area
return intersection_over_union
但问题是我不知道如何分配我想要计算 IOU 的图像的框值?
我将不胜感激;谢谢你。
解决方案
推荐阅读
- python - 如何根据 Pandas 中第一个数据帧中的某些列值从第二个数据帧添加列值
- php - Laravel/ PHP- 404 路由返回不存在的页面
- python - IndexError: list index out of range coursera assignment
- javascript - 如何在不超时的情况下从javascript中的字符串中删除元音?
- c++ - 使用 C++ 和 i2c-tools 从虚拟 i2c 写入和读取
- android - 使用 Oreo 8.1 在 MIUI 中关闭应用程序时,作业计划停止
- javafx - JavaFX 路径:不需要的行
- maven - 从 azure maven 管道中对 azure 工件进行身份验证
- ios - 如何以编程方式在 iOS 中的元素上触发键盘焦点(tab 键)事件?
- laravel-5 - Google Oauth 回调 url 参数有问题