Apollo 11.0
自动驾驶开放平台
camera_location_refinement_component.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2023 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 <utility>
19
20#include "cyber/common/file.h"
24
25namespace apollo {
26namespace perception {
27namespace camera {
28
29void CameraLocationRefinementComponent::InitCalibrationService(
30 const CameraLocationRefinement& location_refinement_param) {
32 algorithm::SensorManager::Instance()->GetUndistortCameraModel(
33 location_refinement_param.camera_name());
34 ACHECK(model) << "Can't find " << location_refinement_param.camera_name()
35 << " in data/conf/sensor_meta.pb.txt";
36 auto pinhole = static_cast<base::PinholeCameraModel*>(model.get());
37 name_intrinsic_map_.insert(std::pair<std::string, Eigen::Matrix3f>(
38 location_refinement_param.camera_name(),
39 pinhole->get_intrinsic_params()));
40
41 auto calibration_service_param =
42 location_refinement_param.calibration_service_param();
43 CalibrationServiceInitOptions calibration_service_init_options;
44 calibration_service_init_options.calibrator_working_sensor_name =
45 location_refinement_param.camera_name();
46 calibration_service_init_options.name_intrinsic_map = name_intrinsic_map_;
47 calibration_service_init_options.calibrator_method =
48 calibration_service_param.calibrator_method();
49 calibration_service_init_options.image_height =
50 static_cast<int>(model->get_height());
51 calibration_service_init_options.image_width =
52 static_cast<int>(model->get_width());
53 calibration_service_.reset(
54 BaseCalibrationServiceRegisterer::GetInstanceByName(
55 calibration_service_param.plugin_param().name()));
56 ACHECK(calibration_service_ != nullptr);
57 ACHECK(calibration_service_->Init(calibration_service_init_options))
58 << "Failed to init: " << calibration_service_param.plugin_param().name();
59 AINFO << "calibration_service: " << calibration_service_->Name();
60}
61
62void CameraLocationRefinementComponent::InitPostprocessor(
63 const CameraLocationRefinement& location_refinement_param) {
64 InitCalibrationService(location_refinement_param);
65
66 PostprocessorInitOptions postprocessor_init_options;
67 auto plugin_param =
68 location_refinement_param.postprocessor_param().plugin_param();
69 postprocessor_init_options.config_path = plugin_param.config_path();
70 postprocessor_init_options.config_file = plugin_param.config_file();
71 postprocessor_init_options.calibration_service = calibration_service_;
72 postprocessor_.reset(
73 BasePostprocessorRegisterer::GetInstanceByName(plugin_param.name()));
74 ACHECK(postprocessor_ != nullptr);
75 ACHECK(postprocessor_->Init(postprocessor_init_options))
76 << "Failed to init: " << plugin_param.name();
77}
78
79void CameraLocationRefinementComponent::SetCameraHeightAndPitch(
80 const std::map<std::string, float>& name_camera_ground_height_map,
81 const std::map<std::string, float>& name_camera_pitch_angle_diff_map,
82 const float& pitch_angle_calibrator_working_sensor) {
83 if (calibration_service_ == nullptr) {
84 AERROR << "Calibraion service is not available";
85 return;
86 }
87 calibration_service_->SetCameraHeightAndPitch(
88 name_camera_ground_height_map, name_camera_pitch_angle_diff_map,
89 pitch_angle_calibrator_working_sensor);
90}
91
93 CameraLocationRefinement location_refinement_param;
94 if (!GetProtoConfig(&location_refinement_param)) {
95 AERROR << "Load camera detection 3d component config failed!";
96 return false;
97 }
98
99 InitPostprocessor(location_refinement_param);
100
101 // todo(daohu527): need complete
102 // SetCameraHeightAndPitch();
103
104 writer_ = node_->CreateWriter<onboard::CameraFrame>(
105 location_refinement_param.channel().output_obstacles_channel_name());
106 return true;
107}
108
110 const std::shared_ptr<onboard::CameraFrame>& msg) {
112 PostprocessorOptions obstacle_postprocessor_options;
113 obstacle_postprocessor_options.do_refinement_with_calibration_service =
114 calibration_service_ != nullptr;
115
116 std::shared_ptr<onboard::CameraFrame> out_message(new (std::nothrow)
118 out_message->frame_id = msg->frame_id;
119 out_message->timestamp = msg->timestamp;
120 out_message->data_provider = msg->data_provider;
121 out_message->detected_objects = msg->detected_objects;
122 out_message->feature_blob = msg->feature_blob;
123 out_message->camera_k_matrix = msg->camera_k_matrix;
124 out_message->camera2world_pose = msg->camera2world_pose;
125
126 // calibration_service_->Update(&frame);
127
128 PERF_BLOCK("location_refinement_postprocessor")
129 if (!postprocessor_->Process(obstacle_postprocessor_options,
130 out_message.get())) {
131 AERROR << "Failed to post process obstacles.";
132 return false;
133 }
135
136 writer_->Write(out_message);
137 return true;
138}
139
140} // namespace camera
141} // namespace perception
142} // namespace apollo
bool GetProtoConfig(T *config) const
std::shared_ptr< Node > node_
bool Proc(const std::shared_ptr< onboard::CameraFrame > &msg) override
Process of camera location refinement component.
bool Init() override
Init for camera location refinement component.
#define ACHECK(cond)
Definition log.h:80
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
std::shared_ptr< BaseCameraModel > BaseCameraModelPtr
Definition camera.h:75
class register implement
Definition arena_queue.h:37
#define PERF_FUNCTION(...)
Definition profiler.h:54
#define PERF_BLOCK_END
Definition profiler.h:53
#define PERF_BLOCK(...)
Definition profiler.h:52