关于Opencv2.4.x中stitcher类的简单应用
?
1.opencv2.4以上版本有stitcher類,可以簡單方便的實(shí)現(xiàn)圖像的拼接,目前只是簡單的測(cè)試一下stitcher類的拼接功能,也是糾結(jié)了好長時(shí)間,最終發(fā)現(xiàn)是要在鏈接庫中加上opencv_stitching249.lib(對(duì)于Release),opencv_stitching249d.lib(對(duì)于Debug)才行,不然會(huì)出現(xiàn)VS2013編譯不成功,錯(cuò)誤提示是:(注:紅色數(shù)字249是當(dāng)前opencv的版本號(hào),根據(jù)你的opencv版本號(hào),更改這個(gè)數(shù)值)
?
1>main.obj : error LNK2019: unresolved external symbol "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) referenced in function _main1>main.obj : error LNK2019: unresolved external symbol "public: static class cv::Stitcher __cdecl cv::Stitcher::createDefault(bool)" (?createDefault@Stitcher@cv@@SA?AV12@_N@Z) referenced in function _main 1>D:visual studio 2010Projectsstitching20Debugstitching20.exe : fatal error LNK1120: 2 unresolved externals
?
? ? ? ? 下面是測(cè)試程序:
編譯環(huán)境:
? ? ? ?操作系統(tǒng):XP
? ? ? ?opencv版本:2.4.9
? ? ? ?編譯器版本:VS2013
程序代碼?
#include <iostream>#include <fstream>
#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"; //void printUsage(); //int parseCmdArgs(int argc, char** argv);
int main(int argc, char* argv[])
{
Mat img=imread("1.jpg");
imgs.push_back(img);
img=imread("2.jpg");
imgs.push_back(img);
img=imread("3.jpg");
imgs.push_back(img);
Mat pano;
Stitcher stitcher = Stitcher::createDefault(try_use_gpu);
Stitcher::Status status = stitcher.stitch(imgs, pano);
if (status != Stitcher::OK)
{
cout << "Can't stitch images, error code = " << int(status) << endl;
return -1;
}
imwrite(result_name, pano);
return 0;
}
除了上面的錯(cuò)誤之外,還會(huì)出現(xiàn)像下面的錯(cuò)誤,很多個(gè)
stitching\detail\warpers_inl.hpp(186): error C2059: 語法錯(cuò)誤:“::”
錯(cuò)誤代碼示例:
?2.錯(cuò)誤原因
?? 函數(shù)模板max與Visual C++中的全局的宏max沖突。?
3.解決辦法
? ? 1.第一種辦法:設(shè)置項(xiàng)目屬性,在預(yù)定義處理器中添加定義NOMINMAX來禁止使用Visual C++的min/max宏定義。
???????????????????????項(xiàng)目屬性?? ——> C/C++ ——> 預(yù)處理器 ——> 預(yù)處理器定義 (此處添加預(yù)定義編譯開關(guān)?? NOMINMAX)
但是visual C++中定義能自動(dòng)匹配double和int,如果進(jìn)行了上述設(shè)置,代碼中手動(dòng)將int型的數(shù)據(jù)乘以1.0來達(dá)到double的目的。
? ? 2.第二種辦法:?加上括號(hào),與Vsual C++的min/max宏定義區(qū)分開? ? ? ? ? ? ? ? ??
size.Width?=?std::max(size.Width,?elementSize.Width); ? 修改為如下內(nèi)容:? ? size.Width?=?(std::max)(size.Width,?elementSize.Width); ?
?
轉(zhuǎn)載于:https://www.cnblogs.com/fengting/p/4978364.html
總結(jié)
以上是生活随笔為你收集整理的关于Opencv2.4.x中stitcher类的简单应用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 5大食物千万别挑太艳的
- 下一篇: 【C#】事件,委托3点详解