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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • InitializingBean afterPropertiesSet方法

    afterPropertiesSet方法,初始化bean的时候执行,可以针对某个具体的bean进行配置。afterPropertiesSet必须实现InitializingBean接口。实现InitializingBean接口必须实现afterPropertiesSet方法。

    2022年4月11日
    173
  • 最短路——Floyd – Warshall核心算法的理解

    最短路——Floyd – Warshall核心算法的理解

    2021年9月28日
    67
  • Androidlistview_android listview的用法

    Androidlistview_android listview的用法下面是activity:[java] viewplaincopypublic class MainActivity extends Activity {        private ListView mListView = null;      private List mList = null;        @Overri

    2022年10月3日
    3
  • jQuery+HTML5弹出创意搜索框层

    效果体验:http://hovertree.com/texiao/jquery/26/本效果适用于移动设备,可以使用手机等浏览效果。代码下载:http://hovertree.com/h/bjaf/e

    2021年12月21日
    40
  • Python迭代器实现

    Python迭代器实现文章目录欢迎访问我的个人博客引言 iter 和 next 实现可迭代的斐波那契数列类参考欢迎访问我的个人博客博客引言在 Python 编程中 我们经常使用 for in 语句对容器进行迭代 容器类 比如列表 元组等 之所以可以被 for in 语句迭代 是因为这些容器类实现了 iter 魔术方法 这个方法返回一个迭代器对象 迭代器对象实现了 next 魔术方法 这个方法可以移动迭代器和获取迭代器指向的值 如果我们想要实现支持迭代的对象 只需要实现 iter 方法以及 iter 返

    2025年12月11日
    3
  • python3安装后没有pip_解决Centos7安装python3后pip工具无法使用「建议收藏」

    python3安装后没有pip_解决Centos7安装python3后pip工具无法使用「建议收藏」问题描述:Centos7安装python3,正常流程全部配置完成,python3,pip3的软链接也建立了但是python3可以正常使用,而pip3报错,无法找到文件或目录解决方法:which命令:查找python的路径type命令:也是查找python的路径发现两次命令查询的结果并不一致使用hash-r清除Linux下哈希表中所有缓存,下次再typepython就会去系统环境变量中查找路径,…

    2025年11月26日
    3

发表回复

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

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