定义的box是左上角的x、y以及宽度w、高度h

iou计算出来的交集的w、h必须判断是否大于0,这避免了两个框没有交集的情况。如果不判断,可能存在w、h都为负生成iou>0的情况进而影响结果。

+1操作是计算像素点个数,这个地方其实有点没太理解到,但开源的代码都是这么写的。

#include<iostream>
#include<vector>
#include<algorithm>
#include <stdio.h>
#include <stdlib.h>
using namespace std; typedef struct Bbox{
int x;
int y;
int w;
int h;
float score;
}Bbox; class Solution {
public: static bool sort_score(Bbox box1,Bbox box2){
return box1.score > box2.score ? true : false;
} float iou(Bbox box1,Bbox box2){
int x1 = max(box1.x,box2.x);
int y1 = max(box1.y,box2.y);
int x2 = min(box1.x+box1.w,box2.x+box2.w);
int y2 = min(box1.y+box1.h,box2.y+box2.h);
int w = max(,x2 - x1 + );
int h = max(,y2 - y1 + );
float over_area = w*h;
return over_area/(box1.w * box1.h + box2.w * box2.h - over_area);
} vector<Bbox> nms(std::vector<Bbox>&vec_boxs,float threshold){
vector<Bbox>results;
std::sort(vec_boxs.begin(),vec_boxs.end(),sort_score);
while(vec_boxs.size() > )
{
results.push_back(vec_boxs[]);
int index = ;
while(index < vec_boxs.size()){
float iou_value = iou(vec_boxs[],vec_boxs[index]);
cout << "iou:" << iou_value << endl;
if(iou_value > threshold)
vec_boxs.erase(vec_boxs.begin() + index);
else
index++;
}
vec_boxs.erase(vec_boxs.begin());
}
return results;
}
}; int main(){
Solution a;
vector<Bbox> input; // Bbox box1 = {1,1,1,1,0.3};
// Bbox box2 = {0,0,2,2,0.4};
//Bbox box1 = {1,3,2,2,0.3}; //iou为负
//Bbox box2 = {0,0,2,2,0.4};
//Bbox box1 = {4,4,2,2,0.3};
//Bbox box2 = {0,0,2,2,0.4};
// Bbox box1 = {4,4,1,1,0.3};
// Bbox box2 = {0,0,2,2,0.4};
// Bbox box1 = {3,3,1,1,0.3};
// Bbox box2 = {0,0,2,2,0.4};
input.push_back(box1);
input.push_back(box2);
vector<Bbox> res;
res = a.nms(input,0.3);
// for(int i = 0;i < res.size();i++){
// printf("%d %d %d %d %f",res[i].x,res[i].y,res[i].w,res[i].h,res[i].score);
// cout << endl;
// }
return ;
}

c++版 nms的更多相关文章

  1. YOLACT : 首个实时one-stage实例分割模型,29.8mAP/33.5fps | ICCV 2019

    论文巧妙地基于one-stage目标检测算法提出实时实例分割算法YOLACT,整体的架构设计十分轻量,在速度和效果上面达到很好的trade-off.   来源:[晓飞的算法工程笔记] 公众号 论文: ...

  2. 《zw版·Halcon-delphi系列原创教程》 Halcon分类函数006, image,影像处理(像素图)

    <zw版·Halcon-delphi系列原创教程> Halcon分类函数006, image,影像处理(像素图) 为方便阅读,在不影响说明的前提下,笔者对函数进行了简化: :: 用符号“* ...

  3. 《zw版·Halcon-delphi系列原创教程》 Halcon分类函数004·edge,边缘处理

    <zw版·Halcon-delphi系列原创教程> Halcon分类函数004·edge,边缘处理 为方便阅读,在不影响说明的前提下,笔者对函数进行了简化: :: 用符号“**”,替换:“ ...

  4. 《zw版·delphi与halcon系列原创教程》zw版_THOperatorSetX控件函数列表 v11中文增强版

    <zw版·delphi与halcon系列原创教程>zw版_THOperatorSetX控件函数列表v11中文增强版 Halcon虽然庞大,光HALCONXLib_TLB.pas文件,源码就 ...

  5. 《zw版·delphi与halcon系列原创教程》zw版_THImagex控件函数列表

    <zw版·delphi与halcon系列原创教程>zw版_THImagex控件函数列表 Halcon虽然庞大,光HALCONXLib_TLB.pas文件,源码就要7w多行,但核心控件就是两 ...

  6. zw版_Halcon图像库delphi接口文件

    zw版_Halcon图像库delphi接口文件 Halcon图像库delphi接口文件,根据安装时用户设置的文件目录不同,会有所差异,笔者一般安装在delphi的import目录下.     参见:& ...

  7. 一步步学习操作系统(1)——参照ucos,在STM32上实现一个简单的多任务(“啰里啰嗦版”)

    该篇为“啰里啰嗦版”,另有相应的“精简版”供参考 “不到长城非好汉:不做OS,枉为程序员” OS之于程序员,如同梵蒂冈之于天主教徒,那永远都是块神圣的领土.若今生不能亲历之,实乃憾事! 但是,圣域不是 ...

  8. 非极大值抑制(Non-Maximum Suppression,NMS)

    概述 非极大值抑制(Non-Maximum Suppression,NMS),顾名思义就是抑制不是极大值的元素,可以理解为局部最大搜索.这个局部代表的是一个邻域,邻域有两个参数可变,一是邻域的维数,二 ...

  9. 非极大值抑制(NMS)

    转自:https://www.cnblogs.com/makefile/p/nms.html 概述 非极大值抑制(Non-Maximum Suppression,NMS),顾名思义就是抑制不是极大值的 ...

随机推荐

  1. @Controller和@RestController的区别(转)

    @Controller和@RestController的区别? 官方文档: @RestController is a stereotype annotation that combines @Resp ...

  2. 让iframe可编辑

    function EnableEdit() { var editor; editor = document.getElementById("HtmlEdit").contentWi ...

  3. bae使用nodejs遇到的问题---‘Fix depends failed. Please check requirements.txt.’

    今天尝试了百度开放云里面的nodejs云引擎,部署没有任何问题,修改文件后发现了发布不了,去查看发布设置发现了问题: Fix depends failed. Please check requirem ...

  4. 从敲入 URL 到浏览器渲染完成、对HTTP协议的理解

    1. 大致过程 当你这样子回答的时候: 用户输入 url 地址,浏览器查询 DNS 查找对应的请求 IP 地址 建立 TCP 连接 浏览器向服务器发送 http 请求,如果服务器段返回以 301 之类 ...

  5. PHP CURL库学习

    基本请求步骤 : // . 初始化 $ch = curl_init(); // . 设置选项,包括URL curl_setopt($ch, CURLOPT_URL, "http://www. ...

  6. 使用镶嵌数据集 MosaicDataSet管理不同分辨率影像数据

    镶嵌数据集 MosaicDataSet是Esri推出的一种用于管理海量影像数据的数据模型,它是Geodatabase数据模型的一个子集定义. 该数据模型强大之处在于它能统一管理不同采集时间.不同采集来 ...

  7. PDW V2培训简记

    最近有幸参加了微软专家进行的为期一周PDW培训,将一些知识点记录如下: 不知道PDW是什么东西的,简单介绍一下:这是微软与HP/Dell合作推出的SQL Server数据仓库一体机,由HP或DELL提 ...

  8. 2cmd 窗口 javac 错误:编码GBK的不可映射字符

    错误截图: 解决办法:第一步 第二步:

  9. 线性代数的视角理解LSR(least square regression)的参数评估算法本质

    https://medium.com/@andrew.chamberlain/the-linear-algebra-view-of-least-squares-regression-f67044b7f ...

  10. hdfs基本操作-python接口

    安装hdfs包 pip install hdfs 查看hdfs目录 [root@hadoop hadoop]# hdfs dfs -ls -R / drwxr-xr-x - root supergro ...