Calibration Library 1.0.0
A C++ library for camera calibration and vision-related geometric transformations
Loading...
Searching...
No Matches
planar_utils.cpp
Go to the documentation of this file.
2
3#include <algorithm>
4
6
8
10 const std::string& camera_id) {
11 const auto it =
12 std::find_if(cfg.cameras.begin(), cfg.cameras.end(),
13 [&](const CameraConfig& cam) { return cam.camera_id == camera_id; });
14 return it == cfg.cameras.end() ? nullptr : &(*it);
15}
16
17namespace {
18
19std::unordered_map<std::string, const PlanarImageDetections*> build_point_lookup(
21 std::unordered_map<std::string, const PlanarImageDetections*> lookup;
22 for (const auto& image : detections.images) {
23 lookup.emplace(image.file, &image);
24 }
25 return lookup;
26}
27
28} // namespace
29
30std::unordered_map<std::string, SensorDetectionsIndex> build_sensor_index(
31 const std::vector<PlanarDetections>& detections) {
32 std::unordered_map<std::string, SensorDetectionsIndex> index;
33 for (const auto& det : detections) {
34 if (det.sensor_id.empty()) {
35 continue;
36 }
38 entry.detections = &det;
39 entry.image_lookup = build_point_lookup(det);
40 index.emplace(det.sensor_id, std::move(entry));
41 }
42 return index;
43}
44
46 PlanarView view(detections.points.size());
47 std::transform(detections.points.begin(), detections.points.end(), view.begin(),
48 [&](const auto& point) -> PlanarObservation {
49 return {{point.local_x, point.local_y}, {point.x, point.y}};
50 });
51 return view;
52}
53
54Eigen::Isometry3d average_isometries(const std::vector<Eigen::Isometry3d>& poses) {
55 if (poses.empty()) {
56 return Eigen::Isometry3d::Identity();
57 }
58 Eigen::Vector3d translation = Eigen::Vector3d::Zero();
59 Eigen::Quaterniond q_sum(0.0, 0.0, 0.0, 0.0);
60 for (const auto& pose : poses) {
61 translation += pose.translation();
62 Eigen::Quaterniond q(pose.linear());
63 if (q_sum.coeffs().dot(q.coeffs()) < 0.0) {
64 q.coeffs() *= -1.0;
65 }
66 q_sum.coeffs() += q.coeffs();
67 }
68 translation /= static_cast<double>(poses.size());
69 q_sum.normalize();
70 Eigen::Isometry3d avg = Eigen::Isometry3d::Identity();
71 avg.linear() = q_sum.toRotationMatrix();
72 avg.translation() = translation;
73 return avg;
74}
75
77 const std::string& rig_id) {
78 const auto it = std::find_if(cfg.rigs.begin(), cfg.rigs.end(),
79 [&](const HandEyeRigConfig& rig) { return rig.rig_id == rig_id; });
80 return it == cfg.rigs.end() ? nullptr : &(*it);
81}
82
83} // namespace calib::pipeline::detail
std::vector< Eigen::Isometry3d > cam
PlanarDetections detections
Definition loaders.cpp:15
const HandEyeRigConfig * find_handeye_rig(const HandEyePipelineConfig &cfg, const std::string &rig_id)
auto make_planar_view(const PlanarImageDetections &detections) -> PlanarView
auto find_camera_config(const IntrinsicCalibrationConfig &cfg, const std::string &camera_id) -> const CameraConfig *
auto build_sensor_index(const std::vector< PlanarDetections > &detections) -> std::unordered_map< std::string, SensorDetectionsIndex >
Eigen::Isometry3d average_isometries(const std::vector< Eigen::Isometry3d > &poses)
Definition se3_utils.h:75
std::vector< PlanarObservation > PlanarView
Definition planarpose.h:26
std::vector< HandEyeRigConfig > rigs
Definition handeye.h:53
Hand-eye rig definition used to configure the calibration stage.
Definition handeye.h:44
std::vector< CameraConfig > cameras
Definition intrinsics.h:44
std::unordered_map< std::string, const PlanarImageDetections * > image_lookup