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::Mat

	Mat matLeftImage = Mat(pLeftImage, false); // Do not copy
	Mat matRightImage = Mat(pRightImage, false);

	// Key point and its descriptor

	vector<KeyPoint> LeftKey;
	vector<KeyPoint> RightKey;

	Mat LeftDescriptor;
	Mat RightDescriptor;

	vector<DMatch> Matches;

	// Detect key points from image

	FeatureDetector *pDetector = new SurfFeatureDetector; // 这里我们用了SURF特征点
	pDetector->detect(matLeftImage, LeftKey);
	pDetector->detect(matRightImage, RightKey);

	delete pDetector;

	// Extract descriptors

	DescriptorExtractor *pExtractor = new SurfDescriptorExtractor; // 提取SURF描述向量
	pExtractor->compute(matLeftImage, LeftKey, LeftDescriptor);
	pExtractor->compute(matRightImage, RightKey, RightDescriptor);

	delete pExtractor;

	// Matching features

	DescriptorMatcher *pMatcher = new FlannBasedMatcher; // 使用Flann匹配算法
	pMatcher->match(LeftDescriptor, RightDescriptor, Matches);

	delete pMatcher;

	// Show result

	Mat OutImage;
	drawMatches(matLeftImage, LeftKey, matRightImage, RightKey, Matches, OutImage);
	cvNamedWindow( "Match features", 1);
	cvShowImage("Match features", &(IplImage(OutImage)));
	cvWaitKey( 0 );
	cvDestroyWindow( "Match features" );

	return 0;
}





你可能感兴趣的:(opencv)