【计算机视觉】交并比IOU概念理解

前言

交并比IOU(Intersection over Union)是一种测量在特定数据集中检测相应物体准确度的一个标准。

图示

很简单,IoU相当于两个区域重叠的部分除以两个区域的集合部分得出的结果。

一般来说,这个score > 0.7 就可以被认为一个不错的结果了。

需要注意两个区域的位置,也有可能没有交集。

code

python版本:

复制代码
# import the necessary packages
from collections import namedtuple
import numpy as np
import cv2
# define the `Detection` object
Detection = namedtuple("Detection", ["image_path", "gt", "pred"])
def bb_intersection_over_union(boxA, boxB):
    # determine the (x, y)-coordinates of the intersection rectangle
    xA = max(boxA[0], boxB[0])
    yA = max(boxA[1], boxB[1])
    xB = min(boxA[2], boxB[2])
    yB = min(boxA[3], boxB[3])
    # compute the area of intersection rectangle
    interArea = max(0, xB - xA + 1) * max(0, yB - yA + 1)
    # compute the area of both the prediction and ground-truth
    # rectangles
    boxAArea = (boxA[2] - boxA[0] + 1) * (boxA[3] - boxA[1] + 1)
    boxBArea = (boxB[2] - boxB[0] + 1) * (boxB[3] - boxB[1] + 1)
    # compute the intersection over union by taking the intersection
    # area and dividing it by the sum of prediction + ground-truth
    # areas - the interesection area
    iou = interArea / float(boxAArea + boxBArea - interArea)
    # return the intersection over union value
    return iou
复制代码

c++版本:

复制代码
//compute iou.
float compute_iou(cv::Rect boxA, cv::Rect boxB)
{
   int xA = std::max(boxA.x, boxB.x);
   int yA = std::max(boxA.y, boxB.y);
   int xB = std::min(boxA.x+boxA.width, boxB.x+boxB.width);
   int yB = std::min(boxA.y+boxA.height, boxB.y+boxB.height);

   float inter_area = max(0, xB-xA+1) * max(0, yB-yA+1);
   float boxA_area = boxA.width * boxA.height;
   float boxB_area = boxB.width * boxB.height;

   float iou = inter_area / (boxA_area + boxB_area - inter_area);
   return iou;
}
复制代码

 参考

1.oldpan博客

2.IOU

3. NMS和计算mAP时的置信度阈值和IoU阈值

posted on   鹅要长大  阅读(2948)  评论(0编辑  收藏  举报

编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
历史上的今天:
2017-09-11 Vec3b类型数据确定颜色通道

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示