weixin_46135347
假z、
2021-03-07 21:19

surf:无法解析的外部符号 Ptr<class cv::xfeatures2d::SURF>

问题就很奇怪,我是win10系统+VS2019+Opencv4.5.1+OpenCV_contrib4.5.1。运行sift特征检测十分正常,但是运行surfte特征检测就baoc报错,头文件也放了nonfree.hpp和xfeatures2d.hpp,还是无法通过编译,查阅了很多类似的问题都说是缺少依赖,但是opencv4.5+已经没有了opencv_xfeatures2d451d.lib(有可能拼写错误)类似的依赖。

这个问题是昨天出现的,今天早上我选择了重新编译opencv_contribtuoz拓展包,然后成功运行surf特征点检测程序(昨晚报错的),我就以为没啥问题了,结果今晚编程surf特征点匹配相关的程序,又报错。求求大佬帮帮我。

这是代码(ps:个人觉得不是代码问题,应该是环境或者其他问题):

#include <opencv2/opencv.hpp>
#include <opencv2/xfeatures2d/nonfree.hpp>
#include <opencv2/xfeatures2d.hpp>
#include <iostream>
#include <vector>

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

void surf_features(Mat& img, vector<KeyPoint>& keypoints, Mat& desriptions);

int main(int agrc, char* agrv[])
{
	Mat src1 = imread("box.png");
	Mat src2 = imread("box_in_scene.png");
	if (!src1.data || !src2.data)
	{
		cout << "请检查图片文件是否正确!!!" << endl;
		return -1;
	}

	//提取、计算特征点
	vector<KeyPoint>keypoints1, keypoints2;
	Mat descriptions1, descriptions2;
	surf_features(src1, keypoints1, descriptions1);
	surf_features(src2, keypoints2, descriptions2);

	//特征点匹配
	vector<DMatch>matches;
	BFMatcher matcher(NORM_L2);
	matcher.match(descriptions1, descriptions2, matches);
	cout << "matches = " << matches.size() << endl;

	//筛选汉明距离匹配结果
	double min_dist = 1000, max_dist = 0;
	for (int i = 0; i < matches.size(); i++)
	{
		double dist = matches[i].distance;
		if (dist < min_dist) min_dist = dist;
		if (dist > max_dist) max_dist = dist;
	}

	//输出所有匹配结果中最大汉明距离和最小汉明距离
	cout << "min_dist = " << min_dist << endl;
	cout << "max_dist = " << max_dist << endl;

	//将汉明距离较大的匹配点对删除
	vector<DMatch>good_matches;
	for (int i = 0; i < matches.size(); i++)
	{
		if (matches[i].distance <= max(2 * min_dist, 20.0))
		{
			good_matches.push_back(matches[i]);
		}
	}
	cout << "good_min = " << good_matches.size() << endl;

	//绘制匹配结果
	Mat dst1, dst2;
	drawMatches(src1, keypoints1, src2, keypoints2, matches, dst1);
	drawMatches(src1, keypoints1, src2, keypoints2, good_matches, dst2);

	//显示结果
	imshow("未筛选的结果", dst1);
	imshow("最小汉明距离筛选", dst2);

	waitKey(0);
	return 0;
}

void surf_features(Mat& img, vector<KeyPoint>& keypoints, Mat& desriptions)
{
	Ptr<SURF>surf = SURF::create();
	surf->detectAndCompute(img, noArray(), keypoints, desriptions, false);
}

这是错误的内容:

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答