1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
#pragma once
#include <Eigen/Dense>
#include <PoseLib/camera_pose.h>
#include <vector>
namespace poselib {
struct AbsolutePoseProblemInstance {
public:
// Ground truth camera pose
CameraPose pose_gt;
double scale_gt = 1.0;
double focal_gt = 1.0;
// Point-to-point correspondences
std::vector<Eigen::Vector3d> x_point_;
std::vector<Eigen::Vector3d> X_point_;
// Point-to-line correspondences
std::vector<Eigen::Vector3d> x_line_;
std::vector<Eigen::Vector3d> X_line_;
std::vector<Eigen::Vector3d> V_line_;
// Line-to-point correspondences
std::vector<Eigen::Vector3d> l_line_point_;
std::vector<Eigen::Vector3d> X_line_point_;
// Line-to-line correspondences
std::vector<Eigen::Vector3d> l_line_line_;
std::vector<Eigen::Vector3d> X_line_line_;
std::vector<Eigen::Vector3d> V_line_line_;
// For generalized cameras we have an offset in the camera coordinate system
std::vector<Eigen::Vector3d> p_point_;
std::vector<Eigen::Vector3d> p_line_;
std::vector<Eigen::Vector3d> p_line_point_;
std::vector<Eigen::Vector3d> p_line_line_;
};
struct RelativePoseProblemInstance {
public:
// Ground truth camera pose
CameraPose pose_gt;
Eigen::Matrix3d H_gt; // for homography problems
double scale_gt = 1.0;
double focal_gt = 1.0;
// Point-to-point correspondences
std::vector<Eigen::Vector3d> p1_;
std::vector<Eigen::Vector3d> x1_;
std::vector<Eigen::Vector3d> p2_;
std::vector<Eigen::Vector3d> x2_;
};
struct CalibPoseValidator {
// Computes the distance to the ground truth pose
static double compute_pose_error(const AbsolutePoseProblemInstance &instance, const CameraPose &pose, double scale);
static double compute_pose_error(const RelativePoseProblemInstance &instance, const CameraPose &pose);
static double compute_pose_error(const RelativePoseProblemInstance &instance, const ImagePair &image_pair);
// Checks if the solution is valid (i.e. is rotation matrix and satisfies projection constraints)
static bool is_valid(const AbsolutePoseProblemInstance &instance, const CameraPose &pose, double scale, double tol);
static bool is_valid(const RelativePoseProblemInstance &instance, const CameraPose &pose, double tol);
static bool is_valid(const RelativePoseProblemInstance &instance, const ImagePair &image_pair, double tol);
};
struct HomographyValidator {
// Computes the distance to the ground truth pose
static double compute_pose_error(const RelativePoseProblemInstance &instance, const Eigen::Matrix3d &H);
// Checks if the solution is valid (i.e. is rotation matrix and satisfies projection constraints)
static bool is_valid(const RelativePoseProblemInstance &instance, const Eigen::Matrix3d &H, double tol);
};
struct UnknownFocalValidator {
// Computes the distance to the ground truth pose
static double compute_pose_error(const AbsolutePoseProblemInstance &instance, const CameraPose &pose, double focal);
// Checks if the solution is valid (i.e. is rotation matrix and satisfies projection constraints)
static bool is_valid(const AbsolutePoseProblemInstance &instance, const CameraPose &pose, double focal, double tol);
};
struct RadialPoseValidator {
// Computes the distance to the ground truth pose
static double compute_pose_error(const AbsolutePoseProblemInstance &instance, const CameraPose &pose, double scale);
// Checks if the solution is valid (i.e. is rotation matrix and satisfies projection constraints)
static bool is_valid(const AbsolutePoseProblemInstance &instance, const CameraPose &pose, double scale, double tol);
};
struct ProblemOptions {
double min_depth_ = 0.1;
double max_depth_ = 10.0;
double camera_fov_ = 70.0;
int n_point_point_ = 0;
int n_point_line_ = 0;
int n_line_point_ = 0;
int n_line_line_ = 0;
bool upright_ = false;
bool planar_ = false;
bool generalized_ = false;
bool generalized_duplicate_obs_ = false;
int generalized_first_cam_obs_ = 0; // how many of the points should from the first camera (relpose only)
bool unknown_scale_ = false;
bool unknown_focal_ = false;
bool radial_lines_ = false;
double min_scale_ = 0.1;
double max_scale_ = 10.0;
double min_focal_ = 100.0;
double max_focal_ = 1000.0;
std::string additional_name_ = "";
};
void set_random_pose(CameraPose &pose, bool upright, bool planar);
void generate_abspose_problems(int n_problems, std::vector<AbsolutePoseProblemInstance> *problem_instances,
const ProblemOptions &options);
void generate_relpose_problems(int n_problems, std::vector<RelativePoseProblemInstance> *problem_instances,
const ProblemOptions &options);
void generate_homography_problems(int n_problems, std::vector<RelativePoseProblemInstance> *problem_instances,
const ProblemOptions &options);
}; // namespace poselib
|