用opencv提取fFAST角点和SURF描述子这遇到的问题

    技术2022-07-11  84

    用opencv提取fFAST角点和SURF描述子这遇到的问题

    今天在提FAST取特征点和SURF描述子的时候居然出现了问题,我一直以为这玩意上手就干呢,毕竟也是用的opencv的库,现在才发现我还是个弟弟。

    第一个问题:

    OpenCV Error: Assertion failed (src.type() == (((0) & ((1 << 3) - 1)) + (((1)-1) << 3)) || src.type() == (((5) & ((1 << 3) - 1)) + (((1)-1) << 3))) in cornerEigenValsVecs, file /tmp/binarydeb/ros-kinetic-opencv3-3.3.1/modules/imgproc/src/corner.cpp, line 269 这个问题我找到了一个解决办法,链接,解决办法我是从这里找到的。知道解决了,并没有去深究是什么原因导致的。

    第二个问题:

    OpenCV Error: The function/feature is not implemented () in detectAndCompute, file /tmp/binarydeb/ros-kinetic-opencv3-3.3.1/modules/features2d/src/feature2d.cpp, line 154 这个问题参考链接。 现在把我提取SURF描述子的代码贴到下面:

    #include<opencv2/opencv.hpp> #include <opencv2/xfeatures2d.hpp> #include <opencv2/features2d/features2d.hpp> using namespace std; using namespace cv; using namespace cv::xfeatures2d; int main(int argc, char** argv) { Mat img_1 = imread("/home/yang/line-with-opencv/src/data/image1.png",0); Mat img_2 = imread("/home/yang/line-with-opencv/src/data/image3.png",0); if(!img_1.empty()) { cout<<"the image is read"<<endl; } cout<<" -- Step 1: Detect the keypoints using STAR Detector"<<endl; vector<cv::Point2f> key1,key2; vector<KeyPoint> keypoints_1,keypoints_2; StarDetector detector; //detector.detect(img_1, keypoints_1); //detector.detect(img_2, keypoints_2); goodFeaturesToTrack(img_1,key1,500,0.01,10); goodFeaturesToTrack(img_2,key2,500,0.01,10); cout<<" -- Stpe 2: Calculate descriptors (feature vectors)"<<endl; for(int i = 0; i < (int)key1.size(); i++) { cv::KeyPoint key; key.pt = key1[i]; keypoints_1.push_back(key); } for(int i = 0; i < (int)key2.size(); i++) { cv::KeyPoint key; key.pt = key1[i]; keypoints_2.push_back(key); } Ptr<cv::DescriptorExtractor> brief; brief = xfeatures2d::BriefDescriptorExtractor::create(); cv::Mat descriptors_1, descriptors_2; brief->compute(img_1,keypoints_1,descriptors_1); brief->compute(img_2,keypoints_2,descriptors_2) cout<<"-- Step 3: Matching descriptor vectors with a brute force matcher"<<endl; BFMatcher matcher(NORM_HAMMING); std::vector<DMatch> mathces; matcher.match(descriptors_1, descriptors_2, mathces); // -- dwaw matches Mat img_mathes; drawMatches(img_1, keypoints_1, img_2, keypoints_2, mathces, img_mathes); // -- show imshow("Mathces", img_mathes); waitKey(0); return 0; }

    代码执行结果如下: 结果很乱,也没有去剔除误匹配。

    Processed: 0.011, SQL: 10