komrad36 / LATCH

Fastest CPU implementation of the LATCH 512-bit binary feature descriptor; fully scale- and rotation-invariant
MIT License
34 stars 12 forks source link

LATCH with multi scale keypoints #9

Open dbs4261 opened 5 years ago

dbs4261 commented 5 years ago

Ive been working on rigging together a CPU pipeline that corresponds to KORAL. One thing I have not been able to figure out is if, when describing keypoints on a scaled image, LATCH should run on the scaled image? Below is the code sample I am using for detecting and computing keypoints. To prove that it is working, I am using the opencv brute force matcher.

template <bool nonmax_suppression=true, bool multithread=false>
void PyramidDetectAndCompute(const uint8_t* image, uint32_t width, uint32_t height, float scale_factor, 
    uint8_t scale_levels, uint8_t threshold, std::vector<Keypoint>& kps, std::vector<Descriptor512>& descs) {
  kps = Detect<nonmax_suppression, multithread>(image, width, height, threshold);
  descs = Compute<multithread>(image, width, height, kps);

  std::vector<uint8_t> scaled;
  float scale = 1.0f;
  for (uint8_t l = 2; l <= scale_levels; l++) {
    scale /= scale_factor;
    const auto level_width = static_cast<uint32_t>(lround(width * scale));
    const auto level_height = static_cast<uint32_t>(lround(height * scale));
    scaled.resize(level_width * level_height);
    KLERP<multithread>(image, width, height, scaled.data(), level_width, level_height);

    auto level_kps = Detect<nonmax_suppression, multithread>(scaled.data(), level_width, level_height, threshold, l);
    std::vector<Descriptor512> level_descs(level_kps.size());
//    LATCH<multithread>(scaled.data(), level_width, level_height, level_width, level_kps, level_descs.data());
    LATCH<multithread>(image, width, height, width, level_kps, level_descs.data());
    level_descs.resize(level_kps.size());
    kps.insert(kps.end(), std::make_move_iterator(level_kps.begin()), std::make_move_iterator(level_kps.end()));
    descs.insert(descs.end(), std::make_move_iterator(level_descs.begin()), std::make_move_iterator(level_descs.end()));
  }
}