Jay_z在造梦 2021-03-07 21:19 采纳率: 0%
浏览 692

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);
}

这是错误的内容:

  • 写回答

1条回答 默认 最新

  • luimn 2021-05-17 11:02
    关注

    解决了吗  博主

    评论

报告相同问题?

悬赏问题

  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 arduino控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题