surf在opencv3.1.0用法及error LNK2019: 无法解析的外部符号 "public: __thiscall cv::SURF::SURF

error LNK2019: 无法解析的外部符号 "public: __thiscall cv::SURF::SURF(double,int,int,bool,bool)" (??0SURF@cv@@QAE@NHH_N0@Z)

解决办法:VS2015中,设置项目属性->链接器->输入->附加依赖项里面添加上添加库文件opencv_xfeatures2d310d.lib和   opencv_xfeatures2d310.lib  其中310为opencv的版本。

如果还报错,把其它的库也加上,


下面附上surf在opencv3.1.0中的用法。

#include "stdafx.h"
#include <iostream>
#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <opencv2\features2d\features2d.hpp>
#include <opencv2\xfeatures2d.hpp>


using namespace std;
using namespace cv;
using namespace  cv::xfeatures2d;

int main()
{
	Mat srcImage1 = imread("H:\\test\\VS2015_projects\\\A.png", IMREAD_GRAYSCALE);
	Mat srcImage2 = imread("H:\\test\\VS2015_projects\\\B.png", IMREAD_GRAYSCALE);

	//判断文件是否读取成功
	if (srcImage1.empty() || srcImage2.empty())
	{
		cout << "图像加载失败!";
		return -1;
	}
	else
		cout << "图像加载成功..." << endl << endl;

	//检测两幅图像中的特征点
	Ptr<SURF> surf;      //创建方式和opencv2中的不一样,并且要加上命名空间xfeatures2d.
	surf = SURF::create(800);  //定义阈值
	//SurfFeatureDetector detector(minHessian);       //定义Surf检测器
	vector<KeyPoint>keypoint1, keypoint2;           //定义两个KeyPoint类型矢量存储检测到的特征点
	surf->detect(srcImage1, keypoint1);
	surf->detect(srcImage2, keypoint2);

	//计算特征向量的描述子
	//SurfDescriptorExtractor descriptorExtractor;
	Mat descriptors1, descriptors2;

	surf->compute(srcImage1, keypoint1, descriptors1);
	surf->compute(srcImage2, keypoint2, descriptors2);

	//使用BruteForceMatcher进行描述符匹配
	BFMatcher matcher(NORM_L2);
	vector<DMatch>matches;
	matcher.match(descriptors1, descriptors2, matches);

	//绘制匹配特征点
	Mat matchImage;
	drawMatches(srcImage1, keypoint1, srcImage2, keypoint2, matches, matchImage);

	//显示匹配的图像
	namedWindow("Match", WINDOW_NORMAL);
	imshow("Match", matchImage);

	waitKey(0);

	return 0;
}




猜你喜欢

转载自blog.csdn.net/csdn330/article/details/79984876