1.opencv2.4 above version has Stitcher class, can be simple and convenient to achieve image splicing, at present just a simple test of stitcher class splicing function, but also tangled for a long time, the final discovery is to add opencv_stitching in the link library 249. Lib (for release), opencv_stitching249d.lib (for debug), otherwise the VS2013 compilation is unsuccessful, error message is: (Note: Red number 249 is the current OPENCV version number, depending on your OPENCV version number, change this value)
1>main.obj:error lnk2019:unresolved External symbol "Public:static class Cv::stitcher __cdecl cv::stitcher::created Efault (BOOL) "([email Protected]@[email protected]@[email protected][email protected]) referenced in function _main 1 >d:visual Studio 2010projectsstitching20debugstitching20.exe:fatal Error Lnk1120:2 unresolved externals
Here is the test program:
Compilation Environment:
Operating system: XP
OpenCV version: 2.4.9
Compiler version: VS2013
Program code
#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;
}
In addition to the above error, there will be errors like the following, a lot of
STITCHING\DETAIL\WARPERS_INL.HPP (186): Error C2059: Syntax errors: "::"
Error code example:
- Size. Width = Std::max (size. Width, Elementsize.width);
2. Cause of Error
The function template max conflicts with the global macro Max in Visual C + +.
3. Workaround
1. First approach: Set project properties, add definition Nominmax to predefined processors to disallow the use of Visual C + + MIN/MAX macro definitions.
Item Properties--c/c++--> preprocessor--preprocessor definition (here add predefined compile switch Nominmax)
However, the definition in Visual C + + can automatically match double and int, and if you do this, the code manually multiplies the data of type int by 1.0来 to double.
2. The second approach: parentheses, separate from the vsual C + + MIN/MAX macro definition
Size. Width = Std::max (size. Width, Elementsize.width); Modify the following to read:
Size. Width = (Std::max) (size. Width, Elementsize.width);
Simple application of Stitcher class in opencv2.4.x