Skip to content

Commit

Permalink
add DisparityWidth, Disparity Companding, SubpixelFractionalBits opti…
Browse files Browse the repository at this point in the history
…ons (#279)
  • Loading branch information
borongyuan authored Apr 20, 2023
1 parent 786288e commit 1cd447a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions depthai_ros_driver/config/camera.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@
i_board_socket_id: 0
i_depth_filter_size: 5
i_depth_preset: HIGH_ACCURACY
i_disparity_width: DISPARITY_96
i_enable_companding: false
i_enable_decimation_filter: false
i_enable_distortion_correction: true
i_enable_spatial_filter: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class StereoParamHandler : public BaseParamHandler {

private:
std::unordered_map<std::string, dai::node::StereoDepth::PresetMode> depthPresetMap;
std::unordered_map<std::string, dai::StereoDepthConfig::CostMatching::DisparityWidth> disparityWidthMap;
std::unordered_map<std::string, dai::StereoDepthConfig::PostProcessing::DecimationFilter::DecimationMode> decimationModeMap;
std::unordered_map<std::string, dai::StereoDepthConfig::PostProcessing::TemporalFilter::PersistencyMode> temporalPersistencyMap;
};
Expand Down
17 changes: 15 additions & 2 deletions depthai_ros_driver/src/param_handlers/stereo_param_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ StereoParamHandler::StereoParamHandler(rclcpp::Node* node, const std::string& na
{"HIGH_ACCURACY", dai::node::StereoDepth::PresetMode::HIGH_ACCURACY},
{"HIGH_DENSITY", dai::node::StereoDepth::PresetMode::HIGH_DENSITY},
};

disparityWidthMap = {
{"DISPARITY_64", dai::StereoDepthConfig::CostMatching::DisparityWidth::DISPARITY_64},
{"DISPARITY_96", dai::StereoDepthConfig::CostMatching::DisparityWidth::DISPARITY_96},
};

decimationModeMap = {{"PIXEL_SKIPPING", dai::StereoDepthConfig::PostProcessing::DecimationFilter::DecimationMode::PIXEL_SKIPPING},
{"NON_ZERO_MEDIAN", dai::StereoDepthConfig::PostProcessing::DecimationFilter::DecimationMode::NON_ZERO_MEDIAN},
{"NON_ZERO_MEAN", dai::StereoDepthConfig::PostProcessing::DecimationFilter::DecimationMode::NON_ZERO_MEAN}};
Expand All @@ -27,7 +33,6 @@ StereoParamHandler::StereoParamHandler(rclcpp::Node* node, const std::string& na
{"VALID_1_IN_LAST_5", dai::StereoDepthConfig::PostProcessing::TemporalFilter::PersistencyMode::VALID_1_IN_LAST_5},
{"VALID_1_IN_LAST_8", dai::StereoDepthConfig::PostProcessing::TemporalFilter::PersistencyMode::VALID_1_IN_LAST_8},
{"PERSISTENCY_INDEFINITELY", dai::StereoDepthConfig::PostProcessing::TemporalFilter::PersistencyMode::PERSISTENCY_INDEFINITELY},

};
}

Expand Down Expand Up @@ -72,10 +77,18 @@ void StereoParamHandler::declareParams(std::shared_ptr<dai::node::StereoDepth> s
stereo->initialConfig.setLeftRightCheckThreshold(declareAndLogParam<int>("i_lrc_threshold", 10));
stereo->initialConfig.setMedianFilter(static_cast<dai::MedianFilter>(declareAndLogParam<int>("i_depth_filter_size", 5)));
stereo->initialConfig.setConfidenceThreshold(declareAndLogParam<int>("i_stereo_conf_threshold", 255));
stereo->initialConfig.setSubpixel(declareAndLogParam<bool>("i_subpixel", false));
if(declareAndLogParam<bool>("i_subpixel", false)) {
stereo->initialConfig.setSubpixel(true);
stereo->initialConfig.setSubpixelFractionalBits(declareAndLogParam<int>("i_subpixel_fractional_bits", 3));
}
stereo->setExtendedDisparity(declareAndLogParam<bool>("i_extended_disp", false));
stereo->setRectifyEdgeFillColor(declareAndLogParam<int>("i_rectify_edge_fill_color", 0));
auto config = stereo->initialConfig.get();
config.costMatching.disparityWidth =
utils::getValFromMap(declareAndLogParam<std::string>("i_disparity_width", "DISPARITY_96"), disparityWidthMap);
if(!config.algorithmControl.enableExtended) {
config.costMatching.enableCompanding = declareAndLogParam<bool>("i_enable_companding", false);
}
config.postProcessing.temporalFilter.enable = declareAndLogParam<bool>("i_enable_temporal_filter", false);
if(config.postProcessing.temporalFilter.enable) {
config.postProcessing.temporalFilter.alpha = declareAndLogParam<float>("i_temporal_filter_alpha", 0.4);
Expand Down

0 comments on commit 1cd447a

Please sign in to comment.