首页 > 编程语言 >IOU计算-纯python

IOU计算-纯python

时间:2022-11-08 17:02:11浏览次数:36  
标签:right bottom python IOU 计算 rec2 line rec1 iou

iou计算代码,纯python

from:https://blog.csdn.net/leviopku/article/details/81629492

#!/usr/bin/env python
# encoding: utf-8
 
 
 
def compute_iou(rec1, rec2):
    """
    computing IoU
    :param rec1: (y0, x0, y1, x1), which reflects
            (top, left, bottom, right)
    :param rec2: (y0, x0, y1, x1)
    :return: scala value of IoU
    """
    # computing area of each rectangles
    S_rec1 = (rec1[2] - rec1[0]) * (rec1[3] - rec1[1])
    S_rec2 = (rec2[2] - rec2[0]) * (rec2[3] - rec2[1])
 
    # computing the sum_area
    sum_area = S_rec1 + S_rec2
 
    # find the each edge of intersect rectangle
    left_line = max(rec1[1], rec2[1])
    right_line = min(rec1[3], rec2[3])
    top_line = max(rec1[0], rec2[0])
    bottom_line = min(rec1[2], rec2[2])
 
    # judge if there is an intersect
    if left_line >= right_line or top_line >= bottom_line:
        return 0
    else:
        intersect = (right_line - left_line) * (bottom_line - top_line)
        return (intersect / (sum_area - intersect))*1.0
 
 
if __name__=='__main__':
    rect1 = (661, 27, 679, 47)
    # (top, left, bottom, right)
    rect2 = (662, 27, 682, 47)
    iou = compute_iou(rect1, rect2)
    print(iou)

 

标签:right,bottom,python,IOU,计算,rec2,line,rec1,iou
From: https://www.cnblogs.com/chentiao/p/16870277.html

相关文章

  • Python学习笔记3
    Python学习笔记3       Python中的True和Falsepath=os.path.join('a','b')print(path)#a\bmessages=[]ifmessages==False:  print('[]就是False')m......
  • esp32 micropython引脚电容值实现模拟按键
    frommachineimportTouchPad,Pin#引入touchpad模块fromtimeimportsleepimportutimetouch_up=TouchPad(Pin(12))#12是上touch_down=TouchPad(Pin(13)......
  • Python基础30
    今日内容概要面向对象之魔法方法基于魔法方法的笔试题元类简介创建类的两种方式元类定制类的产生行为元类定制对象的产生行为魔法方法之双下new方法设计模式简介......
  • python 入门 2 数字类型
    在编程时,经常会使用到数字来记录的情况,比如游戏分数、可视化。存储web等。python会根据数字的用法,以不同的方式来处理。1.整数python中的整数  加(+)减(-)乘(*)除(/)运算: ......
  • 重温Python基础——if语句
    哈喽兄弟们,本节咱们来复习一下Python基础入门中的if语句。编程中经常需要检查一系列条件,并据此决定采取什么措施。在python中,if语句能检测你的程序的当前状态,并据此采......
  • 一套用了 70 年的计算机架构 —— 冯·诺依曼架构
    本文已收录到 GitHub·AndroidFamily,有Android进阶知识体系,欢迎Star。技术和职场问题,请关注公众号[彭旭锐]进Android面试交流群。前言大家好,我是小彭。上......
  • 【python】美女在召唤,python批量采集~
    前言嗨喽~大家好呀,这里是魔王呐!  知识点:动态数据抓包requests发送请求json数据解析开发环境:python3.8运行代码pycharm2021.2辅助敲代码......
  • Python AutoCAD 文件
    目录BlogLinks1.连接及库导入2.打开文件3.新建文件4.设定当前4.1.已知文件名设为当前4.2.未知文件名设为当前5.关闭并保存变更5.1.关闭已存在文......
  • python二机制文件解析
    参考连接:https://blog.csdn.net/lovelyaiq/article/details/81988185C语言解析:#include"stdlib.h"#include"stdio.h"typedefunsignedintuint32_t;typedefunsi......
  • python获取程序执行文件路径方法
    python脚本打包成exe文件获取当前路径importosimportsys#确定应用程序是脚本文件还是被冻结的exeifgetattr(sys,'frozen',False):#获取应用程序exe的路径......