Skip to content

Commit

Permalink
Perception: Support multiple cameras in visualizer
Browse files Browse the repository at this point in the history
Perception: fixed copy to reference and more formats based on the review
  • Loading branch information
techoe authored and jinghaomiao committed Sep 20, 2019
1 parent 2276118 commit 1f4be95
Show file tree
Hide file tree
Showing 9 changed files with 414 additions and 352 deletions.
41 changes: 21 additions & 20 deletions modules/perception/camera/app/lane_camera_perception.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,37 +69,38 @@ void LaneCameraPerception::InitLane(
const std::string &work_root, base::BaseCameraModelPtr &model,
const app::PerceptionParam &perception_param) {
// Init lane
CHECK(perception_param.has_lane_param()) << "Failed to include lane_param";
{
CHECK_GT(perception_param.lane_param_size(), 0)
<< "Failed to include lane_param";
for (int i = 0; i < perception_param.lane_param_size(); ++i) {
// Initialize lane detector
auto lane_param = perception_param.lane_param();
const auto &lane_param = perception_param.lane_param(i);
CHECK(lane_param.has_lane_detector_param())
<< "Failed to include lane_detector_param";
<< "Failed to include lane_detector_param.";
LaneDetectorInitOptions lane_detector_init_options;
auto lane_detector_param = lane_param.lane_detector_param();
auto lane_detector_plugin_param = lane_detector_param.plugin_param();
const auto &lane_detector_param = lane_param.lane_detector_param();
const auto &lane_detector_plugin_param = lane_detector_param.plugin_param();
lane_detector_init_options.conf_file =
lane_detector_plugin_param.config_file();
lane_detector_init_options.root_dir =
GetAbsolutePath(work_root, lane_detector_plugin_param.root_dir());
lane_detector_init_options.gpu_id = perception_param_.gpu_id();
model = common::SensorManager::Instance()->GetUndistortCameraModel(
lane_detector_param.camera_name());
auto pinhole = static_cast<base::PinholeCameraModel *>(model.get());
name_intrinsic_map_.insert(std::pair<std::string, Eigen::Matrix3f>(
lane_detector_param.camera_name(), pinhole->get_intrinsic_params()));
lane_detector_init_options.gpu_id = perception_param.gpu_id();
lane_detector_init_options.base_camera_model = model;
AINFO << "lane detector name: " << lane_detector_plugin_param.name();
AINFO << "lane_detector_name: " << lane_detector_plugin_param.name();
lane_detector_.reset(BaseLaneDetectorRegisterer::GetInstanceByName(
lane_detector_plugin_param.name()));
CHECK(lane_detector_ != nullptr);
CHECK(lane_detector_->Init(lane_detector_init_options))
<< "Failed to init " << lane_detector_plugin_param.name();
<< "Failed to init: " << lane_detector_plugin_param.name();
AINFO << "Detector: " << lane_detector_->Name();

// initialize lane postprocessor
auto lane_postprocessor_param =
perception_param_.lane_param().lane_postprocessor_param();
// Initialize lane postprocessor
const auto &lane_postprocessor_param =
lane_param.lane_postprocessor_param();
LanePostprocessorInitOptions postprocessor_init_options;
postprocessor_init_options.detect_config_root =
GetAbsolutePath(work_root, lane_detector_plugin_param.root_dir());
Expand All @@ -114,21 +115,21 @@ void LaneCameraPerception::InitLane(
lane_postprocessor_param.name()));
CHECK(lane_postprocessor_ != nullptr);
CHECK(lane_postprocessor_->Init(postprocessor_init_options))
<< "Failed to init " << lane_postprocessor_param.name();
AINFO << "Lane postprocessor: " << lane_postprocessor_->Name();
<< "Failed to init: " << lane_postprocessor_param.name();
AINFO << "lane_postprocessor: " << lane_postprocessor_->Name();

// Init output file folder
if (perception_param_.has_debug_param() &&
perception_param_.debug_param().has_lane_out_dir()) {
if (perception_param.has_debug_param() &&
perception_param.debug_param().has_lane_out_dir()) {
write_out_lane_file_ = true;
out_lane_dir_ = perception_param_.debug_param().lane_out_dir();
out_lane_dir_ = perception_param.debug_param().lane_out_dir();
EnsureDirectory(out_lane_dir_);
}

if (perception_param_.has_debug_param() &&
perception_param_.debug_param().has_calibration_out_dir()) {
if (perception_param.has_debug_param() &&
perception_param.debug_param().has_calibration_out_dir()) {
write_out_calib_file_ = true;
out_calib_dir_ = perception_param_.debug_param().calibration_out_dir();
out_calib_dir_ = perception_param.debug_param().calibration_out_dir();
EnsureDirectory(out_calib_dir_);
}
}
Expand Down
97 changes: 44 additions & 53 deletions modules/perception/camera/app/obstacle_camera_perception.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ bool ObstacleCameraPerception::Init(
GetAbsolutePath(options.root_dir, options.conf_file);
config_file = GetAbsolutePath(work_root, config_file);
CHECK(cyber::common::GetProtoFromFile(config_file, &perception_param_))
<< "Read config failed: ";
<< "Read config failed: " << config_file;
CHECK(inference::CudaUtil::set_device_id(perception_param_.gpu_id()));

// Init detector
Expand Down Expand Up @@ -183,21 +183,21 @@ void ObstacleCameraPerception::InitLane(
const std::string &work_root,
const app::PerceptionParam &perception_param) {
// Init lane
CHECK(perception_param.has_lane_param()) << "Failed to include lane_param.";
{
CHECK_GT(perception_param.lane_param_size(), 0)
<< "Failed to include lane_param";
for (int i = 0; i < perception_param.lane_param_size(); ++i) {
// Initialize lane detector
auto lane_param = perception_param.lane_param();
const auto &lane_param = perception_param.lane_param(i);
CHECK(lane_param.has_lane_detector_param())
<< "Failed to include lane_detector_param.";
LaneDetectorInitOptions lane_detector_init_options;
auto lane_detector_param =
perception_param_.lane_param().lane_detector_param();
auto lane_detector_plugin_param = lane_detector_param.plugin_param();
const auto &lane_detector_param = lane_param.lane_detector_param();
const auto &lane_detector_plugin_param = lane_detector_param.plugin_param();
lane_detector_init_options.conf_file =
lane_detector_plugin_param.config_file();
lane_detector_init_options.root_dir =
GetAbsolutePath(work_root, lane_detector_plugin_param.root_dir());
lane_detector_init_options.gpu_id = perception_param_.gpu_id();
lane_detector_init_options.gpu_id = perception_param.gpu_id();
base::BaseCameraModelPtr model =
common::SensorManager::Instance()->GetUndistortCameraModel(
lane_detector_param.camera_name());
Expand All @@ -211,8 +211,8 @@ void ObstacleCameraPerception::InitLane(
AINFO << "Detector: " << lane_detector_->Name();

// Initialize lane postprocessor
auto lane_postprocessor_param =
perception_param_.lane_param().lane_postprocessor_param();
const auto &lane_postprocessor_param =
lane_param.lane_postprocessor_param();
LanePostprocessorInitOptions postprocessor_init_options;
postprocessor_init_options.detect_config_root =
GetAbsolutePath(work_root, lane_detector_plugin_param.root_dir());
Expand All @@ -231,17 +231,17 @@ void ObstacleCameraPerception::InitLane(
AINFO << "lane_postprocessor: " << lane_postprocessor_->Name();

// Init output file folder
if (perception_param_.has_debug_param() &&
perception_param_.debug_param().has_lane_out_dir()) {
if (perception_param.has_debug_param() &&
perception_param.debug_param().has_lane_out_dir()) {
write_out_lane_file_ = true;
out_lane_dir_ = perception_param_.debug_param().lane_out_dir();
out_lane_dir_ = perception_param.debug_param().lane_out_dir();
EnsureDirectory(out_lane_dir_);
}

if (perception_param_.has_debug_param() &&
perception_param_.debug_param().has_calibration_out_dir()) {
if (perception_param.has_debug_param() &&
perception_param.debug_param().has_calibration_out_dir()) {
write_out_calib_file_ = true;
out_calib_dir_ = perception_param_.debug_param().calibration_out_dir();
out_calib_dir_ = perception_param.debug_param().calibration_out_dir();
EnsureDirectory(out_calib_dir_);
}
}
Expand Down Expand Up @@ -313,47 +313,38 @@ bool ObstacleCameraPerception::Perception(
name_intrinsic_map_.at(frame->data_provider->sensor_name());
CHECK(frame->calibration_service != nullptr);

// Lane detector and postprocessor: work on front_6mm only
if (lane_calibration_working_sensor_name_ ==
frame->data_provider->sensor_name()) {
LaneDetectorOptions lane_detetor_options;
LanePostprocessorOptions lane_postprocessor_options;
if (!lane_detector_->Detect(lane_detetor_options, frame)) {
AERROR << "Failed to detect lane.";
return false;
}
PERCEPTION_PERF_BLOCK_END_WITH_INDICATOR(
frame->data_provider->sensor_name(), "LaneDetector");
LaneDetectorOptions lane_detetor_options;
LanePostprocessorOptions lane_postprocessor_options;
if (!lane_detector_->Detect(lane_detetor_options, frame)) {
AERROR << "Failed to detect lane.";
return false;
}
PERCEPTION_PERF_BLOCK_END_WITH_INDICATOR(
frame->data_provider->sensor_name(), "LaneDetector");

if (!lane_postprocessor_->Process2D(lane_postprocessor_options, frame)) {
AERROR << "Failed to postprocess lane 2D.";
return false;
}
PERCEPTION_PERF_BLOCK_END_WITH_INDICATOR(
frame->data_provider->sensor_name(), "LanePostprocessor2D");
if (!lane_postprocessor_->Process2D(lane_postprocessor_options, frame)) {
AERROR << "Failed to postprocess lane 2D.";
return false;
}
PERCEPTION_PERF_BLOCK_END_WITH_INDICATOR(
frame->data_provider->sensor_name(), "LanePostprocessor2D");

// Calibration service
frame->calibration_service->Update(frame);
PERCEPTION_PERF_BLOCK_END_WITH_INDICATOR(
frame->data_provider->sensor_name(), "CalibrationService");
// Calibration service
frame->calibration_service->Update(frame);
PERCEPTION_PERF_BLOCK_END_WITH_INDICATOR(
frame->data_provider->sensor_name(), "CalibrationService");

if (!lane_postprocessor_->Process3D(lane_postprocessor_options, frame)) {
AERROR << "Failed to postprocess lane 3D.";
return false;
}
PERCEPTION_PERF_BLOCK_END_WITH_INDICATOR(
frame->data_provider->sensor_name(), "LanePostprocessor3D");
if (!lane_postprocessor_->Process3D(lane_postprocessor_options, frame)) {
AERROR << "Failed to postprocess lane 3D.";
return false;
}
PERCEPTION_PERF_BLOCK_END_WITH_INDICATOR(
frame->data_provider->sensor_name(), "LanePostprocessor3D");

if (write_out_lane_file_) {
std::string lane_file_path =
out_lane_dir_ + "/" + std::to_string(frame->frame_id) + ".txt";
WriteLanelines(write_out_lane_file_, lane_file_path, frame->lane_objects);
}
} else {
// Fill the frame using previous estimates
frame->calibration_service->Update(frame);
PERCEPTION_PERF_BLOCK_END_WITH_INDICATOR(
frame->data_provider->sensor_name(), "CalibrationService");
if (write_out_lane_file_) {
std::string lane_file_path =
out_lane_dir_ + "/" + std::to_string(frame->frame_id) + ".txt";
WriteLanelines(write_out_lane_file_, lane_file_path, frame->lane_objects);
}

if (write_out_calib_file_) {
Expand Down
2 changes: 1 addition & 1 deletion modules/perception/camera/app/perception.proto
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ message PerceptionParam {
optional int32 gpu_id = 5;
optional string camera_intrinsics = 6;
optional FeatureParam feature_param = 7;
optional LanePerceptionParam lane_param = 8;
repeated LanePerceptionParam lane_param = 8;
optional CalibrationServiceParam calibration_service_param = 9;
optional DebugParam debug_param = 10;
optional ObjectTemplateParam object_template_param = 11;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,15 @@ TEST(darkSCNNLanePostprocessor, camera_lane_postprocessor_point_test) {

intrinsic_map["onsemi_obstacle"] = frame.camera_k_matrix;
extrinsic_map["onsemi_obstacle"] = ex_camera2lidar;
std::vector <std::string> camera_names;
camera_names[0] = visual_camera;

EXPECT_TRUE(visualize_.Init_all_info_single_camera(
visual_camera, intrinsic_map, extrinsic_map, ex_lidar2imu, pitch_adj,
yaw_adj, roll_adj, calibration_service_init_options.image_height,
camera_names, visual_camera, intrinsic_map, extrinsic_map, ex_lidar2imu,
pitch_adj, yaw_adj, roll_adj,
calibration_service_init_options.image_height,
calibration_service_init_options.image_width));
homography_im2car_ = visualize_.homography_im2car();
homography_im2car_ = visualize_.homography_im2car(visual_camera);
lane_postprocessor->SetIm2CarHomography(homography_im2car_);
AINFO << "Initilize visualizer finished!";

Expand Down
Loading

0 comments on commit 1f4be95

Please sign in to comment.