gis如何无缝拼接两张图_opencv图像拼接

gis如何无缝拼接两张图_opencv图像拼接intMyVideoStitcher::Prepare(vector<Mat>&src){ cv::setBreakOnError(true); intnum_images=static_cast<int>(src.size()); if(num_images<2) { printf(“Needmoreimages”); returnSTITCH_CONFIG_ERROR; } intcudaStatus=testG.

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

int MyVideoStitcher::Prepare(vector<Mat> &src)
{
	cv::setBreakOnError(true);
	int num_images = static_cast<int>(src.size());
	if (num_images < 2)
	{
		printf("Need more images");
		return STITCH_CONFIG_ERROR;
	}

	int cudaStatus = testGPU();
	if( is_try_gpu_ && cudaStatus != 0 )
	{
		//printf("GPU acceleration failed! Error code: " <<  cudaStatus << " Please ensure that you have a CUDA-capable GPU installed!");
		printf("Stitching with CPU next ...");
		return STITCH_CONFIG_ERROR;
	}
	
	int flag;
	warp_type_ = "apap";
	if(warp_type_ == "apap")
		flag = PrepareAPAP(src);
	else
		flag = PrepareClassical(src);
	
	if(flag == 0 && is_try_gpu_)
	{
		flag = initGPU(num_images);
		if(flag != 0)
			return flag;
		C2GInitData *c2g_data = new C2GInitData[num_images];
		for(int i = 0; i < num_images; i++)
		{
			c2g_data[i].xmap			= xmaps_[i].ptr<float>(0);
			c2g_data[i].ymap			= ymaps_[i].ptr<float>(0);
			c2g_data[i].ec_weight		= ec_weight_maps_[i].ptr<float>(0);
			c2g_data[i].blend_weight	= blend_weight_maps_[i].ptr<float>(0);
			c2g_data[i].total_weight	= total_weight_maps_[i].ptr<float>(0);
			c2g_data[i].height			= src[i].rows;
			c2g_data[i].width			= src[i].cols;
			c2g_data[i].warped_height	= xmaps_[i].rows;
			c2g_data[i].warped_width	= xmaps_[i].cols;
			c2g_data[i].corner_x		= corners_[i].x - dst_roi_.x;
			c2g_data[i].corner_y		= corners_[i].y - dst_roi_.y;
		}
		initdataCopy2GPU(c2g_data, dst_roi_.height, dst_roi_.width);
	}

	if(flag == STITCH_SUCCESS)
	{
		printf("\t~Prepare complete");
		is_prepared_ = true;
	}

	return flag;
}


int MyVideoStitcher::PrepareAPAP(vector<Mat> &src)
{
	int num_images = static_cast<int>(src.size());

	this->InitMembers(num_images);

	// 计算一些放缩的尺度,在特征检测和计算接缝的时候,为了提高程序效率,可以对源图像进行一些放缩
	work_megapix_ = -1;	//	先不考虑放缩
	seam_megapix_ = -1;	//	先不考虑放缩
	this->SetScales(src);

	// 特征检测
	vector<ImageFeatures> features(num_images);
	this->FindFeatures(src, features);

	// 特征匹配,并去掉噪声图片
	vector<MatchesInfo> pairwise_matches;
	this->MatchImages(features, pairwise_matches);

	// APAP算法
	APAPWarper apap_warper;
	apap_warper.buildMaps(src, features, pairwise_matches, xmaps_, ymaps_, corners_);
	for(int i = 0; i < num_images; i++)
		sizes_[i] = xmaps_[i].size();
	dst_roi_ = resultRoi(corners_, sizes_);

	// 计算接缝
	vector<Mat> seamed_masks(num_images);
	vector<Mat> images_warped(num_images);
	vector<Mat> init_masks(num_images);
	for(int i = 0; i < num_images; i++)
	{
		init_masks[i].create(src[i].size(), CV_8U);
		init_masks[i].setTo(Scalar::all(255));
		remap(src[i], images_warped[i], xmaps_[i], ymaps_[i], INTER_LINEAR);
		remap(init_masks[i], final_warped_masks_[i], xmaps_[i], ymaps_[i], INTER_NEAREST, BORDER_CONSTANT);
		final_warped_masks_[i].copyTo(seamed_masks[i]);
	}
	this->FindSeam(images_warped, seamed_masks);
	printf("find seam");

	// 曝光补偿
	compensator_.createWeightMaps(corners_, images_warped, final_warped_masks_, ec_weight_maps_);
	// 曝光补偿时,各像素权值也要resize一下
	compensator_.gainMapResize(sizes_, ec_weight_maps_);
	printf("compensate");

	images_warped.clear();

	// 计算融合时,各像素的权值
	Size dst_sz = dst_roi_.size();
	//cout << "dst size: " << dst_sz << endl;
	float blend_width = sqrt(static_cast<float>(dst_sz.area())) * blend_strength_ / 100.f;
	blender_.setSharpness(1.f / blend_width);
	for(int i = 0; i < num_images; i++)
		final_blend_masks_[i] = final_warped_masks_[i] & seamed_masks[i];
	blender_.createWeightMaps(dst_roi_, corners_, seamed_masks, blend_weight_maps_);

	return STITCH_SUCCESS;
}

int MyVideoStitcher::FindFeatures(vector<Mat> &src, vector<ImageFeatures> &features)
{
	Ptr<Feature2D> finder;
	if (features_type_ == "surf")
	{
#ifdef HAVE_OPENCV_GPU
		if (is_try_gpu_ && gpu::getCudaEnabledDeviceCount() > 0)
			finder = new SurfFeaturesFinderGpu();
		else
#endif
			finder = xfeatures2d::SURF::create();
	}
	else if (features_type_ == "orb")
	{
		finder = ORB::create();
	}
	else
	{
		cout << "Unknown 2D features type: '" << features_type_ << "'.\n";
		return STITCH_CONFIG_ERROR;
	}

	int num_images = static_cast<int>(src.size());
	Mat full_img, img;

	for (int i = 0; i < num_images; ++i)
	{
		full_img = src[i].clone();//

		if (work_megapix_ < 0)
			img = full_img;
		else
			resize(full_img, img, Size(), work_scale_, work_scale_);

		computeImageFeatures(finder, img, features[i]);
		//LOGLN("Features in image #" << i+1 << "("<<img.size()<< "): " << features[i].keypoints.size());
		features[i].img_idx = i;
	}

	//finder->collectGarbage();
	full_img.release();
	img.release();

	return STITCH_SUCCESS;
}



/*
 * 特征匹配,然后去除噪声图片。本代码实现时,一旦出现噪声图片,就终止算法
 * 返回值:
 *		0	——	正常
 *		-2	——	存在噪声图片
 */
int MyVideoStitcher::MatchImages(vector<ImageFeatures> &features, vector<MatchesInfo> &pairwise_matches)
{
	int total_num_images = static_cast<int>(features.size());

	BestOf2NearestMatcher matcher(is_try_gpu_, match_conf_);
	matcher(features, pairwise_matches);
	matcher.collectGarbage();
	
	// 去除噪声图像
	vector<int> indices = leaveBiggestComponent(features, pairwise_matches, conf_thresh_);
	
	// 一旦出现噪声图片,就终止算法
	int num_images = static_cast<int>(indices.size());
	if (num_images != total_num_images)
	{
		//LOGLN(total_num_images - num_images << " videos are invaild");
		return STITCH_NOISE;
	}
	
	return STITCH_SUCCESS;
}

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/190737.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • win10专业工作站版激活码_通用破解码

    win10专业工作站版激活码_通用破解码,https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月17日
    195
  • 用matlab画三维图实例_cad绘制3d图形的教程

    用matlab画三维图实例_cad绘制3d图形的教程文章目录一、引言二、绘制三维空间曲线三、绘制三维空间曲面1.基本概念2.示例(1)3.示例(2)4.等高线的曲面图5.被光照射带阴影的曲面6.图形修饰方法四、绘制等高线一、引言一图胜前言,本篇文章的目的就是绘制这样的三维图形二、绘制三维空间曲线plot3——基本的三维曲线绘制命令调用格式:plot3(x,y,z)——x,y,z是长度相同的向量plot3(X,Y,Z)——X,Y,Z是维数相同的矩阵plot3(x,y,z,’s’)——开关量字符串s用来设定曲线颜色和

    2022年10月11日
    3
  • tomcat部署war包后访问项目报错404问题[通俗易懂]

    tomcat部署war包后访问项目报错404问题[通俗易懂]首先查看log日志,根据报错去查找问题。日志在你的tomcat文件夹下的logs文件夹里面。我把tomcat布置到服务器上之后并没有把我先前跨域更改的lib中的jar包再次更改导致了一直无法访问项目,查看log之后发现是这个问题就再次对服务器上的项目进行了跨域设置就可以访问了。…

    2022年5月8日
    472
  • 分布式事务TCC(Hmily)

    分布式事务TCC(Hmily)1什么是TCC事务?TCC是Try、Confirm、Cancel三个词语,TCC分布式事务的三个操作:预处理Try、确认Confirm、撤销Cancel。Try操作业务检查以及资源预留,Confirm做业务确认操作,Cancel实现一个月try相反的操作即为回滚操作。Try操作全部成功,TM将会发起所有分支事务的Confirm操作,如Confirm/Cancel操作失败,TM进行重试。分支事务失败的情况:TCC分了三个阶段:(1)Try阶段是做业务检查以及资源预留,此阶段仅是一个初步操作,它和

    2022年5月21日
    39
  • eWebEditor漏洞分析

    eWebEditor漏洞分析现在eWebEditor在线编辑器用户越来越多,危害就越来越大。首先介绍编辑器的一些默认特征:   默认登陆admin_login.asp   默认数据库db/ewebeditor.mdb   默认帐号admin密码admin或admin888   在baidu/google搜索inurl:ewebeditor   几万的站起码有几千个是具有默认特征的,那么试一下默认后台   htt…

    2022年7月14日
    17
  • 网站地图起什么作用

    网站地图起什么作用

    2021年9月23日
    55

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号