Ask Your Question

Java: dense SIFT?

asked 2014-09-02 03:51:38 -0500


I have written my Java code for the detection of keypoints using SIFT, as follows:

FeatureDetector featureDetector = FeatureDetector.create(FeatureDetector.SIFT);
MatOfKeyPoint keypoints = new MatOfKeyPoint();
featureDetector.detect(image, keypoints);

where image is a Mat variable containing the image.

However, I am not sure how to compute the dense SIFT descriptors, as contained in the PHOW computation of the VLFeat library. Is there a way of doing this?

Thank you in advance.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2014-09-03 03:30:05 -0500

jestshen gravatar image

I have written it in C++, You can have a try, because they are simular.

initModule_nonfree();//if use SIFT or SURF Ptr<featuredetector> detector = FeatureDetector::create("SIFT"); Ptr<descriptorextractor> descriptor_extractor = DescriptorExtractor::create("SIFT"); Ptr<descriptormatcher> descriptor_matcher = DescriptorMatcher::create("BruteForce"); //if( detector.empty() || descriptor_extractor.empty() ) // MessageBox(_T("aaaaa")); //throw runtime_error("fail to create detector!");

Mat img1 = imread("1.jpg");
Mat img2 = imread("2.jpg");
//detect keypoints;
vector<KeyPoint> keypoints1,keypoints2;
detector->detect( img1, keypoints1 );
detector->detect( img2, keypoints2 );
//cout <<"img1:"<< keypoints1.size() << " points  img2:" <<keypoints2.size() 
//  << " points" << endl << ">" << endl;

//compute descriptors for keypoints;
//cout << "< Computing descriptors for keypoints from images..." << endl;
Mat descriptors1,descriptors2;
descriptor_extractor->compute( img1, keypoints1, descriptors1 );
descriptor_extractor->compute( img2, keypoints2, descriptors2 );

//cout<<endl<<"Descriptors Size: "<<descriptors2.size()<<" >"<<endl;
//cout<<endl<<"Descriptor's Column: "<<descriptors2.cols<<endl
//  <<"Descriptor's Row: "<<descriptors2.rows<<endl;
//cout << ">" << endl;

//Draw And Match img1,img2 keypoints
Mat img_keypoints1,img_keypoints2;
imshow("Box_in_scene keyPoints",img_keypoints1);
imshow("Box keyPoints",img_keypoints2);

descriptor_extractor->compute( img1, keypoints1, descriptors1 );  
vector<DMatch> matches;
descriptor_matcher->match( descriptors1, descriptors2, matches );

Mat img_matches;

edit flag offensive delete link more
Login/Signup to Answer

Question Tools


Asked: 2014-09-02 03:51:38 -0500

Seen: 648 times

Last updated: Sep 03 '14