Program Listing for File matching-problem-frame-to-frame.h

Return to documentation for file (aslam_cv2/aslam_cv_matcher/include/aslam/matcher/matching-problem-frame-to-frame.h)

#ifndef ASLAM_CV_MATCHING_PROBLEM_FRAME_TO_FRAME_H_
#define ASLAM_CV_MATCHING_PROBLEM_FRAME_TO_FRAME_H_


#include <map>
#include <memory>
#include <vector>

#include <aslam/common/macros.h>
#include <aslam/common/memory.h>
#include <aslam/common/pose-types.h>
#include <aslam/common/feature-descriptor-ref.h>
#include <Eigen/Core>

#include "aslam/matcher/match.h"
#include "aslam/matcher/matching-problem.h"

namespace aslam {
class VisualFrame;

class MatchingProblemFrameToFrame : public MatchingProblem {
public:
  ASLAM_POINTER_TYPEDEFS(MatchingProblemFrameToFrame);
  ASLAM_DISALLOW_EVIL_CONSTRUCTORS(MatchingProblemFrameToFrame);
  ASLAM_ADD_MATCH_TYPEDEFS(FrameToFrame);
  friend class MatcherTest;

  MatchingProblemFrameToFrame() = delete;

  MatchingProblemFrameToFrame(const VisualFrame& apple_frame,
                              const VisualFrame& banana_frame,
                              const aslam::Quaternion& q_A_B,
                              double image_space_distance_threshold_pixels,
                              int hamming_distance_threshold);
  virtual ~MatchingProblemFrameToFrame() {};

  virtual size_t numApples() const;
  virtual size_t numBananas() const;

  virtual void getAppleCandidatesForBanana(int frame_banana_keypoint_index, Candidates* candidates);

  inline double computeMatchScore(int hamming_distance) {
    return static_cast<double>(384 - hamming_distance) / 384.0;
  }

  inline int computeHammingDistance(int banana_index, int apple_index) {
    CHECK_LT(apple_index, static_cast<int>(apple_descriptors_.size()))
        << "No descriptor for this apple.";
    CHECK_LT(banana_index, static_cast<int>(banana_descriptors_.size()))
        << "No descriptor for this banana.";
    CHECK_LT(apple_index, static_cast<int>(valid_apples_.size()))
        << "No valid flag for this apple.";
    CHECK_LT(banana_index, static_cast<int>(valid_bananas_.size()))
        << "No valid flag for this apple.";
    CHECK(valid_apples_[apple_index]) << "The given apple is not valid.";
    CHECK(valid_bananas_[banana_index]) << "The given banana is not valid.";

    const common::FeatureDescriptorConstRef& apple_descriptor =
        apple_descriptors_[apple_index];
    const common::FeatureDescriptorConstRef& banana_descriptor =
        banana_descriptors_[banana_index];

    CHECK_NOTNULL(apple_descriptor.data());
    CHECK_NOTNULL(banana_descriptor.data());

    return common::GetNumBitsDifferent(banana_descriptor, apple_descriptor);
  }

  virtual bool doSetup();

private:
  const VisualFrame& apple_frame_;
  const VisualFrame& banana_frame_;
  aslam::Quaternion q_A_B_;
  std::multimap<size_t, size_t> y_coordinate_to_apple_keypoint_index_map_;

  std::vector<bool> valid_apples_;
  std::vector<bool> valid_bananas_;

  Aligned<std::vector, Eigen::Vector2d> A_projected_keypoints_banana_;

  std::vector<common::FeatureDescriptorConstRef> apple_descriptors_;

  std::vector<common::FeatureDescriptorConstRef> banana_descriptors_;

  size_t descriptor_size_bytes_;

  int vertical_band_halfwidth_pixels_;

  double squared_image_space_distance_threshold_px_sq_;

  int hamming_distance_threshold_;

  size_t image_height_apple_frame_;
};
}
#endif //ASLAM_CV_MATCHING_PROBLEM_FRAME_TO_FRAME_H_