Program Listing for File target-aprilgrid.h

Return to documentation for file (aslam_cv2/aslam_cv_calibration/include/aslam/calibration/target-aprilgrid.h)

#ifndef ASLAM_CALIBRATION_TARGET_APRILGRID_H
#define ASLAM_CALIBRATION_TARGET_APRILGRID_H

#include <memory>
#include <string>
#include <vector>

#include <apriltags/TagDetector.h>
#include <apriltags/Tag36h11.h>
#include <Eigen/Core>
#include <opencv2/core/core.hpp>

#include "aslam/calibration/target-base.h"
#include "aslam/calibration/target-observation.h"

namespace aslam {
namespace calibration {

class TargetAprilGrid : public TargetBase {
 public:
  ASLAM_POINTER_TYPEDEFS(TargetAprilGrid);

  struct TargetConfiguration {
    TargetConfiguration()
        : num_tag_rows(6u),
          num_tag_cols(6u),
          tag_size_meter(0.088),
          tag_inbetween_space_meter(0.0264),
          black_tag_border_bits(2u) {};
    size_t num_tag_rows;
    size_t num_tag_cols;

    double tag_size_meter;
    double tag_inbetween_space_meter;
    size_t black_tag_border_bits;

    static TargetConfiguration fromYaml(const std::string& yaml_file);
  };

  TargetAprilGrid(const TargetConfiguration& target_config);
  virtual ~TargetAprilGrid() {};

  const TargetConfiguration& getConfig() const {
    return target_config_;
  }

 private:
  const TargetConfiguration target_config_;
};

Eigen::Matrix3Xd createAprilGridPoints(
    const TargetAprilGrid::TargetConfiguration& target_config);

class DetectorAprilGrid : public DetectorBase {
 public:
  ASLAM_POINTER_TYPEDEFS(DetectorAprilGrid);

  struct DetectorConfiguration {
    DetectorConfiguration()
        : run_subpixel_refinement(true),
          max_subpixel_refine_displacement_px_sq(1.5),
          min_visible_tags_for_valid_obs(4),
          min_border_distance_px(4.0) {};
    bool run_subpixel_refinement;
    double max_subpixel_refine_displacement_px_sq;
    size_t min_visible_tags_for_valid_obs;
    double min_border_distance_px;
  };

  DetectorAprilGrid(const TargetAprilGrid::Ptr& target,
                    const DetectorAprilGrid::DetectorConfiguration& detector_config);
  virtual ~DetectorAprilGrid() {};

  virtual TargetObservation::Ptr detectTargetInImage(const cv::Mat& image) const;

 private:
  const TargetAprilGrid::Ptr target_;
  const DetectorConfiguration detector_config_;

  AprilTags::TagCodes tag_codes_;
  std::unique_ptr<AprilTags::TagDetector> tag_detector_;
};

}  // namespace calibration
}  // namespace aslam

#endif  // ASLAM_CALIBRATION_TARGET_APRILGRID_H