Python计算机视觉里的IOU计算实例

yipeiwu_com6年前Python基础

其中x1,y1;x2,y2分别表示两个矩形框的中心点

def calcIOU(x1, y1, w1, h1, x2, y2, w2, h2):
  if((abs(x1 - x2) < ((w1 + w2)/ 2.0)) and (abs(y1-y2) < ((h1 + h2)/2.0))):
    left = max((x1 - (w1 / 2.0)), (x2 - (w2 / 2.0)))
    upper = max((y1 - (h1 / 2.0)), (y2 - (h2 / 2.0)))

    right = min((x1 + (w1 / 2.0)), (x2 + (w2 / 2.0)))
    bottom = min((y1 + (h1 / 2.0)), (y2 + (h2 / 2.0)))

    inter_w = abs(left - right)
    inter_h = abs(upper - bottom)
    inter_square = inter_w * inter_h
    union_square = (w1 * h1)+(w2 * h2)-inter_square

    calcIOU = inter_square/union_square * 1.0
    print("calcIOU:", calcIOU)
  else:
    print("No intersection!")

  return calcIOU
def main():
  calcIOU(1, 2, 2, 2, 2, 1, 2, 2)

if __name__ == '__main__':
  main()

以上这篇Python计算机视觉里的IOU计算实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python实现给scatter设置颜色渐变条colorbar的方法

python实现给scatter设置颜色渐变条colorbar的方法

python设置scatter颜色渐变的方法 参考代码如下: <span style="font-size:18px;">import matplotlib.pyplot...

python实现递归查找某个路径下所有文件中的中文字符

本文实例为大家分享了python实现递归查找某个路径下所有文件中的中文字符,供大家参考,具体内容如下 # -*- coding: utf-8 -*- # @ description:...

python将文本分每两行一组并保存到文件

python将文本分每两行一组并保存到文件

业务需求 需要将文本文件分每两行一组 jb51.txt 1:www.jb51.net 2:www.jb51.net 3:www.jb51.net 4:www.jb51.net 5:ww...

Python解决pip install时出现的Could not fetch URL问题

Python解决pip install时出现的Could not fetch URL问题

前言 使用python直接使用pip install xx时,出现 Could not fetch URL https://pypi.python.org/simple/requests...

Python 一句话生成字母表的方法

List >>> [chr(i) for i in range(97,123)] ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',...