Skip to content

Commit

Permalink
Merge pull request #1151 from luxonis/stereo_filter_improvements
Browse files Browse the repository at this point in the history
Stereo filter improvements: do postprocessing in 13 bit range
  • Loading branch information
SzabolcsGergely authored Nov 8, 2024
2 parents acafbab + 02f004d commit b0b4d49
Show file tree
Hide file tree
Showing 4 changed files with 245 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmake/Depthai/DepthaiDeviceSideConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot")

# "full commit hash of device side binary"
set(DEPTHAI_DEVICE_SIDE_COMMIT "5a168b72adfbd1bcc7c5e0e0cb8506a18304fcd4")
set(DEPTHAI_DEVICE_SIDE_COMMIT "f5f9f88ada8dc7ac279e44e6a02d37198e333549")

# "version if applicable"
set(DEPTHAI_DEVICE_SIDE_VERSION "")
11 changes: 9 additions & 2 deletions include/depthai/pipeline/node/StereoDepth.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,18 @@ class StereoDepth : public NodeCRTP<Node, StereoDepth, StereoDepthProperties> {
/**
* Prefers accuracy over density. More invalid depth values, but less outliers.
*/
HIGH_ACCURACY,
HIGH_ACCURACY [[deprecated("Will be removed in future releases and replaced with DEFAULT")]],
/**
* Prefers density over accuracy. Less invalid depth values, but more outliers.
*/
HIGH_DENSITY
HIGH_DENSITY [[deprecated("Will be removed in future releases and replaced with DEFAULT")]],

DEFAULT,
FACE,
HIGH_DETAIL,
HIGH_FPS,
HIGH_ACCURACY2,
ROBOTICS
};

protected:
Expand Down
2 changes: 1 addition & 1 deletion shared/depthai-shared
234 changes: 234 additions & 0 deletions src/pipeline/node/StereoDepth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,240 @@ void StereoDepth::setDefaultProfilePreset(PresetMode mode) {
initialConfig.setLeftRightCheck(true);
initialConfig.setLeftRightCheckThreshold(10);
} break;
case PresetMode::DEFAULT: {
setDefaultProfilePreset(PresetMode::HIGH_DENSITY);
initialConfig.setLeftRightCheck(true);
initialConfig.setExtendedDisparity(false);
initialConfig.setSubpixel(true);
initialConfig.setSubpixelFractionalBits(3);
initialConfig.setMedianFilter(MedianFilter::KERNEL_7x7);

dai::RawStereoDepthConfig config = initialConfig.get();

config.postProcessing.filteringOrder = {RawStereoDepthConfig::PostProcessing::Filter::DECIMATION,
RawStereoDepthConfig::PostProcessing::Filter::MEDIAN,
RawStereoDepthConfig::PostProcessing::Filter::SPECKLE,
RawStereoDepthConfig::PostProcessing::Filter::SPATIAL,
RawStereoDepthConfig::PostProcessing::Filter::TEMPORAL};
config.postProcessing.decimationFilter.decimationFactor = 2;
config.postProcessing.decimationFilter.decimationMode = RawStereoDepthConfig::PostProcessing::DecimationFilter::DecimationMode::NON_ZERO_MEAN;

config.postProcessing.spatialFilter.enable = true;
config.postProcessing.spatialFilter.holeFillingRadius = 1;
config.postProcessing.spatialFilter.numIterations = 2;
config.postProcessing.spatialFilter.alpha = 0.5;
config.postProcessing.spatialFilter.delta = 3;

config.postProcessing.temporalFilter.enable = true;
config.postProcessing.temporalFilter.alpha = 0.5;
config.postProcessing.temporalFilter.delta = 3;

config.postProcessing.speckleFilter.enable = true;
config.postProcessing.speckleFilter.speckleRange = 200;
config.postProcessing.speckleFilter.differenceThreshold = 2;

config.postProcessing.thresholdFilter.minRange = 0;
config.postProcessing.thresholdFilter.maxRange = 15000;

initialConfig.set(config);

setPostProcessingHardwareResources(3, 3);
} break;
case PresetMode::FACE: {
setDefaultProfilePreset(PresetMode::HIGH_DENSITY);
initialConfig.setLeftRightCheck(true);
initialConfig.setExtendedDisparity(true);
initialConfig.setSubpixel(true);
initialConfig.setSubpixelFractionalBits(5);
initialConfig.setMedianFilter(MedianFilter::MEDIAN_OFF);

dai::RawStereoDepthConfig config = initialConfig.get();

config.postProcessing.filteringOrder = {RawStereoDepthConfig::PostProcessing::Filter::DECIMATION,
RawStereoDepthConfig::PostProcessing::Filter::MEDIAN,
RawStereoDepthConfig::PostProcessing::Filter::SPECKLE,
RawStereoDepthConfig::PostProcessing::Filter::SPATIAL,
RawStereoDepthConfig::PostProcessing::Filter::TEMPORAL};
config.postProcessing.decimationFilter.decimationFactor = 2;
config.postProcessing.decimationFilter.decimationMode = RawStereoDepthConfig::PostProcessing::DecimationFilter::DecimationMode::NON_ZERO_MEAN;

config.postProcessing.spatialFilter.enable = true;
config.postProcessing.spatialFilter.holeFillingRadius = 1;
config.postProcessing.spatialFilter.numIterations = 1;
config.postProcessing.spatialFilter.alpha = 0.5;
config.postProcessing.spatialFilter.delta = 3;

config.postProcessing.temporalFilter.enable = true;
config.postProcessing.temporalFilter.alpha = 0.5;
config.postProcessing.temporalFilter.delta = 3;

config.postProcessing.speckleFilter.enable = true;
config.postProcessing.speckleFilter.speckleRange = 200;
config.postProcessing.speckleFilter.differenceThreshold = 2;

config.postProcessing.thresholdFilter.minRange = 30;
config.postProcessing.thresholdFilter.maxRange = 3000;

initialConfig.set(config);

setPostProcessingHardwareResources(3, 3);
} break;
case PresetMode::HIGH_DETAIL: {
setDefaultProfilePreset(PresetMode::HIGH_ACCURACY);
initialConfig.setLeftRightCheck(true);
initialConfig.setExtendedDisparity(true);
initialConfig.setSubpixel(true);
initialConfig.setSubpixelFractionalBits(5);
initialConfig.setMedianFilter(MedianFilter::MEDIAN_OFF);

dai::RawStereoDepthConfig config = initialConfig.get();

config.postProcessing.filteringOrder = {RawStereoDepthConfig::PostProcessing::Filter::DECIMATION,
RawStereoDepthConfig::PostProcessing::Filter::MEDIAN,
RawStereoDepthConfig::PostProcessing::Filter::SPECKLE,
RawStereoDepthConfig::PostProcessing::Filter::SPATIAL,
RawStereoDepthConfig::PostProcessing::Filter::TEMPORAL};
config.postProcessing.decimationFilter.decimationFactor = 1;
config.postProcessing.decimationFilter.decimationMode = RawStereoDepthConfig::PostProcessing::DecimationFilter::DecimationMode::NON_ZERO_MEAN;

config.postProcessing.spatialFilter.enable = true;
config.postProcessing.spatialFilter.holeFillingRadius = 1;
config.postProcessing.spatialFilter.numIterations = 3;
config.postProcessing.spatialFilter.alpha = 0.7;
config.postProcessing.spatialFilter.delta = 3;

config.postProcessing.temporalFilter.enable = true;
config.postProcessing.temporalFilter.alpha = 0.5;
config.postProcessing.temporalFilter.delta = 3;

config.postProcessing.speckleFilter.enable = true;
config.postProcessing.speckleFilter.speckleRange = 200;
config.postProcessing.speckleFilter.differenceThreshold = 2;

config.postProcessing.thresholdFilter.minRange = 0;
config.postProcessing.thresholdFilter.maxRange = 15000;

initialConfig.set(config);

setPostProcessingHardwareResources(3, 3);
} break;
case PresetMode::HIGH_FPS: {
setDefaultProfilePreset(PresetMode::HIGH_DENSITY);
initialConfig.setLeftRightCheck(true);
initialConfig.setExtendedDisparity(false);
initialConfig.setSubpixel(true);
initialConfig.setSubpixelFractionalBits(3);
initialConfig.setMedianFilter(MedianFilter::KERNEL_3x3);

dai::RawStereoDepthConfig config = initialConfig.get();

config.postProcessing.filteringOrder = {RawStereoDepthConfig::PostProcessing::Filter::DECIMATION,
RawStereoDepthConfig::PostProcessing::Filter::MEDIAN,
RawStereoDepthConfig::PostProcessing::Filter::SPECKLE,
RawStereoDepthConfig::PostProcessing::Filter::SPATIAL,
RawStereoDepthConfig::PostProcessing::Filter::TEMPORAL};
config.postProcessing.decimationFilter.decimationFactor = 2;
config.postProcessing.decimationFilter.decimationMode = RawStereoDepthConfig::PostProcessing::DecimationFilter::DecimationMode::NON_ZERO_MEAN;

config.postProcessing.spatialFilter.enable = true;
config.postProcessing.spatialFilter.holeFillingRadius = 1;
config.postProcessing.spatialFilter.numIterations = 2;
config.postProcessing.spatialFilter.alpha = 0.5;
config.postProcessing.spatialFilter.delta = 3;

config.postProcessing.temporalFilter.enable = false;
config.postProcessing.temporalFilter.alpha = 0.5;
config.postProcessing.temporalFilter.delta = 3;

config.postProcessing.speckleFilter.enable = true;
config.postProcessing.speckleFilter.speckleRange = 50;
config.postProcessing.speckleFilter.differenceThreshold = 2;

config.postProcessing.thresholdFilter.minRange = 0;
config.postProcessing.thresholdFilter.maxRange = 15000;

initialConfig.set(config);

setPostProcessingHardwareResources(3, 3);
} break;
case PresetMode::HIGH_ACCURACY2: {
setDefaultProfilePreset(PresetMode::HIGH_ACCURACY);
initialConfig.setLeftRightCheck(true);
initialConfig.setExtendedDisparity(true);
initialConfig.setSubpixel(true);
initialConfig.setSubpixelFractionalBits(5);
initialConfig.setMedianFilter(MedianFilter::MEDIAN_OFF);

dai::RawStereoDepthConfig config = initialConfig.get();

config.postProcessing.filteringOrder = {RawStereoDepthConfig::PostProcessing::Filter::DECIMATION,
RawStereoDepthConfig::PostProcessing::Filter::MEDIAN,
RawStereoDepthConfig::PostProcessing::Filter::SPECKLE,
RawStereoDepthConfig::PostProcessing::Filter::SPATIAL,
RawStereoDepthConfig::PostProcessing::Filter::TEMPORAL};
config.postProcessing.decimationFilter.decimationFactor = 2;
config.postProcessing.decimationFilter.decimationMode = RawStereoDepthConfig::PostProcessing::DecimationFilter::DecimationMode::NON_ZERO_MEAN;

config.postProcessing.spatialFilter.enable = true;
config.postProcessing.spatialFilter.holeFillingRadius = 1;
config.postProcessing.spatialFilter.numIterations = 3;
config.postProcessing.spatialFilter.alpha = 0.5;
config.postProcessing.spatialFilter.delta = 3;

config.postProcessing.temporalFilter.enable = true;
config.postProcessing.temporalFilter.alpha = 0.5;
config.postProcessing.temporalFilter.delta = 3;

config.postProcessing.speckleFilter.enable = true;
config.postProcessing.speckleFilter.speckleRange = 200;
config.postProcessing.speckleFilter.differenceThreshold = 2;

config.postProcessing.thresholdFilter.minRange = 0;
config.postProcessing.thresholdFilter.maxRange = 15000;

initialConfig.set(config);

setPostProcessingHardwareResources(3, 3);
} break;
case PresetMode::ROBOTICS: {
setDefaultProfilePreset(PresetMode::HIGH_DENSITY);
initialConfig.setLeftRightCheck(true);
initialConfig.setExtendedDisparity(false);
initialConfig.setSubpixel(true);
initialConfig.setSubpixelFractionalBits(3);
initialConfig.setMedianFilter(MedianFilter::KERNEL_7x7);

dai::RawStereoDepthConfig config = initialConfig.get();

config.postProcessing.filteringOrder = {RawStereoDepthConfig::PostProcessing::Filter::DECIMATION,
RawStereoDepthConfig::PostProcessing::Filter::MEDIAN,
RawStereoDepthConfig::PostProcessing::Filter::SPECKLE,
RawStereoDepthConfig::PostProcessing::Filter::SPATIAL,
RawStereoDepthConfig::PostProcessing::Filter::TEMPORAL};
config.postProcessing.decimationFilter.decimationFactor = 2;
config.postProcessing.decimationFilter.decimationMode = RawStereoDepthConfig::PostProcessing::DecimationFilter::DecimationMode::NON_ZERO_MEAN;

config.postProcessing.spatialFilter.enable = true;
config.postProcessing.spatialFilter.holeFillingRadius = 2;
config.postProcessing.spatialFilter.numIterations = 1;
config.postProcessing.spatialFilter.alpha = 0.5;
config.postProcessing.spatialFilter.delta = 20;

config.postProcessing.temporalFilter.enable = false;
config.postProcessing.temporalFilter.alpha = 0.5;
config.postProcessing.temporalFilter.delta = 3;

config.postProcessing.speckleFilter.enable = true;
config.postProcessing.speckleFilter.speckleRange = 200;
config.postProcessing.speckleFilter.differenceThreshold = 2;

config.postProcessing.thresholdFilter.minRange = 0;
config.postProcessing.thresholdFilter.maxRange = 10000;

initialConfig.set(config);

setPostProcessingHardwareResources(3, 3);
} break;
}
}

Expand Down

0 comments on commit b0b4d49

Please sign in to comment.