Apollo 10.0
自动驾驶开放平台
camera_tracking_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 *****************************************************************************/
16
18
19#include "modules/perception/camera_tracking/proto/camera_tracking_component.pb.h"
20
21#include "cyber/common/file.h"
23#include "cyber/time/clock.h"
24
25namespace apollo {
26namespace perception {
27namespace camera {
28
30
32 CameraTrackingComponentConfig camera_tracking_component_config;
33 if (!GetProtoConfig(&camera_tracking_component_config)) {
34 return false;
35 }
36 AINFO << "Camera Tracking Component config: "
37 << camera_tracking_component_config.DebugString();
38 output_channel_name_ = camera_tracking_component_config.output_channel_name();
39 writer_ =
40 node_->CreateWriter<onboard::SensorFrameMessage>(output_channel_name_);
41
42 sensor_manager_ = algorithm::SensorManager::Instance();
43
44 PluginParam plugin_param = camera_tracking_component_config.plugin_param();
45 std::string tracker_name = plugin_param.name();
46 camera_obstacle_tracker_.reset(
47 BaseObstacleTrackerRegisterer::GetInstanceByName(tracker_name));
48 if (nullptr == camera_obstacle_tracker_) {
49 AERROR << "Failed to get camera obstacle tracker instance.";
50 return false;
51 }
52
53 ObstacleTrackerInitOptions tracker_init_options;
54 tracker_init_options.config_path = plugin_param.config_path();
55 tracker_init_options.config_file = plugin_param.config_file();
56 tracker_init_options.image_width =
57 camera_tracking_component_config.image_width();
58 tracker_init_options.image_height =
59 camera_tracking_component_config.image_height();
60 tracker_init_options.gpu_id = camera_tracking_component_config.gpu_id();
61 if (!camera_obstacle_tracker_->Init(tracker_init_options)) {
62 AERROR << "Failed to init camera obstacle tracker.";
63 return false;
64 }
65 return true;
66}
67
69 const std::shared_ptr<onboard::CameraFrame>& message) {
71 AINFO << std::setprecision(16)
72 << "Enter Tracking component, message timestamp: " << message->timestamp
73 << " current timestamp: " << Clock::NowInSeconds();
74
75 auto out_message = std::make_shared<onboard::SensorFrameMessage>();
76 bool status = InternalProc(message, out_message);
77
78 if (status) {
79 writer_->Write(out_message);
80 AINFO << "Send camera tracking output message.";
81 }
82 return status;
83}
84
85bool CameraTrackingComponent::InternalProc(
86 const std::shared_ptr<const onboard::CameraFrame>& in_message,
87 std::shared_ptr<onboard::SensorFrameMessage> out_message) {
88 out_message->timestamp_ = in_message->timestamp;
89 std::shared_ptr<CameraTrackingFrame> tracking_frame;
90 tracking_frame.reset(new CameraTrackingFrame);
91 tracking_frame->frame_id = in_message->frame_id;
92 tracking_frame->timestamp = in_message->timestamp;
93 tracking_frame->data_provider = in_message->data_provider;
94 tracking_frame->detected_objects = in_message->detected_objects;
95 tracking_frame->feature_blob = in_message->feature_blob;
96 tracking_frame->track_feature_blob.reset(new base::Blob<float>());
97 tracking_frame->project_matrix.setIdentity();
98 tracking_frame->camera2world_pose = in_message->camera2world_pose;
99
100 // Tracking
101 PERF_BLOCK("camera_tracking")
102 bool res = camera_obstacle_tracker_->Process(tracking_frame);
104
105 if (!res) {
106 out_message->error_code_ =
108 AERROR << "Camera tracking process error!";
109 return false;
110 }
111
112 base::SensorInfo sensor_info;
113 std::string camera_name = in_message->data_provider->sensor_name();
114 if (!(sensor_manager_->GetSensorInfo(camera_name, &sensor_info))) {
115 AERROR << "Failed to get sensor info, sensor name: " << camera_name;
116 return false;
117 }
118
119 auto& frame = out_message->frame_;
120 frame = base::FramePool::Instance().Get();
121 // todo(wxt): check if sensor_info needed
122 // frame->sensor_info = lidar_frame->sensor_info;
123 frame->sensor_info = sensor_info;
124 frame->timestamp = in_message->timestamp;
125 frame->objects = tracking_frame->tracked_objects;
126 // todo(wxt): check if sensor2world_pose needed
127 frame->sensor2world_pose = tracking_frame->camera2world_pose;
128 return true;
129}
130
131} // namespace camera
132} // namespace perception
133} // namespace apollo
a singleton clock that can be used to get the current timestamp.
Definition clock.h:39
static double NowInSeconds()
gets the current time in second.
Definition clock.cc:56
bool GetProtoConfig(T *config) const
std::shared_ptr< Node > node_
bool Process(const std::shared_ptr< onboard::CameraFrame > &msg0, const std::shared_ptr< NullType > &msg1, const std::shared_ptr< NullType > &msg2, const std::shared_ptr< NullType > &msg3)
Definition component.h:505
bool GetSensorInfo(const std::string &name, apollo::perception::base::SensorInfo *sensor_info) const
A wrapper around SyncedMemory holders serving as the basic computational unit for images,...
Definition blob.h:88
bool Proc(const std::shared_ptr< onboard::CameraFrame > &message) override
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
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