Apollo 11.0
自动驾驶开放平台
omnidirectional_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 <limits>
19
20#include "cyber/common/log.h"
21
24
25namespace apollo {
26namespace perception {
27namespace base {
28
30 const Eigen::Vector3f& point3d) {
31 if (std::isgreater(point3d[2], 0.f)) {
32 AERROR << "The input point (" << point3d
33 << ") should be in front of the camera";
34 }
35
36 // rotate:
37 // [0 1 0;
38 // 1 0 0;
39 // 0 0 -1];
40 double x[3] = {point3d(1), point3d(0), -point3d(2)};
41 const double norm = sqrt(x[0] * x[0] + x[1] * x[1]);
42
43 Eigen::Vector2f projection;
44 if (norm < std::numeric_limits<double>::epsilon()) {
45 projection(0) = center_[1];
46 projection(1) = center_[0];
47 return projection;
48 }
49
50 const double theta = atan(x[2] / norm);
51 const double rho = world2cam_(theta);
52
53 const float u = static_cast<float>(x[0] / norm * rho);
54 const float v = static_cast<float>(x[1] / norm * rho);
55 projection(1) = affine_[0] * u + affine_[1] * v + center_[0];
56 projection(0) = affine_[2] * u + v + center_[1];
57 return projection;
58}
59
60std::shared_ptr<BaseCameraModel>
62 std::shared_ptr<PinholeCameraModel> camera_model(new PinholeCameraModel());
63 camera_model->set_width(width_);
64 camera_model->set_height(height_);
65 camera_model->set_intrinsic_params(intrinsic_params_);
66
67 return std::dynamic_pointer_cast<BaseCameraModel>(camera_model);
68}
69
71 size_t width, size_t height, const Eigen::VectorXf& params) {
72 if (params.size() < 9) {
73 AINFO << "Missing cam2world and world2cam model.";
74 return false;
75 }
76
77 uint32_t cam2world_order = uint32_t(params(8));
78 AINFO << "cam2world order: " << cam2world_order << ", size: " << params.size()
79 << std::endl;
80
81 if (params.size() < 9 + cam2world_order + 1) {
82 AINFO << "Incomplete cam2world model or missing world2cam model.";
83 return false;
84 }
85
86 uint32_t world2cam_order = uint32_t(params(9 + cam2world_order));
87 AINFO << "world2cam order: " << world2cam_order << ", size: " << params.size()
88 << std::endl;
89
90 if (params.size() < 9 + cam2world_order + 1 + world2cam_order) {
91 AINFO << "Incomplete world2cam model.";
92 return false;
93 }
94
95 width_ = width;
96 height_ = height;
97
98 center_[0] = params(0);
99 center_[1] = params(1);
100
101 affine_[0] = params(2);
102 affine_[1] = params(3);
103 affine_[2] = params(4);
104
105 intrinsic_params_ = Eigen::Matrix3f::Identity();
106 intrinsic_params_(0, 0) = params(5);
107 intrinsic_params_(1, 1) = params(5);
108 intrinsic_params_(0, 2) = params(6);
109 intrinsic_params_(1, 2) = params(7);
110
111 for (size_t i = 0; i < cam2world_order; ++i) {
112 cam2world_[static_cast<uint32_t>(i)] = static_cast<double>(params(9 + i));
113 }
114
115 for (size_t i = 0; i < world2cam_order; ++i) {
116 world2cam_[static_cast<uint32_t>(i)] =
117 static_cast<double>(params(10 + cam2world_order + i));
118 }
119
120 return true;
121}
122
123} // namespace base
124} // namespace perception
125} // namespace apollo
std::shared_ptr< BaseCameraModel > get_camera_model() override
Eigen::Vector2f Project(const Eigen::Vector3f &point3d) override
bool set_params(size_t width, size_t height, const Eigen::VectorXf &params) override
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
class register implement
Definition arena_queue.h:37