GOICE项目初探
GOICE项目初探
//使用变量
Ptr<FeaturesFinder> finder;
Mat full_img, img;
int num_images = m_ImageList.size();
vector<ImageFeatures> features(num_images);
vector<Mat> images(num_images);
vector<cv::Size> full_img_sizes(num_images);
double seam_work_aspect = ;
vector<MatchesInfo> pairwise_matches;
BestOf2NearestMatcher matcher(try_gpu, match_conf);
vector<int> indices;
vector<Mat> img_subset;
vector<cv::Size> full_img_sizes_subset;
HomographyBasedEstimator estimator;
vector<CameraParams> cameras;
vector<cv::Point> corners(num_images);
vector<Mat> masks_warped(num_images);
vector<Mat> images_warped(num_images);
vector<cv::Size> sizes(num_images);
vector<Mat> masks(num_images);
Mat img_warped, img_warped_s;
Mat dilated_mask, seam_mask, mask, mask_warped;
Ptr<Blender> blender;
double compose_work_aspect = ; //拼接开始
if (features_type == "surf")
finder = new SurfFeaturesFinder();
else
finder = new OrbFeaturesFinder(); //寻找特征点
m_progress.SetPos();
for (int i = ; i < num_images; ++i)
{ full_img = m_ImageList[i].clone();
full_img_sizes[i] = full_img.size();//读到的是大小
if (full_img.empty())
{
MessageBox("图片读取错误,请确认后重新尝试!");
return;
}
if (work_megapix < )
{
img = full_img;
work_scale = ;
is_work_scale_set = true;
}else{
if (!is_work_scale_set)
{
work_scale = min(1.0, sqrt(work_megapix * 1e6 / full_img.size().area()));
is_work_scale_set = true;
}
resize(full_img, img, cv::Size(), work_scale, work_scale);
}
if (!is_seam_scale_set)
{
seam_scale = min(1.0, sqrt(seam_megapix * 1e6 / full_img.size().area()));
seam_work_aspect = seam_scale / work_scale;
is_seam_scale_set = true;
}
(*finder)(img, features[i]);
features[i].img_idx = i;
resize(full_img, img, cv::Size(), seam_scale, seam_scale);
images[i] = img.clone();
} finder->collectGarbage();
full_img.release();
img.release();
//进行匹配
m_progress.SetPos();
matcher(features, pairwise_matches);
matcher.collectGarbage();
indices = leaveBiggestComponent(features, pairwise_matches, conf_thresh);
for (size_t i = ; i < indices.size(); ++i)
{
img_subset.push_back(images[indices[i]]);
full_img_sizes_subset.push_back(full_img_sizes[indices[i]]);
}
m_progress.SetPos();
images = img_subset; //判断图片是否足够
num_images = static_cast<int>(img_subset.size());
if (num_images < )
{
MessageBox("图片特征太少,尝试添加更多图片!");
return;
}
estimator(features, pairwise_matches, cameras);
for (size_t i = ; i < cameras.size(); ++i)
{
Mat R;
cameras[i].R.convertTo(R, CV_32F);
cameras[i].R = R;
//LOGLN("Initial intrinsics #" << indices[i]+1 << ":\n" << cameras[i].K());
}
//开始对准
m_progress.SetPos();
Ptr<detail::BundleAdjusterBase> adjuster;
if (ba_cost_func == "reproj") adjuster = new detail::BundleAdjusterReproj();
else
adjuster = new detail::BundleAdjusterRay(); adjuster->setConfThresh(conf_thresh);
Mat_<uchar> refine_mask = Mat::zeros(, , CV_8U);
if (ba_refine_mask[] == 'x') refine_mask(,) = ;
if (ba_refine_mask[] == 'x') refine_mask(,) = ;
if (ba_refine_mask[] == 'x') refine_mask(,) = ;
if (ba_refine_mask[] == 'x') refine_mask(,) = ;
if (ba_refine_mask[] == 'x') refine_mask(,) = ;
adjuster->setRefinementMask(refine_mask);
(*adjuster)(features, pairwise_matches, cameras); // Find median focal length
vector<double> focals;
for (size_t i = ; i < cameras.size(); ++i)
focals.push_back(cameras[i].focal);
sort(focals.begin(), focals.end());
float warped_image_scale;
if (focals.size() % == )
warped_image_scale = static_cast<float>(focals[focals.size() / ]);
else
warped_image_scale = static_cast<float>(focals[focals.size() / - ] + focals[focals.size() / ]) * 0.5f;
//开始融合
m_progress.SetPos();
if (do_wave_correct)
{
vector<Mat> rmats;
for (size_t i = ; i < cameras.size(); ++i)
rmats.push_back(cameras[i].R);
waveCorrect(rmats, wave_correct);
for (size_t i = ; i < cameras.size(); ++i)
cameras[i].R = rmats[i];
} //最后修正
m_progress.SetPos();
// Preapre images masks
for (int i = ; i < num_images; ++i)
{
masks[i].create(images[i].size(), CV_8U);
masks[i].setTo(Scalar::all());
}
Ptr<WarperCreator> warper_creator;
{
if (warp_type == "plane") warper_creator = new cv::PlaneWarper();
else if (warp_type == "cylindrical") warper_creator = new cv::CylindricalWarper();
else if (warp_type == "spherical") warper_creator = new cv::SphericalWarper();
else if (warp_type == "fisheye") warper_creator = new cv::FisheyeWarper();
else if (warp_type == "stereographic") warper_creator = new cv::StereographicWarper();
else if (warp_type == "compressedPlaneA2B1") warper_creator = new cv::CompressedRectilinearWarper(, );
else if (warp_type == "compressedPlaneA1.5B1") warper_creator = new cv::CompressedRectilinearWarper(1.5, );
else if (warp_type == "compressedPlanePortraitA2B1") warper_creator = new cv::CompressedRectilinearPortraitWarper(, );
else if (warp_type == "compressedPlanePortraitA1.5B1") warper_creator = new cv::CompressedRectilinearPortraitWarper(1.5, );
else if (warp_type == "paniniA2B1") warper_creator = new cv::PaniniWarper(, );
else if (warp_type == "paniniA1.5B1") warper_creator = new cv::PaniniWarper(1.5, );
else if (warp_type == "paniniPortraitA2B1") warper_creator = new cv::PaniniPortraitWarper(, );
else if (warp_type == "paniniPortraitA1.5B1") warper_creator = new cv::PaniniPortraitWarper(1.5, );
else if (warp_type == "mercator") warper_creator = new cv::MercatorWarper();
else if (warp_type == "transverseMercator") warper_creator = new cv::TransverseMercatorWarper();
}
if (warper_creator.empty())
{
cout << "Can't create the following warper '" << warp_type << "'\n";
return;} Ptr<RotationWarper> warper = warper_creator->create(static_cast<float>(warped_image_scale * seam_work_aspect)); for (int i = ; i < num_images; ++i)
{
Mat_<float> K;
cameras[i].K().convertTo(K, CV_32F);
float swa = (float)seam_work_aspect;
K(,) *= swa; K(,) *= swa;
K(,) *= swa; K(,) *= swa; corners[i] = warper->warp(images[i], K, cameras[i].R, INTER_LINEAR, BORDER_REFLECT, images_warped[i]);
sizes[i] = images_warped[i].size(); warper->warp(masks[i], K, cameras[i].R, INTER_NEAREST, BORDER_CONSTANT, masks_warped[i]);
}
vector<Mat> images_warped_f(num_images);
for (int i = ; i < num_images; ++i)
images_warped[i].convertTo(images_warped_f[i], CV_32F);
Ptr<ExposureCompensator> compensator = ExposureCompensator::createDefault(expos_comp_type);
compensator->feed(corners, images_warped, masks_warped);
//接缝修正
m_progress.SetPos();
Ptr<SeamFinder> seam_finder;
if (seam_find_type == "no")
seam_finder = new detail::NoSeamFinder();
else if (seam_find_type == "voronoi")
seam_finder = new detail::VoronoiSeamFinder();
else if (seam_find_type == "gc_color")
seam_finder = new detail::GraphCutSeamFinder(GraphCutSeamFinderBase::COST_COLOR);
else if (seam_find_type == "gc_colorgrad")
seam_finder = new detail::GraphCutSeamFinder(GraphCutSeamFinderBase::COST_COLOR_GRAD);
else if (seam_find_type == "dp_color")
seam_finder = new detail::DpSeamFinder(DpSeamFinder::COLOR);
else if (seam_find_type == "dp_colorgrad")
seam_finder = new detail::DpSeamFinder(DpSeamFinder::COLOR_GRAD);
if (seam_finder.empty())
{
MessageBox("无法对图像进行缝隙融合");
return;
}
//输出最后结果
m_progress.SetPos();
seam_finder->find(images_warped_f, corners, masks_warped);
// Release unused memory
images.clear();
images_warped.clear();
images_warped_f.clear();
masks.clear(); for (int img_idx = ; img_idx < num_images; ++img_idx)
{
// Read image and resize it if necessary
full_img = m_ImageList[img_idx];
if (!is_compose_scale_set)
{
if (compose_megapix > )
compose_scale = min(1.0, sqrt(compose_megapix * 1e6 / full_img.size().area()));
is_compose_scale_set = true;
// Compute relative scales
compose_work_aspect = compose_scale / work_scale;
// Update warped image scale
warped_image_scale *= static_cast<float>(compose_work_aspect);
warper = warper_creator->create(warped_image_scale);
// Update corners and sizes
for (int i = ; i < num_images; ++i)
{
// Update intrinsics
cameras[i].focal *= compose_work_aspect;
cameras[i].ppx *= compose_work_aspect;
cameras[i].ppy *= compose_work_aspect; // Update corner and size
cv::Size sz = full_img_sizes[i];
if (std::abs(compose_scale - ) > 1e-)
{
sz.width = cvRound(full_img_sizes[i].width * compose_scale);
sz.height = cvRound(full_img_sizes[i].height * compose_scale);
}
Mat K;
cameras[i].K().convertTo(K, CV_32F);
cv::Rect roi = warper->warpRoi(sz, K, cameras[i].R);
corners[i] = roi.tl();
sizes[i] = roi.size();
}
}
if (abs(compose_scale - ) > 1e-)
resize(full_img, img, cv::Size(), compose_scale, compose_scale);
else
img = full_img;
full_img.release();
cv::Size img_size = img.size(); Mat K;
cameras[img_idx].K().convertTo(K, CV_32F); // Warp the current image
warper->warp(img, K, cameras[img_idx].R, INTER_LINEAR, BORDER_REFLECT, img_warped); // Warp the current image mask
mask.create(img_size, CV_8U);
mask.setTo(Scalar::all());
warper->warp(mask, K, cameras[img_idx].R, INTER_NEAREST, BORDER_CONSTANT, mask_warped); // Compensate exposure
compensator->apply(img_idx, corners[img_idx], img_warped, mask_warped); img_warped.convertTo(img_warped_s, CV_16S);
img_warped.release();
img.release();
mask.release(); dilate(masks_warped[img_idx], dilated_mask, Mat());
resize(dilated_mask, seam_mask, mask_warped.size());
mask_warped = seam_mask & mask_warped; if (blender.empty())
{
blender = Blender::createDefault(blend_type, try_gpu);
cv::Size dst_sz = resultRoi(corners, sizes).size();
float blend_width = sqrt(static_cast<float>(dst_sz.area())) * blend_strength / .f;
if (blend_width < .f)
blender = Blender::createDefault(Blender::NO, try_gpu);
else if (blend_type == Blender::MULTI_BAND)
{
MultiBandBlender* mb = dynamic_cast<MultiBandBlender*>(static_cast<Blender*>(blender));
mb->setNumBands(static_cast<int>(ceil(log(blend_width)/log(.)) - .));
LOGLN("Multi-band blender, number of bands: " << mb->numBands());
}
else if (blend_type == Blender::FEATHER)
{
FeatherBlender* fb = dynamic_cast<FeatherBlender*>(static_cast<Blender*>(blender));
fb->setSharpness(.f/blend_width);
LOGLN("Feather blender, sharpness: " << fb->sharpness());
}
blender->prepare(corners, sizes);
} // Blend the current image
blender->feed(img_warped_s, mask_warped, corners[img_idx]);
}
Mat result, result_mask;
blender->blend(result, result_mask);
m_progress.SetPos();
AfxMessageBox("拼接成功!");
m_progress.ShowWindow(false);
m_progress.SetPos();
//格式转换
result.convertTo(result,CV_8UC3);
showImage(result,IDC_PBDST);
//保存结果
m_matResult = result.clone();
void CMFCApplication1View::OnButtonOpenmov()
{
CString pathName;
CString szFilters= _T("*(*.*)|*.*|avi(*.avi)|*.avi|mp4(*.mp4)|*.mp4||");
CFileDialog dlg(TRUE,NULL,NULL,NULL,szFilters,this);
VideoCapture capture;
Mat frame;
int iFrameCount = ;
int iFram = ;
if(dlg.DoModal()==IDOK){
//获得路径
pathName=dlg.GetPathName();
//设置窗体
m_ListThumbnail.ShowWindow(false);
m_imagerect.ShowWindow(false);
m_imagedst.ShowWindow(true);
m_progress.ShowWindow(false);
m_msg.ShowWindow(false);
//打开视频并且抽取图片
capture.open((string)pathName);
if (!capture.isOpened())
{
MessageBox("视频打开错误!");
return;
}
m_VectorMovImageNames.clear();
m_MovImageList.clear();
char cbuf[];
while (capture.read(frame))
{
//每隔50帧取一图
if ( == iFram%)
{
m_MovImageList.push_back(frame.clone());
}
showImage(frame,IDC_PBDST);
iFram = iFram +;
}
}
}
GOICE项目初探的更多相关文章
- 《ASP.NET MVC 5 破境之道》:第一境 ASP.Net MVC5项目初探 — 第三节:View层简单改造
第一境 ASP.Net MVC5项目初探 — 第三节:View层简单改造 MVC默认模板的视觉设计从MVC1到MVC3都没有改变,比较陈旧了:在MVC4中做了升级,好看些,在不同的分辨率下,也能工作得 ...
- 《ASP.NET MVC 5 破境之道》:第一境 ASP.Net MVC5项目初探 — 第二节:MVC5项目结构
第一境 ASP.Net MVC5项目初探 — 第二节:MVC5项目结构 接下来,我们来看看,VS为我们自动创建的项目,是什么样子的? 可以通过菜单中[View]->[Solution Explo ...
- 《ASP.NET MVC 5 破境之道》:第一境 ASP.Net MVC5项目初探 — 第一节:运行第一个MVC5项目
第一境 ASP.Net MVC5项目初探 — 第一节:运行第一个MVC5项目 创建一个MVC项目,是很容易的,大部分工作,VS都帮我们完成了.只需要按照如下步骤按部就班就可以了. 打开VS2017,选 ...
- 【Magenta 项目初探】手把手教你用Tensorflow神经网络创造音乐
原文链接:http://www.cnblogs.com/learn-to-rock/p/5677458.html 偶然在网上看到了一个让我很感兴趣的项目 Magenta,用Tensorflow让神经网 ...
- django项目初探
一:创建django项目 设置数据库(默认sqlit3) mysql: setting:中设置 DATABASES = { 'default': { 'ENGINE': 'django.db.back ...
- ewasm项目初探
为了改进EVM1.0,以太坊的新一代虚拟机项目ewasm (github.com/ewasm)将支持WebAssembly(wasm),wasm在性能,扩展性,开发工具,社区都更有优势.除以太坊外,一 ...
- 云原生项目实践DevOps(GitOps)+K8S+BPF+SRE,从0到1使用Golang开发生产级麻将游戏服务器—第1篇
项目初探 项目地址: 原项目:https://github.com/lonng/nanoserver 调过的:https://github.com/Kirk-Wang/nanoserver 这将是一个 ...
- 第01讲 Android开发系列---Activity
一. Android系统版本及详细信息 最新数据 https://developer.android.com/about/dashboards/ 二. Android项目初探 1. 使用a ...
- 壹佰文章最全总结| 《关于ASP.NETCore的分享之路》
学习路线图 (关于学习ASP.NET Core需要了解和掌握的知识点图) 一言不合就来图,各位博客园小伙伴大家好,感觉好久没有写文章了,自从春节开始,中间经历种种,慢慢的就开始微信公众号发文了,原因有 ...
随机推荐
- 新版mysql(mysql-5.7.12-winx64)安装
之前安装了一个php集成运行环境的mysql,不太习惯,还是想弄一个原生的环境来进行学习.于是,卸载了php集成环境中的mysql. 计算机环境:win7 x64. 1.mysql-5.7.12-wi ...
- Leetcode: Palindrome Pairs
Given a list of unique words, find all pairs of distinct indices (i, j) in the given list, so that t ...
- jvm内存设置
JVM有很多个内存管理命令,总体而言,分为两类: 1.-X开头的管理命令:这些选项在JDK升级时不会通知修改: 2.-XX开头的管理命令:这些选项不够稳定,所以建议少用. JVM参数的含义: 参数名称 ...
- 转:python webdriver API 之分页处理
对于 web 页面上的分页功能,我们一般做做以下操作: 获取总页数 翻页操作(上一页,下一页) 对于有些分页功能提供上一页,下一页按钮,以及可以输入具体页面数跳转功能不在本例的讨论范围. .. ...
- java 8种基本数据类型
数值型--> 整 型:int,short,long,byte 浮点型:double,float 字符型-->char 布尔型-->boolean
- js 默认选中select 选项
<select id="HDname" style="width: 150px;"><option value="0"&g ...
- (转) 关于Oracle EBS邮件服务无法使用的报错
来源http://blog.itpub.net/23850820/viewspace-1060596/ 也可以检查如下网站:http://blog.sina.com.cn/s/blog_5b021b4 ...
- struts拦截器
struts中的拦截器相当于过滤器的作用 一在struts.xml中配置拦截器或拦截器栈 <interceptors>!--全部的拦截器 <interceptor name=&quo ...
- css 标签 垂直居中
<!DOCTYPE html > <html xmlns="http://www.w3.org/1999/xhtml"> <head> < ...
- [php] PHP Fatal error: Class 'AMQPConnection' not found
When using rabbitmq, $this->conn = new AMQPConnection($conn_args); $this->conn->connect(); ...