SURF opencv 的描述符评估
我正在做一个关于 SURF 的项目,到目前为止我已经成功实现了 SURF 功能,并且我也正确地完成了功能评估。但我不知道如何进行描述符评估...我正在使用 c++/opencv svn。
此处你可以从opencv svn找到示例代码(这展示了如何使用EVALUATOR,但我无法在我的代码中使用它......
我的代码:
#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 的描述符(如何做到这一点)我尝试了很多方法,但我无法做到这一点..
非常感谢
I'm doing a project on SURF and so far I have implemented SURF features successfully, and I have done the feature evaluation correctly as well. But I don't know how to do the DESCRIPTOR evaluation... I'm using c++/opencv svn.
Here you can find the sample code from opencv svn(That shows how use the EVALUATOR but I couldn't use it in my code...
My code:
#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;
}
So my question is: How to evaluate the descriptor for SURF(How to do that) I tried in many ways but I couldn't do that..
Thank you so much
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用描述符匹配器
这将为您提供匹配向量。查看 DMatch 的文档。
另请看一下这个函数:
Use a descriptor matcher
This will get you a vector of matches. Have a look at the documentation for
DMatch
.Also have a look at this function: