目录
json独立文件可视化并转独立txt文件:
# -*- coding: UTF-8 -*-
import glob
import json
import os
import shutil
import numpy as np
import cv2
def iou(box1, box2):
''' box:[x1, y1, x2, y2] '''
in_h = min(box1[3], box2[3]) - max(box1[1], box2[1])
in_w = min(box1[2], box2[2]) - max(box1[0], box2[0])
inner = 0 if in_h <0 or in_w <0 else in_h *in_w
union = (box1[2] - box1[0]) * (box1[3] - box1[1]) + \
(box2[2] - box2[0]) * (box2[3] - box2[1]) - inner
iou = inner / union
return iou
def batch_IoU(bbox, gt):
""" :param bbox: (n, 4)
:param gt: (m, 4)
:return: (n, m)
numpy 广播机制 从后向前对齐。 维度为1 的可以重复等价为任意维度
eg: (4,3,2) (3,2) (3,2)会扩充为(4,3,2)