失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > OpenCV18(图像拼接stitcher_detail)

OpenCV18(图像拼接stitcher_detail)

时间:2024-02-11 14:04:20

相关推荐

OpenCV18(图像拼接stitcher_detail)

从OpenCV2.4.0之后的版本中都包含有一个图像拼接的例程。路径:“...\opencv\sources\samples\cpp\stitcher_detail.cpp”

本文就网上基于图像拼接的例程代码总结一下,基本上都是由此修改而来。以下给出原代,以及一个简单版本的例程。

1.一个简单的例子(易于理解)

#include "stdafx.h"#include <iostream>#include <fstream>#include <opencv2/core/core.hpp>#include "opencv2/highgui/highgui.hpp"#include "opencv2/stitching/stitcher.hpp"using namespace std;using namespace cv;bool try_use_gpu = false;vector<Mat> imgs;string result_name = "result.jpg";int main(){Mat img1=imread("1.jpg");Mat img2=imread("2.jpg");imgs.push_back(img1);imgs.push_back(img2);Mat pano;Stitcher stitcher = Stitcher::createDefault(try_use_gpu);//关键语句一Stitcher::Status status = stitcher.stitch(imgs, pano);//关键语句二if (status != Stitcher::OK){cout << "Can stitch images, error code = " << status << endl;return -1;}namedWindow(result_name);imshow(result_name,pano);imwrite(result_name,pano);waitKey();return 0;}

注意事项:

1.图像可以多幅,但是建议先两幅

2.图像之间的重合度要高一点

3.图像的大小建议一样,不一样的还没测试

问题解决:

1.问题描述:

1>stitch.obj : error LNK: 无法解析的外部符号 "public: static class cv::Stitcher __cdecl cv::Stitcher::createDefault(bool)" (?createDefault@Stitcher@cv@@SA?AV12@_N@Z),该符号在函数 _main 中被引用

1>stitch.obj : error LNK: 无法解析的外部符号 "public: enum cv::Stitcher::Status __thiscall cv::Stitcher::stitch(class cv::_InputArray const &,class cv::_OutputArray const &)" (?stitch@Stitcher@cv@@QAE?AW4Status@12@ABV_InputArray@2@ABV_OutputArray@2@@Z),该符号在函数 _main 中被引用

这种错误出在配置上,缺少opencv_stitching294.lib,这个不常用,在opencv配置教程中一般都没有包含。

解决方法

在属性中(我原来是用属性管理器中配置opencv的)

找不到的话,在下图中输入“属性”,点击 属性管理器

在连接器中(link)->输入->附加依赖项,添加“opencv_stitching249d.lib”(看你的版本了)。如果你是用debug,不要添加opencv_stitching249.lib(没有d)。这里还涉及一个问题,见4中的描述

4.问题描述

Stitcher::Status status = stitcher.stitch(imgs, pano);//关键语句二 运行出错 | vector访问出错 | vector小标越界 | 程序中断如下 | 0x00000005错误

解决方法

原因还是在OpenCV的配置上。如果你是debug,将属性管理器中的所有不带d的lib文件都删去(建议你放记事本里备份)。如果是release,就把带d的都删去。

测试发现,平时使用的时候,会在属性管理器的“Microsoft.Cpp.Win32.user”中加上带d和不带d的lib,这样就不需要每个工程都配置opencv了。

但是debug中的“Microsoft.Cpp.Win32.user”和release中的是同一个,会相互影响,修改哪一个中的都不行,于是全部添加上。相信有很多人都是这样的,所以这个问题应该是很多人都会遇到的吧。改过了就可以了。

最后注意一下,拼接成功的概率不高,应该是代码还不够优化吧。只要通过了“关键代码二”,基本配置上就不会有问题了。剩下的就要自己调参数了。

2.一个截图程序

(稍后附上)

3.源代码(复制过来的)

/*M/////// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.//// By downloading, copying, installing or using the software you agree to this license.// If you do not agree to this license, do not download, install,// copy or use the software.//////License Agreement//For Open Source Computer Vision Library//// Copyright (C) 2000-, Intel Corporation, all rights reserved.// Copyright (C) , Willow Garage Inc., all rights reserved.// Third party copyrights are property of their respective owners.//// Redistribution and use in source and binary forms, with or without modification,// are permitted provided that the following conditions are met://// * Redistributions of source code must retain the above copyright notice,//this list of conditions and the following disclaimer.//// * Redistributions in binary form must reproduce the above copyright notice,//this list of conditions and the following disclaimer in the documentation//and/or other materials provided with the distribution.//// * The name of the copyright holders may not be used to endorse or promote products//derived from this software without specific prior written permission.//// This software is provided by the copyright holders and contributors "as is" and// any express or implied warranties, including, but not limited to, the implied// warranties of merchantability and fitness for a particular purpose are disclaimed.// In no event shall the Intel Corporation or contributors be liable for any direct,// indirect, incidental, special, exemplary, or consequential damages// (including, but not limited to, procurement of substitute goods or services;// loss of use, data, or profits; or business interruption) however caused// and on any theory of liability, whether in contract, strict liability,// or tort (including negligence or otherwise) arising in any way out of// the use of this software, even if advised of the possibility of such damage.//////M*/#include <iostream>#include <fstream>#include <string>#include "opencv2/opencv_modules.hpp"#include "opencv2/highgui/highgui.hpp"#include "opencv2/stitching/detail/autocalib.hpp"#include "opencv2/stitching/detail/blenders.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/util.hpp"#include "opencv2/stitching/detail/warpers.hpp"#include "opencv2/stitching/warpers.hpp"using namespace std;using namespace cv;using namespace cv::detail;static void printUsage(){cout <<"Rotation model images stitcher.\n\n""stitching_detailed img1 img2 [...imgN] [flags]\n\n""Flags:\n"" --preview\n""Run stitching in the preview mode. Works faster than usual mode,\n""but output image will have lower resolution.\

如果觉得《OpenCV18(图像拼接stitcher_detail)》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。