zoukankan      html  css  js  c++  java
  • 【计算机视觉】交并比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

  • 相关阅读:
    ubuntu 安装 redis desktop manager
    ubuntu 升级内核
    Ubuntu 内核升级,导致无法正常启动
    spring mvc 上传文件,但是接收到文件后发现文件变大,且文件打不开(multipartfile)
    angular5 open modal
    POJ 1426 Find the Multiple(二维DP)
    POJ 3093 Margritas
    POJ 3260 The Fewest Coins
    POJ 1837 Balance(二维DP)
    POJ 1337 A Lazy Worker
  • 原文地址:https://www.cnblogs.com/happyamyhope/p/9629358.html
Copyright © 2011-2022 走看看