Skip to content
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

Add support for 5x5 bilateral filter in stereo depth; add runtime con… #159

Merged
merged 11 commits into from
Jun 21, 2021
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ add_library(${TARGET_CORE_NAME}
src/pipeline/datatype/SpatialLocationCalculatorConfig.cpp
src/pipeline/datatype/Tracklets.cpp
src/pipeline/datatype/IMUData.cpp
src/pipeline/datatype/StereoDepthConfig.cpp
src/utility/Initialization.cpp
src/utility/Resources.cpp
src/xlink/XLinkConnection.cpp
Expand Down
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 "9628a4701a703d4654d2e965bbfcb74b6cee4915")
set(DEPTHAI_DEVICE_SIDE_COMMIT "3df098eb3fa3d0bf6c53291f9b5e2d892ac33d28")

# "version if applicable"
set(DEPTHAI_DEVICE_SIDE_VERSION "")
31 changes: 31 additions & 0 deletions include/depthai/pipeline/datatype/StereoDepthConfig.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include <unordered_map>
#include <vector>

#include "depthai-shared/datatype/RawStereoDepthConfig.hpp"
#include "depthai/pipeline/datatype/Buffer.hpp"

namespace dai {

/**
* StereoDepthConfig message.
*/
class StereoDepthConfig : public Buffer {
std::shared_ptr<RawBuffer> serialize() const override;
RawStereoDepthConfig& cfg;

public:
/**
* Construct StereoDepthConfig message.
*/
StereoDepthConfig();
explicit StereoDepthConfig(std::shared_ptr<RawStereoDepthConfig> ptr);
virtual ~StereoDepthConfig() = default;

void setConfidenceThreshold(int confThr);
void setMedianFilter(StereoDepthConfigData::MedianFilter median);
void setBilateralFilterSigma(uint16_t sigma);
};

} // namespace dai
13 changes: 13 additions & 0 deletions include/depthai/pipeline/node/StereoDepth.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

// shared
#include "depthai-shared/properties/StereoDepthProperties.hpp"
#include "depthai/pipeline/datatype/StereoDepthConfig.hpp"

namespace dai {
namespace node {
Expand All @@ -23,10 +24,22 @@ class StereoDepth : public Node {
std::vector<Input> getInputs() override;
nlohmann::json getProperties() override;
std::shared_ptr<Node> clone() override;
std::shared_ptr<RawStereoDepthConfig> rawConfig;

public:
StereoDepth(const std::shared_ptr<PipelineImpl>& par, int64_t nodeId);

/**
* Initial config to use when calculating spatial location data.
*/
StereoDepthConfig initialConfig;

/**
* Input StereoDepthConfig message with ability to modify parameters in runtime.
* Default queue is non-blocking with size 4.
*/
Input inputConfig{*this, "inputConfig", Input::Type::SReceiver, false, 4, {{DatatypeEnum::StereoDepthConfig, false}}};

/**
* Input for left ImgFrame of left-right pair
*
Expand Down
25 changes: 25 additions & 0 deletions src/pipeline/datatype/StereoDepthConfig.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "depthai/pipeline/datatype/StereoDepthConfig.hpp"

namespace dai {

std::shared_ptr<RawBuffer> StereoDepthConfig::serialize() const {
return raw;
}

StereoDepthConfig::StereoDepthConfig() : Buffer(std::make_shared<RawStereoDepthConfig>()), cfg(*dynamic_cast<RawStereoDepthConfig*>(raw.get())) {}
StereoDepthConfig::StereoDepthConfig(std::shared_ptr<RawStereoDepthConfig> ptr)
: Buffer(std::move(ptr)), cfg(*dynamic_cast<RawStereoDepthConfig*>(raw.get())) {}

void StereoDepthConfig::setConfidenceThreshold(int confThr) {
cfg.config.confidenceThreshold = confThr;
}

void StereoDepthConfig::setMedianFilter(StereoDepthConfigData::MedianFilter median) {
cfg.config.median = median;
}

void StereoDepthConfig::setBilateralFilterSigma(uint16_t sigma) {
cfg.config.bilateralSigmaValue = sigma;
}

} // namespace dai
9 changes: 9 additions & 0 deletions src/pipeline/datatype/StreamPacketParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "depthai/pipeline/datatype/SpatialImgDetections.hpp"
#include "depthai/pipeline/datatype/SpatialLocationCalculatorConfig.hpp"
#include "depthai/pipeline/datatype/SpatialLocationCalculatorData.hpp"
#include "depthai/pipeline/datatype/StereoDepthConfig.hpp"
#include "depthai/pipeline/datatype/SystemInformation.hpp"
#include "depthai/pipeline/datatype/Tracklets.hpp"

Expand All @@ -37,6 +38,7 @@
#include "depthai-shared/datatype/RawSpatialImgDetections.hpp"
#include "depthai-shared/datatype/RawSpatialLocationCalculatorConfig.hpp"
#include "depthai-shared/datatype/RawSpatialLocations.hpp"
#include "depthai-shared/datatype/RawStereoDepthConfig.hpp"
#include "depthai-shared/datatype/RawSystemInformation.hpp"
#include "depthai-shared/datatype/RawTracklets.hpp"

Expand Down Expand Up @@ -126,6 +128,9 @@ std::shared_ptr<RawBuffer> parsePacket(streamPacketDesc_t* packet) {
case DatatypeEnum::IMUData:
return parseDatatype<RawIMUData>(jser, data);
break;
case DatatypeEnum::StereoDepthConfig:
return parseDatatype<RawStereoDepthConfig>(jser, data);
break;
}

throw std::runtime_error("Bad packet, couldn't parse");
Expand Down Expand Up @@ -197,6 +202,10 @@ std::shared_ptr<ADatatype> parsePacketToADatatype(streamPacketDesc_t* packet) {
case DatatypeEnum::IMUData:
return std::make_shared<IMUData>(parseDatatype<RawIMUData>(jser, data));
break;

case DatatypeEnum::StereoDepthConfig:
return std::make_shared<StereoDepthConfig>(parseDatatype<RawStereoDepthConfig>(jser, data));
break;
}

throw std::runtime_error("Bad packet, couldn't parse");
Expand Down
17 changes: 12 additions & 5 deletions src/pipeline/node/StereoDepth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
namespace dai {
namespace node {

StereoDepth::StereoDepth(const std::shared_ptr<PipelineImpl>& par, int64_t nodeId) : Node(par, nodeId) {
StereoDepth::StereoDepth(const std::shared_ptr<PipelineImpl>& par, int64_t nodeId)
: Node(par, nodeId), rawConfig(std::make_shared<RawStereoDepthConfig>()), initialConfig(rawConfig) {
// 'properties' defaults already set
}

Expand All @@ -21,11 +22,12 @@ std::vector<Node::Output> StereoDepth::getOutputs() {
}

std::vector<Node::Input> StereoDepth::getInputs() {
return {left, right};
return {inputConfig, left, right};
}

nlohmann::json StereoDepth::getProperties() {
nlohmann::json j;
properties.initialConfig = *rawConfig;
nlohmann::to_json(j, properties);
return j;
}
Expand All @@ -46,7 +48,7 @@ void StereoDepth::loadCalibrationFile(const std::string& path) {

void StereoDepth::setEmptyCalibration(void) {
// Special case: a single element
const std::vector<std::uint8_t> empty = {0};
const std::vector<std::uint8_t> empty = {};
properties.calibration = empty;
}

Expand All @@ -55,7 +57,10 @@ void StereoDepth::setInputResolution(int width, int height) {
properties.height = height;
}
void StereoDepth::setMedianFilter(Properties::MedianFilter median) {
properties.median = median;
StereoDepthConfigData::MedianFilter cfgMedian = static_cast<StereoDepthConfigData::MedianFilter>(median);
initialConfig.setMedianFilter(cfgMedian);
properties.initialConfig = *rawConfig;
;
}
void StereoDepth::setDepthAlign(Properties::DepthAlign align) {
properties.depthAlign = align;
Expand All @@ -66,7 +71,9 @@ void StereoDepth::setDepthAlign(CameraBoardSocket camera) {
properties.depthAlignCamera = camera;
}
void StereoDepth::setConfidenceThreshold(int confThr) {
properties.confidenceThreshold = confThr;
initialConfig.setConfidenceThreshold(confThr);
properties.initialConfig = *rawConfig;
;
}
void StereoDepth::setLeftRightCheck(bool enable) {
properties.enableLeftRightCheck = enable;
Expand Down