关于Opencv2.4.x中stitcher类的简单应用
?
1.opencv2.4以上版本有stitcher類,可以簡單方便的實現圖像的拼接,目前只是簡單的測試一下stitcher類的拼接功能,也是糾結了好長時間,最終發現是要在鏈接庫中加上opencv_stitching249.lib(對于Release),opencv_stitching249d.lib(對于Debug)才行,不然會出現VS2013編譯不成功,錯誤提示是:(注:紅色數字249是當前opencv的版本號,根據你的opencv版本號,更改這個數值)
?
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
?
? ? ? ? 下面是測試程序:
編譯環境:
? ? ? ?操作系統: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;
}
除了上面的錯誤之外,還會出現像下面的錯誤,很多個
stitching\detail\warpers_inl.hpp(186): error C2059: 語法錯誤:“::”
錯誤代碼示例:
?2.錯誤原因
?? 函數模板max與Visual C++中的全局的宏max沖突。?
3.解決辦法
? ? 1.第一種辦法:設置項目屬性,在預定義處理器中添加定義NOMINMAX來禁止使用Visual C++的min/max宏定義。
???????????????????????項目屬性?? ——> C/C++ ——> 預處理器 ——> 預處理器定義 (此處添加預定義編譯開關?? NOMINMAX)
但是visual C++中定義能自動匹配double和int,如果進行了上述設置,代碼中手動將int型的數據乘以1.0來達到double的目的。
? ? 2.第二種辦法:?加上括號,與Vsual C++的min/max宏定義區分開? ? ? ? ? ? ? ? ??
size.Width?=?std::max(size.Width,?elementSize.Width); ? 修改為如下內容:? ? size.Width?=?(std::max)(size.Width,?elementSize.Width); ?
?
轉載于:https://www.cnblogs.com/fengting/p/4978364.html
總結
以上是生活随笔為你收集整理的关于Opencv2.4.x中stitcher类的简单应用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 5大食物千万别挑太艳的
- 下一篇: 【C#】事件,委托3点详解