Hi, and thank you very much for this code! I am using KORAL to get features and descriptors, and trying to match using K2NN. Using the below code:
// ------------- KORAL ------------
KORAL koral(scale_factor, scale_levels);
KORAL koral2(scale_factor, scale_levels);
int64 t0 = cv::getTickCount();
koral.go(image.data, image.cols, image.rows, KFAST_thresh);
koral2.go(image2.data, image2.cols, image2.rows, KFAST_thresh);
int64 t1 = cv::getTickCount();
double secs = (t1 - t0) / cv::getTickFrequency();
std::cout << "features took: " << secs * 1000 << std::endl;
cv::Mat image_with_kps, image_with_kps2;
std::vector<cv::KeyPoint> converted_kps;
std::vector<cv::KeyPoint> converted_kps2;
for (const auto& kp : koral.kps) {
const float scale = static_cast<float>(std::pow(scale_factor, kp.scale));
converted_kps.emplace_back(scale*static_cast<float>(kp.x), scale*static_cast<float>(kp.y), 7.0f*scale, 180.0f / 3.1415926535f * kp.angle, static_cast<float>(kp.score));
}
for (const auto& kp : koral2.kps) {
const float scale = static_cast<float>(std::pow(scale_factor, kp.scale));
converted_kps2.emplace_back(scale*static_cast<float>(kp.x), scale*static_cast<float>(kp.y), 7.0f*scale, 180.0f / 3.1415926535f * kp.angle, static_cast<float>(kp.score));
}
constexpr int runs = 50;
constexpr int threshold = 5;
constexpr int max_twiddles = 20;
constexpr bool first_order = false;
// --------------------------------
Matcher<false> m(&koral.desc[0], static_cast<int>(koral.kps.size()), &koral2.desc[0], static_cast<int>(koral2.kps.size()), threshold, max_twiddles);
std::chrono::high_resolution_clock::time_point start = std::chrono::high_resolution_clock::now();
m.exactMatch();
std::chrono::high_resolution_clock::time_point end = std::chrono::high_resolution_clock::now();
const double sec = static_cast<double>(std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count()) * 1e-9 / static_cast<double>(runs);
std::cout << std::endl << "Brute force K2NN found " << m.matches.size() << " matches in " << sec * 1e3 << " ms" << std::endl;
// std::vector<cv::DMatch> dmatches;
std::vector<cv::KeyPoint> _kps1;
std::vector<cv::KeyPoint> _kps2;
for (int i = 0; i < m.matches.size(); ++i) {
// dmatches.emplace_back(m.matches[i].q, m.matches[i].t, 0.0f);
_kps1.push_back(converted_kps[m.matches[i].q]);
_kps2.push_back(converted_kps2[m.matches[i].t]);
}
cv::drawMarker(image, _kps1[0].pt, cv::Scalar(255, 0, 0), cv::MARKER_CROSS, 8, 1, 8);
cv::drawMarker(image2, _kps2[0].pt, cv::Scalar(255, 0, 0), cv::MARKER_CROSS, 8, 1, 8);
cv::imshow("1", image);
cv::imshow("2", image2);
I get 800+ matches, in a very short time.
What i am having trouble with, is validating the matches. The last section of the code above I would expect to show me two markers, on the two images, in the same place, but they are far apart instead. Am I doing something wrong here? or do i need to filter to get 'good' matches after running K2NN? Thank you again!