50817d7717cc66973fc3079a8e6d3527a9e20c82
[platform/core/api/mediavision.git] / mv_machine_learning / inference / include / ObjectDecoder.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 __MEDIA_VISION_OBJECTDECODER_H__
18 #define __MEDIA_VISION_OBJECTDECODER_H__
19
20 #include <string>
21 #include <vector>
22 #include <map>
23 #include <list>
24 #include <opencv2/core.hpp>
25
26 #include "TensorBuffer.h"
27 #include "OutputMetadata.h"
28 #include "PostProcess.h"
29
30 /**
31  * @file ObjectDecoder.h
32  * @brief This file contains the ObjectDecoder class definition which
33  *        provides object decoder.
34  */
35
36 namespace mediavision
37 {
38 namespace inference
39 {
40 class ObjectDecoder
41 {
42 private:
43         TensorBuffer mTensorBuffer;
44         OutputMetadata mMeta;
45         int mBoxOffset;
46         int mNumberOfOjects;
47         float mScaleW;
48         float mScaleH;
49         Boxes mResultBoxes;
50
51         float decodeScore(int idx);
52         Box decodeBox(int idx, float score, int label = -1, int offset = 0);
53         Box decodeBoxWithAnchor(int idx, int anchorIdx, float score, cv::Rect2f &anchor);
54
55 public:
56         ObjectDecoder(TensorBuffer &buffer, OutputMetadata &metaData, int boxOffset, float scaleW, float scaleH,
57                                   int numberOfObjects = 0)
58                         : mTensorBuffer(buffer)
59                         , mMeta(metaData)
60                         , mBoxOffset(boxOffset)
61                         , mNumberOfOjects(numberOfObjects)
62                         , mScaleW(scaleW)
63                         , mScaleH(scaleH)
64                         , mResultBoxes() {};
65
66         ~ObjectDecoder() = default;
67
68         int init();
69         int decode();
70         Boxes &getObjectAll();
71 };
72
73 } /* Inference */
74 } /* MediaVision */
75
76 #endif /* __MEDIA_VISION_OBJECTDECODER_H__ */