-
Notifications
You must be signed in to change notification settings - Fork 139
Feature/extract stereo filters #1308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v3_develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Jakub!
Left some comments&suggestions, generally looks good.
Let's also add an example (can be similar to stereo_depth_from_host.py
) and tests before merging.
src/pipeline/datatype/ImgFrame.cpp
Outdated
@@ -187,6 +187,23 @@ ImgFrame& ImgFrame::setMetadata(const std::shared_ptr<ImgFrame>& sourceFrame) { | |||
return setMetadata(*sourceFrame); | |||
} | |||
|
|||
ImgFrame& ImgFrame::setDataFrom(const ImgFrame& sourceFrame) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should go with copyDataFrom
to make it clearer it's not a move.
typedef dai::StereoDepthConfig::PostProcessing::SpatialFilter SpatialFilterParams; | ||
typedef dai::StereoDepthConfig::PostProcessing::SpeckleFilter SpeckleFilterParams; | ||
typedef dai::StereoDepthConfig::PostProcessing::TemporalFilter TemporalFilterParams; | ||
typedef std::variant<MedianFilterParams, SpatialFilterParams, SpeckleFilterParams, TemporalFilterParams> FilterParams; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probbably better to move to the filters to a common location and then use using ...
in both StereoDepth and here
/** | ||
* Index of the filter to be applied | ||
*/ | ||
std::int32_t filterIndex; | ||
|
||
/** | ||
* Parameters of the filter to be applied | ||
*/ | ||
FilterParams filterParams; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why we didn't go with std::vector here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is as follows: Say we have filters, applied sequentially, (F1 | F2 | F3 | F4 | F5). When one wants to modify the properties any one filter, say F3, one can simply specify its index and properties without modifying or having to worry about all the other filters. This will throw an error if the param's type does not match the expected type of the filter at the given index.
struct SequentialDepthFiltersProperties : PropertiesSerializable<Properties, SequentialDepthFiltersProperties> { | ||
/** | ||
* List of filters (the type of which is determined by the filter parameters) to apply to the input frame | ||
*/ | ||
std::vector<FilterParams> filters; | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's rather use an initialConfig, to not duplicate parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Read this, the properties and the config are different, we have a fixed sequence of filters, each of which one can set the properties at runtime for.
struct DepthConfidenceFilterProperties : PropertiesSerializable<Properties, DepthConfidenceFilterProperties> { | ||
/** | ||
* Threshold for the confidence filter | ||
*/ | ||
float confidenceThreshold = 0.0f; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as for DepthFilter properties
|
||
constexpr const size_t PERSISTENCY_LUT_SIZE = 256; | ||
|
||
struct TemporalFilterParams { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not break out each implementation in their own .cpp ?
@@ -0,0 +1,904 @@ | |||
#include "depthai/pipeline/node/host/DepthFilters.hpp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'd rather call these ImageFilters, they can be used for general purposes, if one wants to.
Only depthConfidence filter is ToF specific?
E.g. temporal filter could be used on input images to stereo depth to reduce noise. Same for median.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, the DepthConfidenceFilter
is specifically designed to used alongside the ToF
node.
…epthai-core into feature/extract_stereo_filters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds two new host-runnable filter nodes (image filters and depth-confidence filter) to the pipeline, along with their data/config types, properties, bindings, and example scripts.
- Introduce
ImgFrame::copyDataFrom
andclone
methods to duplicate frames - Define
ImageFilters
andDepthConfidenceFilter
nodes, their configs, properties, and Python/JS bindings - Refactor
StereoDepthConfig
to use centralizedFilterParams
, update datatype enums, CMake, and examples
Reviewed Changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
src/pipeline/datatype/ImgFrame.cpp | Implement copyDataFrom and clone for frame duplication |
include/depthai/pipeline/datatype/ImgFrame.hpp | Declare copyDataFrom /clone and update doc comments |
src/pipeline/datatype/DatatypeEnum.cpp | Add new datatypes to hierarchy for image/depth-confidence |
include/depthai/pipeline/datatype/DatatypeEnum.hpp | Extend DatatypeEnum with new config entries |
include/depthai/properties/ImageFiltersProperties.hpp | Define properties for both filter nodes |
include/depthai/pipeline/node/ImageFilters.hpp | Create ImageFilters and DepthConfidenceFilter nodes |
include/depthai/pipeline/datatype/StereoDepthConfig.hpp | Refactor post-processing filters to FilterParams |
include/depthai/pipeline/FilterParams.hpp | Introduce centralized filter parameter structs/enums |
include/depthai/pipeline/datatype/ImageFiltersConfig.hpp | New buffer messages for runtime filter reconfiguration |
bindings/python/.../FilterParamsBindings.* | Python bindings for filter parameters |
bindings/python/.../ImageFiltersBindings.cpp | Python/node bindings for new filter nodes |
bindings/js/bindings.cpp | Add ImageFiltersConfig to JS bindings |
CMakeLists.txt | Link OpenCV calib3d, include new source and binding files |
examples/python/.../stereo_depth_filters.py | Python example for image filters on stereo disparity |
examples/python/RVC2/ToF/tof_host_filter.py | Python example for depth-confidence filter with ToF node |
Comments suppressed due to low confidence (1)
src/pipeline/datatype/ImgFrame.cpp:200
- New
clone
method should have unit tests verifying deep copy of both metadata and pixel data.
std::shared_ptr<ImgFrame> ImgFrame::clone() const {
@@ -310,6 +310,25 @@ class ImgFrame : public Buffer, public ProtoSerializable { | |||
*/ | |||
ImgFrame& setMetadata(const std::shared_ptr<ImgFrame>& sourceFrame); | |||
|
|||
/** | |||
* Convience function to set the data of the ImgFrame |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in doc comment: 'Convience' should be 'Convenience'.
Copilot uses AI. Check for mistakes.
ImgFrame& copyDataFrom(const ImgFrame& sourceFrame); | ||
|
||
/** | ||
* Convience function to set the data of the ImgFrame |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in doc comment: 'Convience' should be 'Convenience'.
Copilot uses AI. Check for mistakes.
std::vector<uint8_t> data(sourceFrame.data->getData().begin(), sourceFrame.data->getData().end()); | ||
setData(std::move(data)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] This copies the frame data via iterator range; consider using the underlying buffer or a single setData(sourceFrame.data->getData())
call to avoid redundant allocations.
std::vector<uint8_t> data(sourceFrame.data->getData().begin(), sourceFrame.data->getData().end()); | |
setData(std::move(data)); | |
setData(sourceFrame.data->getData()); |
Copilot uses AI. Check for mistakes.
Purpose
This PR adds stereo-depth and other depth-confidence TOF filters as two nodes. The two nodes are implemented as host-runnable device nodes. By default, the two nodes run on host. An important feature the two nodes have is that all filter settings can be modified at runtime.
Clickup task: https://app.clickup.com/t/86c0x6wq6
Screencast.from.2025-04-28.01-24-50.webm
Testing script (RVC2)