web-dev-qa-db-ja.com

2つの検出間の交差オーバーオン

私は論文を読んでいた: Ferrari et al。 in "Affinity Measures"セクション。フェラーリらによってアフィニティを取得しようとします:

  1. 場所の親和性-2つの検出間の交差オーバーオンエリアを使用
  2. 外観の親和性-ヒストグラム間のユークリッド距離を使用
  3. KLTポイントアフィニティ測定

ただし、2つの主な問題があります。

  1. 2つの検出の交差交差の実際の意味とその計算方法を理解できない
  2. わずかに異なる外観の親和性の尺度を試しました。 RGB検出をHSVに変換しました。色相と彩度を1つのベクトルに連結し、それを使用して他の検出と比較しました。ただし、バッグの検出は同じ人物の頭の検出(向きが異なる)よりも類似性スコアが高いため、この手法の使用は失敗しました。

上記の私の問題に対する提案や解決策はありますか?ありがとう、あなたの助けは大歓迎です。

19
Sambas23

1)2つのオーバーラップする境界ボックスがあります。ボックスの交差部分を計算します。これはオーバーラップの面積です。オーバーラップするボックスの和を計算します。これは、ボックス全体の面積からオーバーラップの面積を引いたものです。次に、交差点をユニオンで分割します。 bboxOverlapRatio と呼ばれるComputer Vision System Toolboxには、そのための関数があります。

2)通常、カラーチャンネルを連結することは望ましくありません。代わりに必要なのは、寸法がH、S、およびVである3Dヒストグラムです。

25
Dima

ユニオンで交差点を試す

ユニオンの交差点は、特定のデータセットのオブジェクト検出器の精度を測定するために使用される評価指標です。

より正式には、UnionにIntersectionを適用して(任意の)オブジェクト検出器を評価するには、次が必要です。

  1. グラウンドトゥルースバウンディングボックス(つまり、オブジェクトが画像内のどこにあるかを指定するテストセットのバウンディングボックスとラベル付けされた手)。
  2. モデルから予測された境界ボックス。

以下に、地上の境界ボックスと予測された境界ボックスの視覚的な例を示します。

enter image description here

予測されたバウンディングボックスは赤で描画され、グラウンドトゥルース(つまり、手でラベル付けされた)バウンディングボックスは緑で描画されます。

上の図では、オブジェクト検出器が画像内の一時停止標識の存在を検出したことがわかります。

したがって、Union上の交差点の計算は、次の方法で決定できます。

enter image description here

これら2つのバウンディングボックスのセットがある限り、UnionにIntersectionを適用できます。

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 = (xB - xA) * (yB - yA)

    # compute the area of both the prediction and ground-truth
    # rectangles
    boxAArea = (boxA[2] - boxA[0]) * (boxA[3] - boxA[1])
    boxBArea = (boxB[2] - boxB[0]) * (boxB[3] - boxB[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

gtpred

  1. gt:グラウンドトゥルースバウンディングボックス。
  2. pred:モデルから予測された境界ボックス。

詳細については、 this post をクリックしてください。

34
GoingMyWay

現在の回答はすでに質問を明確に説明しています。そこで、ここでPythonという2つのバウンディングボックスが交差しない場合に壊れないIoUの少し良いバージョンを提供します。

import numpy as np

def IoU(box1: np.ndarray, box2: np.ndarray):
    """
    calculate intersection over union cover percent
    :param box1: box1 with shape (N,4) or (N,2,2) or (2,2) or (4,). first shape is preferred
    :param box2: box2 with shape (N,4) or (N,2,2) or (2,2) or (4,). first shape is preferred
    :return: IoU ratio if intersect, else 0
    """
    # first unify all boxes to shape (N,4)
    if box1.shape[-1] == 2 or len(box1.shape) == 1:
        box1 = box1.reshape(1, 4) if len(box1.shape) <= 2 else box1.reshape(box1.shape[0], 4)
    if box2.shape[-1] == 2 or len(box2.shape) == 1:
        box2 = box2.reshape(1, 4) if len(box2.shape) <= 2 else box2.reshape(box2.shape[0], 4)
    point_num = max(box1.shape[0], box2.shape[0])
    b1p1, b1p2, b2p1, b2p2 = box1[:, :2], box1[:, 2:], box2[:, :2], box2[:, 2:]

    # mask that eliminates non-intersecting matrices
    base_mat = np.ones(shape=(point_num,))
    base_mat *= np.all(np.greater(b1p2 - b2p1, 0), axis=1)
    base_mat *= np.all(np.greater(b2p2 - b1p1, 0), axis=1)

    # I area
    intersect_area = np.prod(np.minimum(b2p2, b1p2) - np.maximum(b1p1, b2p1), axis=1)
    # U area
    union_area = np.prod(b1p2 - b1p1, axis=1) + np.prod(b2p2 - b2p1, axis=1) - intersect_area
    # IoU
    intersect_ratio = intersect_area / union_area

    return base_mat * intersect_ratio
0
S. Sean