2 * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef __DFS_OPENCV_PRIVATE_H__
18 #define __DFS_OPENCV_PRIVATE_H__
20 #include <dfs_adaptation.h>
21 #include <dfs_parameter.h>
26 #include <condition_variable>
29 #include <opencv2/core.hpp>
30 #include <opencv2/calib3d.hpp>
31 #include <opencv2/imgproc.hpp>
32 #include <opencv2/ximgproc.hpp>
33 #include <opencv2/ximgproc/disparity_filter.hpp>
36 * @file dfs_opencv_private.h
37 * @brief This file contains the DfsOCV class which
38 * provides OpenCV based depth functionality
45 #define LOG_TAG "DFS_OCV"
47 using namespace DfsAdaptation;
49 namespace DfsAdaptationImpl
51 typedef struct _CameraParam {
57 intrinsic = cv::Mat(cv::Size(3,3), CV_32FC1);
58 distCoeffs = cv::Mat(cv::Size(1,5), CV_32FC1);
62 typedef struct _StereoParam {
63 CameraParam baceCamera;
64 CameraParam extraCamera;
72 translation = cv::Mat(cv::Size(1,3), CV_32FC1);
73 rotation = cv::Mat(cv::Size(1,3), CV_32FC1);
78 class DfsOCV : public IDfsAdaptation
81 cv::Ptr<cv::StereoSGBM> mDfsOcv;
82 cv::Ptr<cv::StereoMatcher> mDfsOcvExtra;
83 cv::Ptr<cv::ximgproc::DisparityWLSFilter> mDfsPostOcv;
85 DfsParameter mDfsParam;
86 size_t mNumDisparities;
92 static constexpr size_t mDispShift = 16;
93 static constexpr float mDispShiftInv = 1.0f/16.f;
98 cv::Mat mDisp2DepthMat;
99 cv::Mat mDispOffsetMat;
102 StereoParam mStereoParam;
103 bool mIsStereoCalibrated;
104 bool mUpdateStereoCalibration;
107 cv::Mat mBaseReMap[2];
108 cv::Mat mExtraReMap[2];
113 std::vector<std::thread> mThreadPool;
114 std::queue<std::function<void()> > mJobs;
115 std::mutex mMutexJob;
116 std::condition_variable mControlJob;
120 template <class F, class... Args>
121 std::future<bool> EnqueueJob(F f, Args... args);
123 void SetParameters();
124 int ConvertDfsDataTypeToCV(int type);
125 void InitializeStereoCalibration(std::string filepath);
126 void InitRectifyMap();
128 bool computeL(const cv::Mat& baseMat, const cv::Mat& extraMat, cv::Mat& disp);
129 bool computeR(const cv::Mat& baseMat, const cv::Mat& extraMat, cv::Mat& disp);
135 void Initialize(DfsParameter& param, size_t width, size_t height,
136 size_t minDisp, size_t maxDisp, std::string stereoConfigPath) override;
137 void Run(DfsData& base, DfsData& extra) override;
139 DfsData& GetDepthData() override;
144 #endif /* __DFS_OPENCV_PRIVATE_H__ */