Fix errata and add LOG to check enter/leave api
[platform/core/multimedia/dfs-opencv.git] / src / dfs_opencv.cpp
1 /**
2  * Copyright (c) 2019 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 #include "dfs_opencv_private.h"
18 #include <dlog.h>
19
20 namespace DfsAdaptationImpl
21 {
22         DfsOCV::DfsOCV() :
23                 mDfsOcv(nullptr),
24                 mTextureThreshold(0.0),
25                 mAggregationWindowWidth(3),
26                 mAggregationWindowHeight(3),
27                 mMaxSpeckleSize(0),
28                 mNumDisparities(179),
29                 mBlockSize(5),
30                 mMinDisparity(32),
31                 mP1(24*3),
32                 mP2(96*3),
33                 mPreFilterCap(63)
34         {
35                 LOGI("ENTER");
36                 LOGI("LEAVE");
37         }
38
39         DfsOCV::~DfsOCV()
40         {
41                 LOGI("ENTER");
42                 LOGI("LEAVE");
43         }
44
45         void DfsOCV::Initialize(double textureThreshold,
46                                                 size_t aggregationWindowWidth,
47                                                 size_t aggregationWindowHeight,
48                                                 size_t maxSpeckleSize)
49         {
50                 LOGI("ENTER");
51
52                 mTextureThreshold = textureThreshold;
53                 mAggregationWindowWidth = aggregationWindowWidth;
54                 mAggregationWindowHeight = aggregationWindowHeight;
55                 mMaxSpeckleSize = maxSpeckleSize;
56
57                 mDfsOcv = cv::StereoSGBM::create(1, mNumDisparities, mBlockSize);
58
59                 this->SetParameters();
60                 LOGI("LEAVE");
61         }
62
63         void DfsOCV::SetParameters()
64         {
65                 LOGI("ENTER");
66
67                 mDfsOcv->setMinDisparity(mMinDisparity);
68                 mDfsOcv->setNumDisparities(mNumDisparities);
69                 mDfsOcv->setBlockSize(mBlockSize);
70                 mDfsOcv->setP1(mP1 * mBlockSize * mBlockSize);
71                 mDfsOcv->setP2(mP2 * mBlockSize * mBlockSize);
72                 mDfsOcv->setPreFilterCap(mPreFilterCap);
73
74                 mDfsOcv->setMode(cv::StereoSGBM::MODE_SGBM_3WAY);
75                 LOGI("LEAVE");
76         }
77
78         extern "C"
79         {
80                 class IDfsAdaptation *AdaptorInit(void)
81                 {
82                         //InferenceTFLite *engine = new InferenceTFLite();
83                         DfsOCV *adaptor = new DfsOCV();
84                         return adaptor;
85                 }
86
87                 void AdaptorDestroy(class IDfsAdaptation *adaptor)
88                 {
89                         delete adaptor;
90                 }
91         }
92 }