From: Tae-Young Chung Date: Wed, 13 Oct 2021 00:26:41 +0000 (+0900) Subject: implement Run() and GetDepthData() X-Git-Tag: submit/tizen/20220701.002357~1^2~27 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2086db6cc4ad4c8f5c0e11ef4a037312a848b0ea;p=platform%2Fcore%2Fmultimedia%2Fdfs-opencv.git implement Run() and GetDepthData() Signed-off-by: Tae-Young Chung --- diff --git a/src/dfs_opencv.cpp b/src/dfs_opencv.cpp index 2db17d6..0d6bd10 100644 --- a/src/dfs_opencv.cpp +++ b/src/dfs_opencv.cpp @@ -21,13 +21,15 @@ namespace DfsAdaptationImpl { DfsOCV::DfsOCV() : mDfsOcv(nullptr), - mDepthParam(), + mDfsParam(), mNumDisparities(179), mBlockSize(5), mMinDisparity(32), mP1(24*3), mP2(96*3), - mPreFilterCap(63) + mPreFilterCap(63), + mDispMat(), + mDepthData() { LOGI("ENTER"); LOGI("LEAVE"); @@ -39,11 +41,11 @@ namespace DfsAdaptationImpl LOGI("LEAVE"); } - void DfsOCV::Initialize(DepthParameter& param) + void DfsOCV::Initialize(DfsParameter& param) { LOGI("ENTER"); - mDepthParam = param; + mDfsParam = param; mDfsOcv = cv::StereoSGBM::create(1, mNumDisparities, mBlockSize); @@ -66,6 +68,65 @@ namespace DfsAdaptationImpl LOGI("LEAVE"); } + int DfsOCV::ConvertDfsDataTypeToCV(int type) + { + LOGI("LEAVE"); + switch (type) { + case DFS_DATA_TYPE_UINT8: + return CV_8UC1; + default: + LOGE("Invalide type"); + } + + return -1; + + LOGI("ENTER"); + } + void DfsOCV::Run(DfsData& base, DfsData& extra) + { + LOGI("ENTER"); + + if (!base.data || !extra.data) { + throw std::runtime_error("invalid data pointer"); + } + + int baseCvType = ConvertDfsDataTypeToCV(base.type); + int extraCvType = ConvertDfsDataTypeToCV(base.type); + if (baseCvType < 0 || extraCvType < 0) { + throw std::runtime_error("invalid data type"); + } + + cv::Mat baseMat(cv::Size(base.width, base.height), baseCvType, base.data); + cv::Mat extraMat(cv::Size(extra.width, extra.height), extraCvType, extra.data); + + if (baseMat.size() != extraMat.size()) { + throw std::runtime_error("base and extra should be the same size"); + } + + if (baseMat.type() != extraMat.type()) { + throw std::runtime_error("base and extra should be the type"); + } + + mDfsOcv->compute(baseMat, extraMat, mDispMat); + + mDepthData.data = mDispMat.data; + mDepthData.type = DFS_DATA_TYPE_UINT8; + mDepthData.width = mDispMat.cols; + mDepthData.height = mDispMat.rows; + mDepthData.stride = mDispMat.elemSize(); + + LOGI("LEAVE"); + } + + DfsData& DfsOCV::GetDepthData() + { + LOGI("ENTER"); + + return mDepthData; + + LOGI("LEAVE"); + } + extern "C" { class IDfsAdaptation *AdaptorInit(void) diff --git a/src/dfs_opencv_private.h b/src/dfs_opencv_private.h index ea394e6..fba5045 100644 --- a/src/dfs_opencv_private.h +++ b/src/dfs_opencv_private.h @@ -45,7 +45,7 @@ namespace DfsAdaptationImpl private: cv::Ptr mDfsOcv; - DepthParameter mDepthParam; + DfsParameter mDfsParam; size_t mNumDisparities; size_t mBlockSize; size_t mMinDisparity; @@ -53,12 +53,19 @@ namespace DfsAdaptationImpl size_t mP2; size_t mPreFilterCap; + cv::Mat mDispMat; + DfsData mDepthData; + void SetParameters(); + int ConvertDfsDataTypeToCV(int type); public: DfsOCV(); ~DfsOCV(); - void Initialize(DepthParameter& param) override; + void Initialize(DfsParameter& param) override; + void Run(DfsData& base, DfsData& extra) override; + + DfsData& GetDepthData() override; }; }