1 | initial version |
It is the classical L2 distance for floating point descriptor and HAMMING like distance for binary descriptor.
You can check it with the following code:
cv::Mat img1 = cv::imread("opencv-3.1.0/samples/data/aero1.jpg");
cv::Mat img2 = cv::imread("opencv-3.1.0/samples/data/aero3.jpg");
cv::Ptr<cv::Feature2D> sift = cv::xfeatures2d::SIFT::create();
std::vector<cv::KeyPoint> trainKeypoints;
cv::Mat trainDescriptors;
sift->detectAndCompute(img1, cv::Mat(), trainKeypoints, trainDescriptors);
std::vector<cv::KeyPoint> queryKeypoints;
cv::Mat queryDescriptors;
sift->detectAndCompute(img2, cv::Mat(), queryKeypoints, queryDescriptors);
cv::Ptr<cv::DescriptorMatcher> matcher = cv::DescriptorMatcher::create("BruteForce");
std::vector<cv::DMatch> matches;
matcher->match(queryDescriptors, trainDescriptors, matches);
std::cout << "matches[0]: trainIdx=" << matches[0].trainIdx << " ; queryIdx="
<< matches[0].queryIdx << " ; dist=" << matches[0].distance << std::endl;
double my_dist = 0.0;
for(int j = 0; j < trainDescriptors.cols; j++) {
my_dist += (trainDescriptors.at<float>(matches[0].trainIdx, j) - queryDescriptors.at<float>(matches[0].queryIdx, j))
* (trainDescriptors.at<float>(matches[0].trainIdx, j) - queryDescriptors.at<float>(matches[0].queryIdx, j));
}
std::cout << "my_dist=" << cv::sqrt(my_dist) << std::endl;
2 | No.2 Revision |
It is the classical L2 distance for floating point descriptor and HAMMING like distance for binary descriptor.
You can check it with the following code:
cv::Mat img1 = cv::imread("opencv-3.1.0/samples/data/aero1.jpg");
cv::Mat img2 = cv::imread("opencv-3.1.0/samples/data/aero3.jpg");
cv::Ptr<cv::Feature2D> sift = cv::xfeatures2d::SIFT::create();
std::vector<cv::KeyPoint> trainKeypoints;
cv::Mat trainDescriptors;
sift->detectAndCompute(img1, cv::Mat(), trainKeypoints, trainDescriptors);
std::vector<cv::KeyPoint> queryKeypoints;
cv::Mat queryDescriptors;
sift->detectAndCompute(img2, cv::Mat(), queryKeypoints, queryDescriptors);
cv::Ptr<cv::DescriptorMatcher> matcher = cv::DescriptorMatcher::create("BruteForce");
std::vector<cv::DMatch> matches;
matcher->match(queryDescriptors, trainDescriptors, matches);
std::cout << "matches[0]: trainIdx=" << matches[0].trainIdx << " ; queryIdx="
<< matches[0].queryIdx << " ; dist=" << matches[0].distance << std::endl;
double my_dist = 0.0;
for(int j = 0; j < trainDescriptors.cols; j++) {
my_dist += (trainDescriptors.at<float>(matches[0].trainIdx, j) - queryDescriptors.at<float>(matches[0].queryIdx, j))
* (trainDescriptors.at<float>(matches[0].trainIdx, j) - queryDescriptors.at<float>(matches[0].queryIdx, j));
}
std::cout << "my_dist=" << cv::sqrt(my_dist) << std::endl;
Edit: the type of distance that could be used is present in the documentation.