2011-07-17 168 views
3

我在SURF上做了一个项目,到目前为止我已经成功实现了SURF特性,并且我也正确地完成了特性评估。但我不知道如何做DESCRIPTOR评估......我使用的是C++/opencv svn。SURF的描述符评估opencv

Here你可以找到来自OpenCV的SVN示例代码(这说明如何使用评价者,但在我的代码我不能用它......

我的代码:

#include "cv.h" // include standard OpenCV headers, same as before 
#include "highgui.h" 
#include "ml.h" 
#include <stdio.h> 
#include <iostream> 
#include <opencv2/features2d/features2d.hpp> 
#include <opencv2/imgproc/imgproc.hpp> 
#include <opencv2/highgui/highgui.hpp> 
#include <vector> 
//#include "precomp.hpp" 


using namespace cv; // all the new API is put into "cv" namespace. Export its content 
using namespace std; 

using std::cout; 
using std::cerr; 
using std::endl; 
using std::vector; 

// enable/disable use of mixed API in the code below. 
#define DEMO_MIXED_API_USE 1 
void warpPerspectiveRand(const Mat& src, Mat& dst, Mat& H, RNG& rng) 
{ 
    H.create(3, 3, CV_32FC1); 
    H.at<float>(0,0) = rng.uniform(0.8f, 1.2f); 
    H.at<float>(0,1) = rng.uniform(-0.1f, 0.1f); 
    H.at<float>(0,2) = rng.uniform(-0.1f, 0.1f)*src.cols; 
    H.at<float>(1,0) = rng.uniform(-0.1f, 0.1f); 
    H.at<float>(1,1) = rng.uniform(0.8f, 1.2f); 
    H.at<float>(1,2) = rng.uniform(-0.1f, 0.1f)*src.rows; 
    H.at<float>(2,0) = rng.uniform(-1e-4f, 1e-4f); 
    H.at<float>(2,1) = rng.uniform(-1e-4f, 1e-4f); 
    H.at<float>(2,2) = rng.uniform(0.8f, 1.2f); 

    warpPerspective(src, dst, H, src.size()); 
} 




double match(const vector<KeyPoint>& /*kpts_train*/, const vector<KeyPoint>& /*kpts_query*/, DescriptorMatcher& matcher, 
      const Mat& train, const Mat& query, vector<DMatch>& matches) 
{ 

    double t = (double)getTickCount(); 
    matcher.match(query, train, matches); //Using features2d 
    return ((double)getTickCount() - t)/getTickFrequency(); 
} 


void simpleMatching(Ptr<DescriptorMatcher>& descriptorMatcher, 
        const Mat& descriptors1, const Mat& descriptors2, 
        vector<DMatch>& matches12); 

int main(int argc, char** argv) 
{ 

string im1_name, im2_name; 
    im1_name = "lena.jpg"; 
    im2_name = "lena.jpg"; 

Mat img1 = imread(im1_name, 1); 
Mat img2 = imread(im2_name, 1); 

RNG rng = theRNG(); 
Mat H12; 
warpPerspectiveRand(img1, img2, H12, rng); 




    SurfFeatureDetector detector(2000); 
    vector<KeyPoint> keypoints1, keypoints2; 
    detector.detect(img1, keypoints1); 
    detector.detect(img2, keypoints2); 


float repeatability; 
int correspCount; 
evaluateFeatureDetector(img1, img2, H12, &keypoints1, &keypoints2, repeatability, correspCount); 

cout << "repeatability = " << repeatability << endl; 
     cout << "correspCount = " << correspCount << endl; 

    // computing descriptors 
    SurfDescriptorExtractor extractor; 
    Mat descriptors1, descriptors2; 
    extractor.compute(img1, keypoints1, descriptors1); 
    extractor.compute(img2, keypoints2, descriptors2); 


    return 0; 
} 

所以我问题是:如何评价描述符SURF(如何做),我在很多方面尝试,但我不能这样做..

谢谢你这么多

回答

0

使用一个描述符垫cher

cv::BruteForceMatcher< cv::L2<float> > matcher; 
std::vector<cv::DMatch> matches; 
matcher.match(descriptors1, descriptors2, matches); 

这会给你一个匹配的向量。看看DMatch的文档。

也可以看看这个函数:

cv::drawMatches(image1, keypoints1, image2, keypoints2, matches, outimage); 
cv::imshow("foo", outimage); 
+0

我想这些功能,并成功地与我的工作,我关心的是这样的:当我实现功能PTR GDM =新VectorDescriptorMatcher(提取器,匹配器);它不是除了提取器和匹配器,我需要这两个参数来实现下一个函数,它是valuateGenericDescriptorMatcher(img1,img2,H12,keypoints1,keypoints2,0,0,curve,gdm);所以你有什么想法我在这里做错了 – Mario

+2

没有。我建议你关闭这个问题,并用一个简单的例子来问一个新问题。 – Unapiedra