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<xfeatures2d::SiftFeatureDetector> featureDetector = xfeatures2d::SiftFeatureDetector::create();
//featureDetector.detect(trainImage_gray, train_keyPoint);
featureDetector->detect(trainImage_gray, train_keyPoint);

源代碼(《OpenCV3編程入門》綜合示例:SIFT配合暴力匹配進行關鍵點描述和提取)

#include<iostream>
#include<opencv2/opencv.hpp>
#include<opencv2/features2d/features2d.hpp>
#include<opencv2/xfeatures2d/nonfree.hpp>
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);
	vector<KeyPoint>train_keyPoint;
	Mat trainDescription;

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


	Ptr<xfeatures2d::SiftDescriptorExtractor> featureExtractor = xfeatures2d::SiftDescriptorExtractor::create();
	featureExtractor->compute(trainImage_gray, train_keyPoint, trainDescription);
	BFMatcher matcher;
	vector<Mat>train_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);
		vector<KeyPoint>test_keyPoint;
		Mat testDescriptor;
		featureDetector->detect(captureImage_gray, test_keyPoint);
		featureExtractor->compute(captureImage_gray, test_keyPoint, testDescriptor);

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

		vector<DMatch>goodMatches;
		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;
}

效果:
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章