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

yipeiwu_com5年前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 常用string函数(收藏)

字符串中字符大小写的变换 1. str.lower() //小写 >>> 'SkatE'.lower() 'skate' 2. str.upper() //大写 >...

python模拟键盘输入 切换键盘布局过程解析

python模拟键盘输入 切换键盘布局过程解析

PostMessage() def keyHwnd(hwndEx, char): """ 向指定控件输入值 :param hwndEx: 控件句柄 :param c...

12步入门Python中的decorator装饰器使用方法

装饰器(decorator)是一种高级Python语法。装饰器可以对一个函数、方法或者类进行加工。在Python中,我们有多种方法对函数和类进行加工,比如在Python闭包中,我们见到函...

python实现xlsx文件分析详解

python实现xlsx文件分析详解

python脚本实现xlsx文件解析,供大家参考,具体内容如下 环境配置: 1.系统环境:Windows 7 64bit 2.编译环境:Python3.4.3 3.依赖库: os s...

python字符串的方法与操作大全

一:字符串的方法与操作 *注意:首字母为l的为从左边操作,为r的方法为从右边操作 1.__contains__()判断是否包含 判断指定字符或字符串是否包含在一个字符串内,返回值为tru...