Add InitRectifyMap() and change distortionCoeff order
[platform/core/multimedia/dfs-opencv.git] / src / dfs_opencv_private.h
1 /**
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #ifndef __DFS_OPENCV_PRIVATE_H__
18 #define __DFS_OPENCV_PRIVATE_H__
19
20 #include <dfs_adaptation.h>
21 #include <dfs_parameter.h>
22
23 #include <opencv2/core.hpp>
24 #include <opencv2/calib3d.hpp>
25 #include <opencv2/imgproc.hpp>
26
27 /**
28 * @file dfs_opencv_private.h
29 * @brief This file contains the DfsAdaptorOCV class which
30 *        provides OpenCV based depth functionality
31 */
32
33 #ifdef LOG_TAG
34 #undef LOG_TAG
35 #endif
36
37 #define LOG_TAG "DFS_ADAPTATION_OCV"
38
39 using namespace DfsAdaptation;
40
41 namespace DfsAdaptationImpl
42 {
43         typedef struct _CameraParam {
44                 cv::Mat intrinsic;
45                 cv::Mat distCoeffs;
46
47                 _CameraParam()
48                 {
49                         intrinsic = cv::Mat(cv::Size(3,3), CV_32FC1);
50                         distCoeffs = cv::Mat(cv::Size(1,5), CV_32FC1);
51                 }
52         } CameraParam;
53
54         typedef struct _StereoParam {
55                 CameraParam baceCamera;
56                 CameraParam extraCamera;
57
58                 cv::Mat translation;
59                 cv::Mat rotation;
60
61                 _StereoParam()
62                 {
63                         translation = cv::Mat(cv::Size(1,3), CV_32FC1);
64                         rotation = cv::Mat(cv::Size(1,3), CV_32FC1);
65                 }
66         } StereoParam;
67
68         class DfsOCV : public IDfsAdaptation
69         {
70         private:
71                 cv::Ptr<cv::StereoSGBM> mDfsOcv;
72
73                 DfsParameter mDfsParam;
74                 size_t mNumDisparities;
75                 size_t mBlockSize;
76                 size_t mMinDisparity;
77                 size_t mP1;
78                 size_t mP2;
79                 size_t mPreFilterCap;
80
81                 cv::Mat mDispMat;
82                 DfsData mDepthData;
83
84                 std::string mCalibFilePath;
85                 StereoParam mStereoParam;
86                 bool mIsStereoCalibrated;
87                 bool mUpdateStereoCalibration;
88
89                 cv::Size mImageSize;
90                 cv::Mat mBaseReMap[2];
91                 cv::Mat mExtraReMap[2];
92
93                 void SetParameters();
94                 int  ConvertDfsDataTypeToCV(int type);
95                 void InitializeStereoCalibration();
96                 void InitRectifyMap();
97
98         public:
99                 DfsOCV();
100                 ~DfsOCV();
101
102                 void Initialize(DfsParameter& param) override;
103                 void Run(DfsData& base, DfsData& extra) override;
104
105                 DfsData& GetDepthData() override;
106
107         };
108 }
109
110 #endif /* __DFS_OPENCV_PRIVATE_H__ */