27bool CameraDetectionMultiStageComponent::InitObstacleDetector(
28 const CameraDetectionMultiStage& detection_param) {
29 ObstacleDetectorInitOptions init_options;
31 auto plugin_param = detection_param.plugin_param();
32 init_options.config_path = plugin_param.config_path();
33 init_options.config_file = plugin_param.config_file();
34 init_options.gpu_id = detection_param.gpu_id();
35 timestamp_offset_ = detection_param.timestamp_offset();
38 std::string camera_name = detection_param.camera_name();
40 algorithm::SensorManager::Instance()->GetUndistortCameraModel(
42 ACHECK(model) <<
"Can't find " << camera_name
43 <<
" in data/conf/sensor_meta.pb.txt";
44 auto pinhole =
static_cast<base::PinholeCameraModel*
>(model.get());
45 init_options.intrinsic = pinhole->get_intrinsic_params();
46 camera_k_matrix_ = init_options.intrinsic;
47 init_options.image_height = model->get_height();
48 init_options.image_width = model->get_width();
49 image_height_ = model->get_height();
50 image_width_ = model->get_width();
54 BaseObstacleDetectorRegisterer::GetInstanceByName(plugin_param.name()));
55 detector_->Init(init_options);
59bool CameraDetectionMultiStageComponent::InitCameraFrame(
60 const CameraDetectionMultiStage& detection_param) {
61 DataProvider::InitOptions init_options;
62 init_options.image_height = image_height_;
63 init_options.image_width = image_width_;
64 init_options.do_undistortion = detection_param.enable_undistortion();
65 init_options.sensor_name = detection_param.camera_name();
66 init_options.device_id = detection_param.gpu_id();
67 AINFO <<
"init_options.device_id: " << init_options.device_id
68 <<
" camera_name: " << init_options.sensor_name;
70 data_provider_ = std::make_shared<camera::DataProvider>();
71 data_provider_->Init(init_options);
76bool CameraDetectionMultiStageComponent::InitTransformWrapper(
77 const CameraDetectionMultiStage& detection_param) {
78 trans_wrapper_.reset(
new onboard::TransformWrapper());
80 trans_wrapper_->Init(detection_param.camera_name());
87 AERROR <<
"Load camera detection 3d component config failed!";
91 InitObstacleDetector(detection_param);
93 InitCameraFrame(detection_param);
95 InitTransformWrapper(detection_param);
103 const std::shared_ptr<apollo::drivers::Image>& msg) {
105 std::shared_ptr<onboard::CameraFrame> out_message(
new (std::nothrow)
107 bool status = InternalProc(msg, out_message);
109 writer_->Write(out_message);
110 AINFO <<
"Send camera detection 2d output message.";
116bool CameraDetectionMultiStageComponent::InternalProc(
117 const std::shared_ptr<apollo::drivers::Image>& msg,
118 const std::shared_ptr<onboard::CameraFrame>& out_message) {
119 out_message->data_provider = data_provider_;
122 out_message->data_provider->FillImageData(
123 image_height_, image_width_,
124 reinterpret_cast<const uint8_t*
>(msg->data().data()), msg->encoding());
126 out_message->camera_k_matrix = camera_k_matrix_;
128 const double msg_timestamp = msg->measurement_time() + timestamp_offset_;
129 out_message->timestamp = msg_timestamp;
132 Eigen::Affine3d camera2world;
133 if (!trans_wrapper_->GetSensor2worldTrans(msg_timestamp, &camera2world)) {
134 const std::string err_str =
135 absl::StrCat(
"failed to get camera to world pose, ts: ", msg_timestamp,
136 " frame_id: ", msg->frame_id());
141 out_message->frame_id = frame_id_;
144 out_message->camera2world_pose = camera2world;
148 detector_->Detect(out_message.get());
bool GetProtoConfig(T *config) const
std::shared_ptr< Node > node_
bool Proc(const std::shared_ptr< drivers::Image > &msg) override
Process of camera detection 2d compoment
bool Init() override
Init for amera detection 2d compoment
std::shared_ptr< BaseCameraModel > BaseCameraModelPtr
#define PERF_FUNCTION(...)
optional string output_obstacles_channel_name