Apollo 11.0
自动驾驶开放平台
camera_homography.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
17
18#include <limits>
19
20namespace apollo {
21namespace perception {
22namespace algorithm {
23
24// @brief: find the corresponding 2D point in camera2, given 2D point in
25// camera1. assume the two cameras have the same optical center.
26// notice camera1_intrinsic_inverse is inverse version
27bool PointCamera1ToCamera2(const Eigen::Vector2d& point,
28 const Eigen::Matrix3d& camera1_intrinsic_inverse,
29 const Eigen::Matrix3d& camera2_intrinsic,
30 const Eigen::Matrix3d& trans_camera1_to_camera2,
31 Eigen::Vector2d* point_out) {
32 Eigen::Vector3d pt = point.homogeneous();
33 Eigen::Vector3d camera2_3d =
34 static_cast<Eigen::Matrix<double, 3, 1, 0, 3, 1>>(
35 trans_camera1_to_camera2 * camera1_intrinsic_inverse * pt);
36
37 double z = camera2_3d(2);
38 if (fabs(z) > 1e-6) {
39 *point_out = (camera2_intrinsic * camera2_3d / z).head(2);
40 return true;
41 }
42 return false;
43}
44
45// @brief: estimate whether two cameras have field overlap.
47 const base::PinholeCameraModel& to_camera,
48 const Eigen::Matrix4d& extrinsic,
49 Eigen::Vector2d* up_left,
50 Eigen::Vector2d* low_right) {
51 size_t f_width = from_camera.get_width();
52 size_t f_height = from_camera.get_height();
53 size_t to_width = to_camera.get_width();
54 size_t to_height = to_camera.get_height();
55 Eigen::Matrix3d f2t_rotation = extrinsic.topLeftCorner(3, 3);
56 Eigen::Matrix<double, 4, 2> points;
57 points << 0.0, 0.0, static_cast<double>(f_width), 0.0,
58 static_cast<double>(f_width), static_cast<double>(f_height), 0.0,
59 static_cast<double>(f_height);
60 Eigen::Vector2d pt_min(std::numeric_limits<double>::max(),
61 std::numeric_limits<double>::max());
62 Eigen::Vector2d pt_max(-std::numeric_limits<double>::max(),
63 -std::numeric_limits<double>::max());
64 Eigen::Matrix3d from_camera_intrinsic_inverse =
65 from_camera.get_intrinsic_params().cast<double>().inverse();
66 for (int i = 0; i < 4; ++i) {
67 Eigen::Vector2d point_out;
68 bool status = PointCamera1ToCamera2(
69 points.block<1, 2>(i, 0), from_camera_intrinsic_inverse,
70 to_camera.get_intrinsic_params().cast<double>(), f2t_rotation,
71 &point_out);
72 if (status) {
73 pt_min = pt_min.cwiseMin(point_out);
74 pt_max = pt_max.cwiseMax(point_out);
75 }
76 }
77 (*up_left) = pt_min.cwiseMax(Eigen::Vector2d(0, 0));
78 (*low_right) = pt_max.cwiseMin(Eigen::Vector2d(to_width, to_height));
79 if ((up_left->array() < low_right->array()).all()) {
80 return true;
81 }
82 return false;
83}
84
85} // namespace algorithm
86} // namespace perception
87} // namespace apollo
Eigen::Matrix3f get_intrinsic_params() const
Definition camera.h:62
bool IsCamerasFieldOverlap(const base::PinholeCameraModel &from_camera, const base::PinholeCameraModel &to_camera, const Eigen::Matrix4d &extrinsic, Eigen::Vector2d *up_left, Eigen::Vector2d *low_right)
bool PointCamera1ToCamera2(const Eigen::Vector2d &point, const Eigen::Matrix3d &camera1_intrinsic_inverse, const Eigen::Matrix3d &camera2_intrinsic, const Eigen::Matrix3d &trans_camera1_to_camera2, Eigen::Vector2d *point_out)
class register implement
Definition arena_queue.h:37