当前位置:   article > 正文

矩形框的IOU计算C++实现_c++ 代码斜率矩形 iou

c++ 代码斜率矩形 iou

可以利用opencv进行实现,非常简单,如果不使用opencv也可以使用min,max也不难。因此下面的C++代码包含了两种计算矩形框IOU的方法。

#include<iostream>
#include<algorithm>
#include<vector>
 
#include<opencv2/opencv.hpp>
 
using namespace std;
 
struct bbox
{
	int m_left;
	int m_top;
	int m_width;
	int m_height;
 
	bbox() {}
	bbox(int left, int top, int width, int height) 
	{
		m_left = left;
		m_top = top;
		m_width = width;
		m_height = height;
	}
};
 
float IOU(const bbox& b1, const bbox& b2)
{
	float w = std::min(b1.m_left + b1.m_width, b2.m_left + b2.m_width)
		      - std::max(b1.m_left, b2.m_left);
	float h = std::min(b1.m_top + b1.m_height, b2.m_top + b2.m_height)
		      - std::max(b1.m_top, b2.m_top);
 
 
	if (w <= 0 || h <= 0)
		return 0;
 
	std::cout << "w :" << w << "h :" << h << std::endl;
 
	return (w * h) / ((b1.m_height * b1.m_width) + (b2.m_heig
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/114102
推荐阅读
相关标签
  

闽ICP备14008679号