Stitching模块中leaveBiggestComponent初步研究


std::vector<int> leaveBiggestComponent(std::vector<ImageFeatures> &features, std::vector<MatchesInfo> &pairwise_matches,float conf_threshold)
{
const int num_images = static_cast<int>(features.size());
DisjointSets comps(num_images);
for (int i = 0; i < num_images; ++i)
{
for (int j = 0; j < num_images; ++j)
{
if (pairwise_matches[i*num_images + j].confidence < conf_threshold)
continue;
int comp1 = comps.findSetByElem(i);
int comp2 = comps.findSetByElem(j);
if (comp1 != comp2)
comps.mergeSets(comp1, comp2);
}
}
int max_comp = static_cast<int>(std::max_element(comps.size.begin(),comps.size.end()) - comps.size.begin());
std::vector<int> indices;
std::vector<int> indices_removed;
for (int i = 0; i < num_images; ++i)
if (comps.findSetByElem(i) == max_comp)
indices.push_back(i);
else
indices_removed.push_back(i);
std::vector<ImageFeatures> features_subset;
std::vector<MatchesInfo> pairwise_matches_subset;
for (size_t i = 0; i < indices.size(); ++i)
{
features_subset.push_back(features[indices[i]]);
for (size_t j = 0; j < indices.size(); ++j)
{
pairwise_matches_subset.push_back(pairwise_matches[indices[i]*num_images + indices[j]]);
pairwise_matches_subset.back().src_img_idx = static_cast<int>(i);
pairwise_matches_subset.back().dst_img_idx = static_cast<int>(j);
}
}
if (static_cast<int>(features_subset.size()) == num_images)
return indices;
LOG("Removed some images, because can't match them or there are too similar images: (");
LOG(indices_removed[0] + 1);
for (size_t i = 1; i < indices_removed.size(); ++i)
LOG(", " << indices_removed[i]+1);
LOGLN(").");
LOGLN("Try to decrease the match confidence threshold and/or check if you're stitching duplicates.");
features = features_subset;
pairwise_matches = pairwise_matches_subset;
return indices;
}
#include "stdafx.h"
#include "opencv2/opencv_modules.hpp"
#include <opencv2/core/utility.hpp>
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/stitching/detail/autocalib.hpp"
#include "opencv2/stitching/detail/blenders.hpp"
#include "opencv2/stitching/detail/timelapsers.hpp"
#include "opencv2/stitching/detail/camera.hpp"
#include "opencv2/stitching/detail/exposure_compensate.hpp"
#include "opencv2/stitching/detail/matchers.hpp"
#include "opencv2/stitching/detail/motion_estimators.hpp"
#include "opencv2/stitching/detail/seam_finders.hpp"
#include "opencv2/stitching/detail/warpers.hpp"
#include "opencv2/stitching/warpers.hpp"
#define conf_threshold 90
#define num_images 10
using namespace std;
using namespace cv;
using namespace cv::detail;
void main()
{
int max_comp = 0;
int max_size = 0;
vector<int> confident(num_images*num_images);
DisjointSets comps(num_images);
//使用随机数模拟多幅图像中每个图像相互匹配的置信度(0-100)
//另外1与2的匹配置信度和2与1的置信度我们默认相同(实际中是不相同的)
srand((unsigned)time(NULL));
for (int i = 0;i<num_images;i++)
{
cout<<endl;
for (int j = 0;j<num_images;j++)
{
if (!confident[i*num_images+j])
{
confident[i*num_images+j] = rand()%100;
confident[j*num_images+i] = confident[i*num_images+j];
}
if (i == j)
{
confident[i*num_images+j] = 100;
}
cout<<" "<<confident[i*num_images+j];
}
}
//根据两幅图匹配置信度是否大于conf_threshold来决定是否属于一个全景集合
for (int i = 0; i < num_images; ++i)
{
for (int j = 0; j < num_images; ++j)
{
if (confident[i*num_images + j] < conf_threshold)
continue;
int comp1 = comps.findSetByElem(i);
int comp2 = comps.findSetByElem(j);
if (comp1 != comp2)
comps.mergeSets(comp1, comp2);
}
}
//找出包含图片最多的全景集合
for (int i = 0;i< num_images;i++)
{
if (i == 0)
{
max_comp = 0;
max_size = comps.size[i];
}
else if(comps.size[i]>max_size)
{
max_comp = i;
max_size = comps.size[i];
}
}
//将该集合中的元素打印出来
cout<<endl<<"images in the max_comp:"<<endl;
int j = 0;
for (int i = 0;i<num_images;i++)
{
if (comps.findSetByElem(i) == max_comp)
{
cout<<++j<<": "<< i<<endl;
}
}
while(1);
}
解析:

Stitching模块中leaveBiggestComponent初步研究的更多相关文章
- Stitching模块中focalsFromHomography初步研究
在Stitching模块中,通过“光束法平差”的时候,有一个步骤为“通过单应矩阵估算摄像头焦距”,调用的地方为: , )); ] ]; d2 ] ]) ] ]); v1 ] ] ...
- Stitching模块中对特征提取的封装解析(以ORB特性为例)
titching模块中对特征提取的封装解析(以ORB特性为例) OpenCV中Stitching模块(图像拼接模块)的拼接过程可以用PipeLine来进行描述,是一个比较复杂的过程.在这个过程 ...
- opencv笔记--stitching模块
opencv 提供了全景图像拼接的所有实现,包括: 1)stitching 模块提供了图像拼接过程中所需要的基本元素,该模块主要依赖于 features2d 模块: 2)提供了 stitching_d ...
- iOS多线程的初步研究(六)
iOS多线程的初步研究(六) iOS平台提供更高级的并发(异步)调用接口,让你可以集中精力去设计需完成的任务代码,避免去写与程序逻辑无关的线程生成.运行等管理代码.当然实质上是这些接口隐含生成线程和管 ...
- iOS多线程的初步研究3
iOS多线程的初步研究(三) 弄清楚NSRunLoop确实需要花时间,这个类的概念和模式似乎是Apple的平台独有(iOS+MacOSX),很难彻底搞懂(iOS没开源,呜呜). 官网的解释是说run ...
- iOS多线程的初步研究1
iOS多线程的初步研究(一) 对于多线程的开发,iOS系统提供了多种不同的接口,先谈谈iOS多线程最基础方面的使用.产生线程的方式姑且分两类,一类是显式调用,另一类是隐式调用. 一.显示调用的类为NS ...
- iOS多线程的初步研究
iOS多线程的初步研究(四) 理解run loop后,才能彻底理解NSTimer的实现原理,也就是说NSTimer实际上依赖run loop实现的. 先看看NSTimer的两个常用方法: + (NST ...
- Nginx基础知识之————RTMP模块中的中HLS专题(翻译文档)
一.在Nginx配置文件的RTMP模块中配置hls hls_key_path /tmp/hlskeys; 提示错误信息: nginx: [emerg] the same path name " ...
- 一个Angular模块中可以声明哪些组件?
一个Angular模块中可以声明哪些组件? (1) controller 控制器 (2) directive 指令 (3) function ...
随机推荐
- Swift/Objective-C-Swift与Objective-C混用教程
简介:我想很多iOS开发者在知道Swift后,心中最大的问题就是如何将Swift应用到原有项目之中.下面我将简要介绍这2种语言的混用方法,内容参考自官方文档 Using Swift with Coco ...
- linux的setup命令设置网卡和防火墙等
以前在centos上配置网卡都是纯命令行,今天发现linux原来还有一个setup那么好用的命令,真是相见恨晚,以后防火墙.网卡.其他网络配置.系统配置(开机启动项)都可用他来完成了
- C++虚继承的概念[转]
C++中虚拟继承的概念 为了解决从不同途径继承来的同名的数据成员在内存中有不同的拷贝造成数据不一致问题,将共同基类设置为虚基类.这时从不同的路径继承过来的同名数据成员在内存中就只有一个拷贝,同一个函数 ...
- JS-在线运行代码小工具
原理:window.open()方法,open一个新的空白页,然后把文本框中粘贴的代码通过DOM操作,写到新的代码页中, 再利用document.write的功能(写进去之前把其他的全部删掉,并且写进 ...
- ubuntu14.04 LTS Visual Studio Code 编辑器推荐
除了ubuntu geany (茶壶图标) 这个一直爱好的编辑器,发现一个新的编辑器“Visual Studio Code”,也是很好用,记录下 https://code.visualstudio.c ...
- Tomcat远程任意代码执行漏洞及其POC(CVE-2017-12617)
一.原理分析: 只需参数readonly设置为false或者使用参数readonly设置启用WebDAV servlet false,则Tomcat可以不经任何身份验证的控制直接接收PUT方式上传的文 ...
- 纯HTML自动刷新页面或重定向(http-equiv属性的refresh)
refresh 属性值 -- 刷新与跳转(重定向)页面 refresh出现在http-equiv属性中,使用content属性表示刷新或跳转的开始时间与跳转的网址 refresh示例一:5秒之后刷 ...
- gradle多项目构建及依赖
上项目结构图: idea里面一个project其实相当于eclipse的一个workspace,这样一来就很好理解了,我们新建了两个module,相当于eclipse的两个项目工程 主要看配置:bui ...
- 扫描二维码的实现(barcode) ---- HTML5+
模块:barcode Barcode模块管理条码扫描,提供常见的条码(二维码及一维码)的扫描识别功能,可调用设备的摄像头对条码图片扫描进行数据输入.通过plus.barcode可获取条码码管理对象. ...
- Eclipse Tomcat插件的使用
目录 Eclipse Tomcat插件的使用 Eclipse Tomcat插件的使用 我使用的Eclipse版本是:4.6.3 Eclipse已经自带Tomcat插件,不需要再自己进行安装 1.新建T ...