本文主要是介绍OpenCV2.3.1特征点提取,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
今天做特征点匹配实验,从网上找来了SURF特征点检测程序,调试也调通了,但是运行之后就是没有结果出来,还会出现运行之后程序崩溃的问题,后来试了好多遍,发现是由于lib文件有问题,虽然在属性里已经添加了,但是仍然链接不上。解决方法是在程序开始添加lib文件,如下所示。
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/imgproc/imgproc.hpp"
#include "core/core.hpp"
#include "cv.h"
#include "fstream"
#include "iostream"#if defined _DEBUG
#pragma comment(lib,"opencv_core231d.lib")
#pragma comment(lib,"opencv_imgproc231d.lib")
#pragma comment(lib,"opencv_highgui231d.lib")
#pragma comment(lib,"opencv_features2d231d.lib")
#pragma comment(lib,"opencv_calib3d231d.lib")
#pragma comment(lib,"opencv_flann231d.lib")
#else
#pragma comment(lib,"opencv_core231.lib")
#pragma comment(lib,"opencv_imgproc231.lib")
#pragma comment(lib,"opencv_highgui231.lib")
#pragma comment(lib,"opencv_features2d231.lib")
#pragma comment(lib,"opencv_calib3d231.lib")
#endif#include <vector> using namespace cv;
using namespace std;int main(int argc,char* argv[])
{IplImage *pLeftImage = cvLoadImage(".\\156.tif", CV_LOAD_IMAGE_GRAYSCALE);IplImage *pRightImage = cvLoadImage(".\\157.tif", CV_LOAD_IMAGE_GRAYSCALE);// Convert IplImage to cv::MatMat matLeftImage = Mat(pLeftImage, false); // Do not copyMat matRightImage = Mat(pRightImage, false);// Key point and its descriptorvector<KeyPoint> LeftKey;vector<KeyPoint> RightKey;Mat LeftDescriptor;Mat RightDescriptor;vector<DMatch> Matches;// Detect key points from imageFeatureDetector *pDetector = new SurfFeatureDetector; // 这里我们用了SURF特征点pDetector->detect(matLeftImage, LeftKey);pDetector->detect(matRightImage, RightKey);delete pDetector;// Extract descriptorsDescriptorExtractor *pExtractor = new SurfDescriptorExtractor; // 提取SURF描述向量pExtractor->compute(matLeftImage, LeftKey, LeftDescriptor);pExtractor->compute(matRightImage, RightKey, RightDescriptor);delete pExtractor;// Matching featuresDescriptorMatcher *pMatcher = new FlannBasedMatcher; // 使用Flann匹配算法pMatcher->match(LeftDescriptor, RightDescriptor, Matches);delete pMatcher;// Show resultMat OutImage;drawMatches(matLeftImage, LeftKey, matRightImage, RightKey, Matches, OutImage);cvNamedWindow( "Match features", 1);cvShowImage("Match features", &(IplImage(OutImage)));cvWaitKey( 0 );cvDestroyWindow( "Match features" );return 0;
}
这篇关于OpenCV2.3.1特征点提取的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!