Skip to content

Commit

Permalink
ToF: add median filter support
Browse files Browse the repository at this point in the history
  • Loading branch information
SzabolcsGergely committed Jun 21, 2023
1 parent 1a430f0 commit 9d9c07a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions examples/StereoDepth/stereo_depth_from_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,9 @@ def __init__(self, config):
fov = 71.86
focal = width / (2 * math.tan(fov / 2 / 180 * math.pi))

stereo.setBaseline(baseline/10)
stereo.setFocalLength(focal)

streams = ['left', 'right']
if outRectified:
streams.extend(['rectified_left', 'rectified_right'])
Expand Down
3 changes: 2 additions & 1 deletion src/pipeline/datatype/ToFConfigBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ void bind_tofconfig(pybind11::module& m, void* pCallstack){

depthParams
.def(py::init<>())
.def_readwrite("enable", &RawToFConfig::DepthParams::enable, DOC(dai, RawToFConfig, DepthParams, enable))
.def_readwrite("freqModUsed", &RawToFConfig::DepthParams::freqModUsed, DOC(dai, RawToFConfig, DepthParams, freqModUsed))
.def_readwrite("avgPhaseShuffle", &RawToFConfig::DepthParams::avgPhaseShuffle, DOC(dai, RawToFConfig, DepthParams, avgPhaseShuffle))
.def_readwrite("minimumAmplitude", &RawToFConfig::DepthParams::minimumAmplitude, DOC(dai, RawToFConfig, DepthParams, minimumAmplitude))
.def_readwrite("median", &RawToFConfig::DepthParams::median, DOC(dai, RawToFConfig, DepthParams, median))
;

// Message
Expand All @@ -63,6 +63,7 @@ void bind_tofconfig(pybind11::module& m, void* pCallstack){
.def("setFreqModUsed", static_cast<ToFConfig&(ToFConfig::*)(dai::ToFConfig::DepthParams::TypeFMod)>(&ToFConfig::setFreqModUsed), DOC(dai, ToFConfig, setFreqModUsed))
.def("setAvgPhaseShuffle", &ToFConfig::setAvgPhaseShuffle, DOC(dai, ToFConfig, setAvgPhaseShuffle))
.def("setMinAmplitude", &ToFConfig::setMinAmplitude, DOC(dai, ToFConfig, setMinAmplitude))
.def("setMedianFilter", &ToFConfig::setMedianFilter, DOC(dai, ToFConfig, setMedianFilter))

.def("set", &ToFConfig::set, py::arg("config"), DOC(dai, ToFConfig, set))
.def("get", &ToFConfig::get, DOC(dai, ToFConfig, get))
Expand Down
12 changes: 12 additions & 0 deletions utilities/cam_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ def socket_type_pair(arg):
help="Show also ToF amplitude output alongside depth")
parser.add_argument('-tofcm', '--tof-cm', action='store_true',
help="Show ToF depth output in centimeters, capped to 255")
parser.add_argument('-tofmedian', '--tof-median', choices=[0,3,5,7], default=5, type=int,
help="ToF median filter kernel size")
parser.add_argument('-rgbprev', '--rgb-preview', action='store_true',
help="Show RGB `preview` stream instead of full size `isp`")

Expand Down Expand Up @@ -221,6 +223,16 @@ def get(self):
tofConfig.depthParams.freqModUsed = dai.RawToFConfig.DepthParams.TypeFMod.MIN
tofConfig.depthParams.avgPhaseShuffle = False
tofConfig.depthParams.minimumAmplitude = 3.0

if args.tof_median == 0:
tofConfig.depthParams.median = dai.MedianFilter.MEDIAN_OFF
elif args.tof_median == 3:
tofConfig.depthParams.median = dai.MedianFilter.KERNEL_3x3
elif args.tof_median == 5:
tofConfig.depthParams.median = dai.MedianFilter.KERNEL_5x5
elif args.tof_median == 7:
tofConfig.depthParams.median = dai.MedianFilter.KERNEL_7x7

tof[c].initialConfig.set(tofConfig)
if args.tof_amplitude:
amp_name = 'tof_amplitude_' + c
Expand Down

0 comments on commit 9d9c07a

Please sign in to comment.