Add Initialize()
authorTae-Young Chung <ty83.chung@samsung.com>
Thu, 7 Oct 2021 05:27:48 +0000 (14:27 +0900)
committer엘무럿/선행S/W Lab(생활가전)/Principal Engineer/삼성전자 <e.talipov@samsung.com>
Tue, 14 Dec 2021 02:21:04 +0000 (11:21 +0900)
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 <ty83.chung@samsung.com>
CMakeLists.txt
src/dfs_opencv.cpp
src/dfs_opencv_private.h

index 9233dd5c5ade949574e19f375641c11c4adca54a..18ff0f6c7d92767122dd24f1af19252ea7550ebf 100644 (file)
@@ -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()
index 37a8b1431a98c372c97bd45f05fc73bfca03c50a..9289c799da2eb63eda8f14bd584f46f3adc4a3d4 100644 (file)
 
 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)
index bcdb1711b4b166a3fb6fc9c94aae53b34315ab65..afbad5e37a44c64d4713e5650260d00244f0fb1a 100644 (file)
 
 #include <dfs_adaptation.h>
 
+#include <opencv2/core.hpp>
+#include <opencv2/calib3d.hpp>
+#include <opencv2/imgproc.hpp>
+
 /**
 * @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<cv::StereoSGBM> 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;
+
        };
 }