Ask Your Question
2

Why this code returns different number of keypoints in Java?

asked 2013-03-18 19:36:02 -0500

rylexr gravatar image

Hi, Can someone explain why this Java code:

Mat ok1 = Highgui.imread("/some/path/k1.png");
Mat ok2 = Highgui.imread("/some/path/k2.png");
Mat k1 = new Mat();
Mat k2 = new Mat();
MatOfKeyPoint mk1 = new MatOfKeyPoint();
MatOfKeyPoint mk2 = new MatOfKeyPoint();
Mat md1 = new Mat();
Mat md2 = new Mat();

Imgproc.cvtColor(ok1, k1, Imgproc.COLOR_BGR2GRAY);
Imgproc.cvtColor(ok2, k2, Imgproc.COLOR_BGR2GRAY);

FeatureDetector detector = FeatureDetector.create(FeatureDetector.PYRAMID_FAST);
DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.ORB);

detector.detect(k1, mk1);
detector.detect(k2, mk2);
extractor.compute(k1, mk1, md1);
extractor.compute(k2, mk2, md2);

System.out.println("k1 has " + mk1.total() + " points (descriptors " + md1.rows() + ")");
System.out.println("k2 has " + mk2.total() + " points (descriptors " + md2.rows() + ")");

displays a different number of KeyPoints (for whatever images) than this C++ code:

cv::Mat ok1 = cv::imread("/some/path/k1.png");
cv::Mat ok2 = cv::imread("/some/path/k2.png");
cv::Mat k1;
cv::Mat k2;
std::vector<cv::KeyPoint> mk1;
std::vector<cv::KeyPoint> mk2;
cv::Mat md1;
cv::Mat md2;

cv::cvtColor(ok1, k1, CV_BGR2GRAY);
cv::cvtColor(ok2, k2, CV_BGR2GRAY);

cv::Ptr<cv::FeatureDetector> detector;
cv::Ptr<cv::DescriptorExtractor> extractor;
detector = cv::FeatureDetector::create("PyramidFAST");
extractor = cv::DescriptorExtractor::create("ORB");

detector->detect(k1, mk1);
detector->detect(k2, mk2);
extractor->compute(k1, mk1, md1);
extractor->compute(k2, mk2, md2);

cout << "k1 has " << mk1.size() << " points (descriptors " << md1.rows << ")\n";
cout << "k2 has " << mk2.size() << " points (descriptors " << md2.rows << ")\n";

Aren't they the same code in different languages?

Regards

* Using OpenCV 2.4.4 *

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-03-26 10:44:03 -0500

Andrey Pavlenko gravatar image

updated 2013-03-26 10:44:35 -0500

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-03-18 19:36:02 -0500

Seen: 462 times

Last updated: Mar 26 '13