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设计】。

相关文章

json跨域调用python的方法详解

本文实例讲述了json跨域调用python的方法。分享给大家供大家参考,具体如下: 客户端: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML...

Python使用turtule画五角星的方法

本文实例讲述了Python使用turtule画五角星的方法。分享给大家供大家参考。具体实现方法如下: #!/usr/bin/env python import turtle impo...

python如何获取当前文件夹下所有文件名详解

前言 本文主要给大家介绍了关于python获取当前文件夹下所有文件名的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧 os 模块下有两个函数: os.walk(...

Python基于Matplotlib库简单绘制折线图的方法示例

Python基于Matplotlib库简单绘制折线图的方法示例

本文实例讲述了Python基于Matplotlib库简单绘制折线图的方法。分享给大家供大家参考,具体如下: Matplotlib画折线图,有一些离散点,想看看这些点的变动趋势: im...

Python中的引用和拷贝浅析

If an object's value can be modified, the object is said to be mutable. If the value cannot b...