OpenCV(3.4.6) Error: The function/feature is not implemented () in cv::Feature2D::detectAndCompute

OpenCV(3.4.6) Error: The function/feature is not implemented () in cv::Feature2D::detectAndCompute

最近想用opencv中的特征检测与匹配,无赖老是遇到错误,查了好多博客都是千篇一律,说要勾选OPENCV_ENABLE_NONFREE,编译时我确实勾选了OPENCV_ENABLE_NONFREE,但是还是用不了,估计有很多人都是这样吧,后来我去国外网站找了下,找到了解决方法,不知道对各位遇到这种问题的有没有帮助。

问题

OpenCV(3.4.6) Error: The function/feature is not implemented () in cv::Feature2D::detectAndCompute, file E:\ck_tools\opencv3.4.6\opencv\sources\modules\features2d\src\feature2d.cpp, line 154
解决:

//xfeatures2d::SiftFeatureDetector featureDetector;
Ptr featureDetector = xfeatures2d::SiftFeatureDetector::create();
//featureDetector.detect(trainImage_gray, train_keyPoint);
featureDetector->detect(trainImage_gray, train_keyPoint);

源代码(《OpenCV3编程入门》综合示例:SIFT配合暴力匹配进行关键点描述和提取)

#include
#include
#include
#include
using namespace std;
using namespace cv;

int main()
{
	Mat trainImage = imread("./image/1.jpg"), trainImage_gray;
	//imshow("trainImage", trainImage);
	cvtColor(trainImage, trainImage_gray,COLOR_BGR2GRAY);
	vectortrain_keyPoint;
	Mat trainDescription;

	//SiftFeatureDetector featureDetector;
	//featureDetector.detect(trainImage_gray, train_keyPoint);
	Ptr featureDetector = xfeatures2d::SiftFeatureDetector::create();
	featureDetector->detect(trainImage_gray, train_keyPoint);


	Ptr featureExtractor = xfeatures2d::SiftDescriptorExtractor::create();
	featureExtractor->compute(trainImage_gray, train_keyPoint, trainDescription);
	BFMatcher matcher;
	vectortrain_desc_collection(1,trainDescription);
	matcher.add(train_desc_collection);
	matcher.train();

	VideoCapture cap(0);
	unsigned int frameCount = 0;
	while (char(waitKey(1)) != 'q')
	{
		double time0 = getTickCount();
		Mat captureImage, captureImage_gray;
		cap >> captureImage;
		if (captureImage.empty())
			continue;
		cvtColor(captureImage, captureImage_gray, COLOR_BGR2GRAY);
		vectortest_keyPoint;
		Mat testDescriptor;
		featureDetector->detect(captureImage_gray, test_keyPoint);
		featureExtractor->compute(captureImage_gray, test_keyPoint, testDescriptor);

		vector>matches;
		matcher.knnMatch(testDescriptor, matches, 2);

		vectorgoodMatches;
		for (unsigned int i = 0; i < matches.size(); i++)
		{
			if (matches[i][0].distance < 0.6*matches[i][1].distance)
				goodMatches.push_back(matches[i][0]);
		}
		Mat dstImage;
		drawMatches(captureImage, test_keyPoint, trainImage, train_keyPoint, goodMatches, dstImage);
		cout << "frame rate:" << getTickFrequency() / (getTickCount() - time0) << endl;
		imshow("dstImage", dstImage);
	}
	return 0;
}

效果:

你可能感兴趣的:(opencv)