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的Flask站点中集成xhEditor文本编辑器的教程

Python的Flask站点中集成xhEditor文本编辑器的教程

xhEditor简介 xhEditor是一个基于jQuery开发的简单迷你并且高效的可视化HTML编辑器,基于网络访问并且兼容IE 6.0+, Firefox 3.0+, Opera 9...

Python 3.x 新特性及10大变化

Python 3.x 起始版本是Python 3.0,目前的最新版本是 3.3.3 Python之父Guido van Rossum谈到了Python 3.0的构思: 一直以来,除非要打...

Python实现串口通信(pyserial)过程解析

pyserial模块封装了对串口的访问,兼容各种平台。 安装 pip insatll pyserial 初始化 简单初始化示例 import serial ser = se...

Python 使用requests模块发送GET和POST请求的实现代码

①GET # -*- coding:utf-8 -*- import requests def get(url, datas=None): response = reques...

Python实现手机号自动判断男女性别(实例解析)

Python实现手机号自动判断男女性别(实例解析)

本文性别判断主要依靠airtest中的自动化测试实现 通过自动对比支付宝页面男女图像,从而实现男女判断 代码如下: 男女判断函数: // An highlighted block...