版本
由于每个版本的代码偏差都比较大,这里是基于opencv 3.4.5版本的开发
https://github.com/opencv/opencv/releases/tag/3.4.5
https://github.com/opencv/opencv_contrib/releases/tag/3.4.5
编译命令:
cmake -DOPENCV_ENABLE_NONFREE=ON -DBUILD_EXAMPLES=ON -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-3.4.5/modules ..
./bin/example_cpp_stitching --try_use_gpu yes --mode panorama ./image_left-1585642221.jpg ./image_center-1585642221.jpg image_right-1585642221.jpg
代码样例
特征点查看代码样例
#include <iostream>
#include <vector>
#include "opencv2/core.hpp"
#ifdef HAVE_OPENCV_XFEATURES2D
#include "opencv2/highgui.hpp"
#include "opencv2/features2d.hpp"
#include "opencv2/xfeatures2d.hpp"
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv/cv.hpp>
#include <opencv2/imgcodecs/imgcodecs.hpp>
#include <opencv2/calib3d/calib3d.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/features2d.hpp>
#include <opencv2/calib3d.hpp>
using namespace cv;
using namespace cv::xfeatures2d;
using std::cout;
using std::endl;
int main( int argc, char* argv[] )
{
CommandLineParser parser( argc, argv, "{@input | box.png | input image}" );
Mat img1 = imread(argv[1], IMREAD_GRAYSCALE );
Mat img2 = imread(argv[2], IMREAD_GRAYSCALE );
if ( img1.empty() )
{
cout << "Could not open or find the image!
" << endl;
cout << "Usage: " << argv[0] << " <Input image>" << endl;
return -1;
}
Mat wide = imread("image_wide.png", IMREAD_GRAYSCALE );
//-- Step 1: Detect the keypoints using SURF Detector
int minHessian = 400;
Ptr<SURF> detector = SURF::create( minHessian );
std::vector<KeyPoint> keypoints1;
std::vector<KeyPoint> keypoints2;
detector->detect(img2, keypoints2);
detector->detect(img1, keypoints1);
Ptr<SURF> extractor = SURF::create();
Mat descriptors1, descriptors2;
extractor->compute(img1, keypoints1, descriptors1);
extractor->compute(img2, keypoints2, descriptors2);
//BFMatcher<L2<float> > matcher;
DescriptorMatcher* matcher = new BFMatcher(NORM_L2,false);
std::vector<DMatch> matches;
matcher->match(descriptors1, descriptors2, matches);
namedWindow("matches", 1);
Mat img_matches;
drawMatches(img1, keypoints1, img2, keypoints2, matches, img_matches);
imshow("matches", img_matches);
waitKey(0);
//-- Draw keypoints
Mat img_keypoints;
drawKeypoints(img1, keypoints1, img_keypoints );
//-- Show detected (drawn) keypoints
imshow("SURF Keypoints", img_keypoints );
waitKey();
return 0;
}
#else
int main()
{
std::cout << "This tutorial code needs the xfeatures2d contrib module to be run." << std::endl;
return 0;
}
#endif
融合测试命令
./bin/example_cpp_stitching_detailed a0.jpg a1.jpg a2.jpg --features orb --save_graph graph.dot --conf_thresh 0.5
H264 数据
https://blog.csdn.net/oldmtn/article/details/46742555
https://github.com/hirorogithub/ffmpeg_sample-H264_to_cv-Mat/blob/master/H264Decoder.cpp
https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples
遇到问题
# 编译报错 # fatal error: boostdesc_bgm.i: No such file or directory # https://github.com/opencv/opencv_contrib/issues/1301 # 文件列表见目录 # opencv_contrib/modules/xfeatures2d/cmake/download_boostdesc.cmake #### 如果可以通过curl命令下载 curl https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_lbgm.i > 0ea90e7a8f3f7876d450e4149c97c74f-boostdesc_lbgm.i #### 可以直接访问网址下载
# fatal error: vgg_generated_120.i: No such file or directory
# opencv_contrib/modules/xfeatures2d/cmake/download_vgg.cmake
# 下载完成后拷贝到目录 opencv_contrib/modules/xfeatures2d/src/
# 编译报错 # fatal error: opencv2/xfeatures2d/cuda.hpp: No such file or directory # https://github.com/opencv/opencv_contrib/issues/1534
# 修改opencv-3.4.5/CMakeLists.txt 增加下行 INCLUDE_DIRECTORIES("/home/xxxx/opencv/opencv_contrib-3.4.5/modules/xfeatures2d/include") # 重新执行cmake命令
参考文档
https://docs.opencv.org/3.0-beta/doc/user_guide/ug_features2d.html
https://www.jb51.net/article/154643.htm
https://docs.opencv.org/trunk/d1/d46/group__stitching.html
https://docs.opencv.org/3.4/d2/dfd/samples_2cpp_2filestorage_8cpp-example.html#_a11