[opencv]Rect集合象限法分类聚合 函数

/**
* 矩形拟合
* @param mats
* @return
*/
vector<Rect> PublicCardFrameDetection::RectContainFit(vector<Rect> rects,Mat src) { //获取图像中心坐标
int src_w = src.cols;
int src_h = src.rows;
Point2i center = (Point2i(src_w/2),Point2i(src_h/2));
Rect rect_center (int(src_w/3),int(src_h/3),int(src_w/3),int(src_h/3));
// rectangle(src,rect_center.tl(),rect_center.br(),cv::Scalar(255,255,255),5,8);
//存放结果Rect区域
vector<Rect> results;
vector<Rect> roi_tl; //左上
vector<Rect> roi_tr; //右上
vector<Rect> roi_bl; //左下
vector<Rect> roi_br; //右下
vector<Rect> roi_center; //中间
int size = rects.size();
for (auto rct : rects){
Point2i tl_pt = rct.tl();
Point2i tr_pt = Point2i(rct.tl().x + src_w,rct.tl().y);
Point2i br_pt = rct.br();
Point2i bl_pt = Point2i(rct.br().x - src_w,rct.br().y);
Point2i center_pt = (tl_pt+br_pt)/2;
//rect是否落在中间3*3的九宫格区域
if ((tl_pt.x < rect_center.tl().x && tl_pt.y < rect_center.tl().y) &&
(br_pt.x < rect_center.br().x && br_pt.y < rect_center.br().y)){
if ((tl_pt.x + rct.width < rect_center.tl().x + rect_center.width) &&
(tl_pt.y + rct.height < rect_center.tl().y + rect_center.height))
roi_center.emplace_back(rct);
} //rect在中心点center左上方
if (center_pt.y < center.y && center_pt.x > center.x){
// if (br_pt.x < center.x && br_pt.y < center.y &&
// bl_pt.x < center.x && bl_pt.y < center.y)
roi_tr.emplace_back(rct);
}
//rect在中心点center右上方
if (center_pt.y < center.y && center_pt.x > center.x){
// if (br_pt.x < center.x && br_pt.y < center.y &&
// bl_pt.x < center.x && bl_pt.y < center.y)
roi_tl.emplace_back(rct);
}
//rect在中心点center左下方
if (center_pt.y > center.y && center_pt.x > center.x){
// if (tl_pt.x > center.x && tl_pt.y > center.y &&
// tr_pt.x < center.x && tr_pt.y < center.y)
roi_br.emplace_back(rct);
}
//rect在中心点左下方
if (center_pt.y > center.y && center_pt.x < center.x){
// if (tl_pt.x > center.x && tl_pt.y > center.y &&
// tr_pt.x < center.x && tr_pt.y < center.y)
roi_bl.emplace_back(rct);
} }//for_end //若rect落在正中间,说明识别单卡片,直接返回results结果
// if (!roi_center.empty()){
// rectangle(src,roi_center[0].tl(),roi_center[0].br(),cv::Scalar(0,0,255),5,8);
// results.emplace_back(roi_center[0]);
// imshow("rectangle",src);
// waitKey(0);
// return results;
// } else {
//否则,说明识别多卡片,对卡片进行排序
//顺序为:逆时针==>左上,左下,右下,左上
//若四个方向的集合为空,存入原图分割后的四个象限
if (roi_tl.empty()) {
Rect tl(0,0,src_w/2,src_h/2);
roi_tl.emplace_back(tl);
}
if (roi_bl.empty()) {
Rect bl(0,src_h/2,src_w/2,src_h/2);
roi_bl.emplace_back(bl);
}
if (roi_br.empty()) {
Rect br(src_w/2,src_h/2,src_w/2,src_h/2);
roi_br.emplace_back(br);
}
if (roi_tr.empty()) {
Rect tr(src_w/2,0,src_w/2,src_h/2);
roi_tr.emplace_back(tr);
}
//Scalr(BGR)
rectangle(src,roi_tl[0].tl(),roi_tl[0].br(),cv::Scalar(0,0,255),5,8);
rectangle(src,roi_bl[0].tl(),roi_bl[0].br(),cv::Scalar(255,0,0),5,8);
rectangle(src,roi_br[0].tl(),roi_br[0].br(),cv::Scalar(0,255,0),5,8);
rectangle(src,roi_tr[0].tl(),roi_tr[0].br(),cv::Scalar(255,0,255),5,8);
imshow("rectangle",src);
waitKey(0);
results.emplace_back(roi_tl[0]);
results.emplace_back(roi_bl[0]);
results.emplace_back(roi_br[0]);
results.emplace_back(roi_tr[0]);
// }
return results;
}
[opencv]Rect集合象限法分类聚合 函数的更多相关文章
- SQL Server温故系列(4):SQL 查询之集合运算 & 聚合函数
1.集合运算 1.1.并集运算 UNION 1.2.差集运算 EXCEPT 1.3.交集运算 INTERSECT 1.4.集合运算小结 2.聚合函数 2.1.求行数函数 COUNT 2.2.求和函数 ...
- 集合运算 & 聚合函数
SQL 查询之集合运算 & 聚合函数 1.集合运算 1.1.并集运算 UNION 1.2.差集运算 EXCEPT 1.3.交集运算 INTERSECT 1.4.集合运算小结 2.聚合函数 ...
- SQL Server数据库--》top关键字,order by排序,distinct去除重复记录,sql聚合函数,模糊查询,通配符,空值处理。。。。
top关键字:写在select后面 字段的前面 比如你要显示查询的前5条记录,如下所示: select top 5 * from Student 一般情况下,top是和order by连用的 orde ...
- Django 数据聚合函数 annotate
统计各个分类下的文章数 2 周,3 日前 字数 3818 阅读 546 评论 21 在我们的博客侧边栏有分类列表,显示博客已有的全部文章分类.现在想在分类名后显示该分类下有多少篇文章,该怎么做呢?最优 ...
- Django之数据聚合函数 annotate
在我们的博客侧边栏有分类列表,显示博客已有的全部文章分类.现在想在分类名后显示该分类下有多少篇文章,该怎么做呢?最优雅的方式就是使用 Django 模型管理器的annotate方法. 模型回顾 回顾一 ...
- Day03:集合、文件处理和函数基础
上节课复习: 1.总结 可变/不可变: 可变类型:list,dict 不可变类型:int,float,str,tuple ...
- Mongodb学习笔记四(Mongodb聚合函数)
第四章 Mongodb聚合函数 插入 测试数据 ;j<;j++){ for(var i=1;i<3;i++){ var person={ Name:"jack"+i, ...
- 数据查询语言DQL 与 内置函数(聚合函数)
数据查询语言DQL 从表中获取符合条件的数据 select select*from表的名字 查询表所有的数据.(select跟from必须一块用 成对出现的) * 表示所有字段,可以换成想要查询的 ...
- SQL语句汇总(三)——聚合函数、分组、子查询及组合查询
聚合函数: SQL中提供的聚合函数可以用来统计.求和.求最值等等. 分类: –COUNT:统计行数量 –SUM:获取单个列的合计值 –AVG:计算某个列的平均值 –MAX:计算列的最大值 –MIN:计 ...
随机推荐
- 关于C语言中不同类型数据进行计算 有符号和无符号数进行计算
float是8个有效位, 做个试验: 输出如下: 上面说明了什么: 1, 18/2.2 是除不尽的, 因为是define,所以没有给ratio变量赋值类型,但是从sizeof输出的结果是8,所以系统默 ...
- 【分布式】Zookeeper伪集群安装部署
zookeeper:伪集群安装部署 只有一台linux主机,但却想要模拟搭建一套zookeeper集群的环境.可以使用伪集群模式来搭建.伪集群模式本质上就是在一个linux操作系统里面启动多个zook ...
- Spring.DM web开发环境搭建
作为一个初学者来说,搭建好Spring.DM 的web开发环境还是有些麻烦的.我就遇到了N多麻烦,走了很多弯路.本文介绍了2种比较简单的搭建Spring.DM OSGi web开发环境的搭建. 第 ...
- ArrayList删除特定元素的方法
最朴实的方法,使用下标的方式: ArrayList<String> al = new ArrayList<String>(); al.add("a"); a ...
- c3p0的使用步骤
//1.导入c3p0的连个包,和mysql的驱动包//2.配置c3p0.xml的配置文件 <c3p0-config> <!-- 使用默认的配置读取连接池对象 --> <d ...
- 5.Vue.js-模板语法
Vue.js 使用了基于 HTML 的模版语法,允许开发者声明式地将 DOM 绑定至底层 Vue 实例的数据. Vue.js 的核心是一个允许你采用简洁的模板语法来声明式的将数据渲染进 DOM 的系统 ...
- 【MySQL】亲测可用的教程筛选:安装与卸载
windows版本的 安装看这篇,非常详细:https://www.cnblogs.com/winton-nfs/p/11524007.html 彻底清除:https://www.pianshen.c ...
- python基础 (三)
成员运算 判断某个个体在不在某个群体里,关键词:in(在),not in(不在)例如: 特殊的,如果是字典中,因为字典的V值是隐藏的,能查看的只有V,所以无法判断V值,只能判断K值. 身份运算 用于判 ...
- Python 字典是如何解决哈希冲突的
本文主要翻译自 so 上面的问题 Why can a Python dict have multiple keys with the same hash? 下 Praveen Gollakota 的答 ...
- 【论文笔记】Recommendations as Treatments: Debiasing Learning and Evaluation
Recommendations as Treatments: Debiasing Learning and Evaluation Authors: Tobias Schnabel, Adith Swa ...