From f38e144ce12d2b1d5411302937f5de75a5f1a82d Mon Sep 17 00:00:00 2001 From: Tae-Young Chung Date: Thu, 7 Oct 2021 14:27:48 +0900 Subject: [PATCH] Add Initialize() Initialize() creates cv::StereoSGBM as a smart pointer and initializes some parameters for DFS. It only supports MODE_SGBM_3WAY. Signed-off-by: Tae-Young Chung --- CMakeLists.txt | 2 +- src/dfs_opencv.cpp | 40 +++++++++++++++++++++++++++++++++++++++- src/dfs_opencv_private.h | 25 +++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9233dd5..18ff0f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ FOREACH(flag ${${fw_name}_CFLAGS}) SET(EXTRA_CXXFLAGS "${EXTRA_CXXFLAGS} ${flag}") ENDFOREACH(flag) -find_package(OpenCV REQUIRED calib3d imgproc) +find_package(OpenCV REQUIRED core calib3d imgproc) if(NOT OpenCV_FOUND) message(SEND_ERROR "OpenCV NOT FOUND") return() diff --git a/src/dfs_opencv.cpp b/src/dfs_opencv.cpp index 37a8b14..9289c79 100644 --- a/src/dfs_opencv.cpp +++ b/src/dfs_opencv.cpp @@ -19,7 +19,18 @@ namespace DfsAdaptationImpl { - DfsOCV::DfsOCV() + DfsOCV::DfsOCV() : + mDfsOcv(nullptr), + mTextureThreshold(0.0), + mAggregationWindowWidth(3), + mAggregationWindowHeight(3), + mMaxSpeckleSize(0), + mNumDisparities(179), + mBlockSize(5), + mMinDisparity(32), + mP1(24*3), + mP2(96*3), + mPreFilterCap(63) { LOGI("ENTER"); LOGI("LEAVE"); @@ -31,6 +42,33 @@ namespace DfsAdaptationImpl LOGI("LEAVE"); } + void DfsOCV::Initialize(double textureThreshold, + size_t aggregationWindowWidth, + size_t aggregationWindowHeight, + size_t maxSpeckleSize) + { + mTextureThreshold = textureThreshold; + mAggregationWindowWidth = aggregationWindowWidth; + mAggregationWindowHeight = aggregationWindowHeight; + mMaxSpeckleSize = maxSpeckleSize; + + mDfsOcv = cv::StereoSGBM::create(1, mNumDisparities, mBlockSize); + + this->SetParameters(); + } + + void DfsOCV::SetParameters() + { + mDfsOcv->setMinDisaprity(mMinDisparity); + mDfsOcv->setNumDisaprities(mNumDisparities); + mDfsOcv->setBlockSize(mBlockSize); + mDfsOcv->setP1(mP1 * mBlockSize * mBlockSize); + mDfsOcv->setP2(mP2 * mBlockSize * mBlockSize); + mDfsOcv->setPreFilterCap(mPreFilterCap); + + mDfsOcv->setMode(cv::StereoSGBM::MODE_SGBM_3WAY); + } + extern "C" { class IDfsAdaptation *AdaptorInit(void) diff --git a/src/dfs_opencv_private.h b/src/dfs_opencv_private.h index bcdb171..afbad5e 100644 --- a/src/dfs_opencv_private.h +++ b/src/dfs_opencv_private.h @@ -19,6 +19,10 @@ #include +#include +#include +#include + /** * @file dfs_opencv_private.h * @brief This file contains the DfsAdaptorOCV class which @@ -37,9 +41,30 @@ namespace DfsAdaptationImpl { class DfsOCV : public IDfsAdaptation { + private: + cv::Ptr mDfsOcv; + + double mTextureThreshold; + size_t mAggregationWindowWidth; + size_t mAggregationWindowHeight; + size_t mMaxSpeckleSize; + size_t mNumDisparities; + size_t mBlockSize; + size_t mMinDisparity; + size_t mP1; + size_t mP2; + size_t mPreFilterCap; + + void SetParameters(); public: DfsOCV(); ~DfsOCV(); + + void Initialize(double textureThreshold, + size_t aggregationWindowWidth, + size_t aggregationWindowHeight, + size_t maxSpeckleSize) override; + }; } -- 2.34.1