Apollo 10.0
自动驾驶开放平台
distortion_model.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 "cyber/common/log.h"
19
20namespace apollo {
21namespace perception {
22namespace base {
23
25 const Eigen::Vector3f& point3d) {
26 if (std::isless(point3d[2], 0.f)) {
27 AERROR << "The input point (" << point3d
28 << ") should be in front of the camera";
29 }
30 // radial distortion coefficients
31 const float k1 = distort_params_[0];
32 const float k2 = distort_params_[1];
33 const float k3 = distort_params_[4];
34 // tangential distortion coefficients
35 const float p1 = distort_params_[2];
36 const float p2 = distort_params_[3];
37 const float k4 = distort_params_[5];
38 const float k5 = distort_params_[6];
39 const float k6 = distort_params_[7];
40
41 Eigen::Vector2f pt2d_img;
42 // normalized
43 const Eigen::Vector2f pt_normalized(point3d[0] / point3d[2],
44 point3d[1] / point3d[2]);
45 const float x_n = pt_normalized[0];
46 const float y_n = pt_normalized[1];
47 const float x_mul_x = x_n * x_n;
48 const float y_mul_y = y_n * y_n;
49 const float x_mul_y = x_n * y_n;
50 const float r_squared = x_mul_x + y_mul_y;
51 const float r_to_the_4th = r_squared * r_squared;
52 const float r_to_the_6th = r_squared * r_to_the_4th;
53
54 // radial distortion
55 pt2d_img = pt_normalized *
56 (1 + k1 * r_squared + k2 * r_to_the_4th + k3 * r_to_the_6th) /
57 (1 + k4 * r_squared + k5 * r_to_the_4th + k6 * r_to_the_6th);
58
59 // tangential distortion
60 pt2d_img[0] += 2 * p1 * x_mul_y + p2 * (r_squared + 2 * x_mul_x);
61 pt2d_img[1] += p1 * (r_squared + 2 * y_mul_y) + 2 * p2 * x_mul_y;
62
63 // transform to image coordinates
64 const float fx = intrinsic_params_(0, 0);
65 const float fy = intrinsic_params_(1, 1);
66 const float cx = intrinsic_params_(0, 2);
67 const float cy = intrinsic_params_(1, 2);
68 pt2d_img[0] = fx * pt2d_img[0] + cx;
69 pt2d_img[1] = fy * pt2d_img[1] + cy;
70
71 return pt2d_img;
72}
73
74std::shared_ptr<BaseCameraModel>
76 std::shared_ptr<PinholeCameraModel> camera_model(new PinholeCameraModel());
77 camera_model->set_width(width_);
78 camera_model->set_height(height_);
79 camera_model->set_intrinsic_params(intrinsic_params_);
80
81 return std::dynamic_pointer_cast<BaseCameraModel>(camera_model);
82}
83
84bool BrownCameraDistortionModel::set_params(size_t width, size_t height,
85 const Eigen::VectorXf& params) {
86 // Brown distortion model
87 if (params.size() == 14) {
88 width_ = width;
89 height_ = height;
90 intrinsic_params_(0, 0) = params(0);
91 intrinsic_params_(0, 1) = params(1);
92 intrinsic_params_(0, 2) = params(2);
93 intrinsic_params_(1, 0) = params(3);
94 intrinsic_params_(1, 1) = params(4);
95 intrinsic_params_(1, 2) = params(5);
96 intrinsic_params_(2, 0) = params(6);
97 intrinsic_params_(2, 1) = params(7);
98 intrinsic_params_(2, 2) = params(8);
99
100 distort_params_[0] = params[9];
101 distort_params_[1] = params[10];
102 distort_params_[2] = params[11];
103 distort_params_[3] = params[12];
104 distort_params_[4] = params[13];
105 return true;
106 } else if (params.size() == 17) {
107 width_ = width;
108 height_ = height;
109 intrinsic_params_(0, 0) = params(0);
110 intrinsic_params_(0, 1) = params(1);
111 intrinsic_params_(0, 2) = params(2);
112 intrinsic_params_(1, 0) = params(3);
113 intrinsic_params_(1, 1) = params(4);
114 intrinsic_params_(1, 2) = params(5);
115 intrinsic_params_(2, 0) = params(6);
116 intrinsic_params_(2, 1) = params(7);
117 intrinsic_params_(2, 2) = params(8);
118
119 distort_params_[0] = params[9];
120 distort_params_[1] = params[10];
121 distort_params_[2] = params[11];
122 distort_params_[3] = params[12];
123 distort_params_[4] = params[13];
124 distort_params_[5] = params[14];
125 distort_params_[6] = params[15];
126 distort_params_[7] = params[16];
127 return true;
128 }
129 return false;
130}
131
132} // namespace base
133} // namespace perception
134} // namespace apollo
Eigen::Vector2f Project(const Eigen::Vector3f &point3d) override
std::shared_ptr< BaseCameraModel > get_camera_model() override
bool set_params(size_t width, size_t height, const Eigen::VectorXf &params) override
#define AERROR
Definition log.h:44
class register implement
Definition arena_queue.h:37