2f66423874d08b71fbd62e812e04a513b66fd8a2
[platform/core/api/mediavision.git] / mv_machine_learning / inference / include / DecodeInfo.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 __DECODE_INFO_H__
18 #define __DECODE_INFO_H__
19
20 #include <string>
21 #include <vector>
22 #include <map>
23 #include <memory>
24
25 #include <MetadataType.h>
26 #include <mv_inference_type.h>
27 #include <opencv2/core.hpp>
28 #include "Utils.h"
29
30 namespace mediavision
31 {
32 namespace inference
33 {
34 namespace box
35 {
36 struct AnchorParam {
37         int mode;
38         int numLayers;
39         float minScale;
40         float maxScale;
41         int inputSizeHeight;
42         int inputSizeWidth;
43         float anchorOffsetX;
44         float anchorOffsetY;
45         std::vector<int> strides;
46         std::vector<float> aspectRatios;
47         bool isReduceBoxedInLowestLayer;
48         float interpolatedScaleAspectRatio;
49         bool isFixedAnchorSize;
50         bool isExponentialBoxScale;
51         float xScale;
52         float yScale;
53         float wScale;
54         float hScale;
55
56         // Yolo
57         int offsetAnchors;
58         inference_score_type_e type;
59         std::map<std::string, inference_score_type_e> supportedCellType;
60         std::vector<std::vector<double> > vxScales;
61         std::vector<std::vector<double> > vyScales;
62 };
63
64 struct NMSParam {
65         inference_box_nms_type_e mode; /**< 0: standard */
66         float iouThreshold;
67         std::map<std::string, inference_box_nms_type_e> supportedBoxNmsTypes;
68 };
69
70 struct RotateParam {
71         int startPointIndex;
72         int endPointIndex;
73         cv::Point2f startPoint;
74         cv::Point2f endPoint;
75         float baseAngle;
76 };
77
78 struct RoiOptionParam {
79         int startPointIndex;
80         int endPointIndex;
81         int centerPointIndex;
82         cv::Point2f centerPoint;
83         float shiftX;
84         float shiftY;
85         float scaleX;
86         float scaleY;
87         int mode;
88 };
89
90 struct DecodeInfo {
91         AnchorParam anchorParam;
92         std::vector<cv::Rect2f> anchorBoxes;
93         NMSParam nmsParam;
94         RotateParam rotParam;
95         RoiOptionParam roiOptParam;
96
97         DecodeInfo()
98         {
99                 nmsParam.mode = INFERENCE_BOX_NMS_TYPE_NONE;
100                 nmsParam.iouThreshold = 0.2f;
101                 nmsParam.supportedBoxNmsTypes.insert({ "STANDARD", INFERENCE_BOX_NMS_TYPE_STANDARD });
102
103                 rotParam.startPointIndex = -1;
104                 rotParam.endPointIndex = -1;
105                 rotParam.startPoint = cv::Point2f(0.f, 0.f);
106                 rotParam.endPoint = cv::Point2f(0.f, 0.f);
107                 rotParam.baseAngle = 0.f;
108
109                 roiOptParam.startPointIndex = -1;
110                 roiOptParam.endPointIndex = -1;
111                 roiOptParam.centerPointIndex = -1;
112                 roiOptParam.centerPoint = cv::Point2f(0.f, 0.f);
113                 roiOptParam.shiftX = 0.f;
114                 roiOptParam.shiftY = 0.f;
115                 roiOptParam.scaleX = 1.f;
116                 roiOptParam.scaleY = 1.f;
117                 roiOptParam.mode = -1;
118         }
119
120         ~DecodeInfo() = default;
121
122         std::vector<cv::Rect2f> &GetAnchorBoxAll();
123         bool IsAnchorBoxEmpty();
124         void AddAnchorBox(cv::Rect2f &ahcnor);
125         void ClearAnchorBox();
126
127         // Anchor param
128         int ParseAnchorParam(JsonObject *root);
129         int GenerateAnchor();
130         bool IsFixedAnchorSize();
131         bool IsExponentialBoxScale();
132         float GetAnchorXscale();
133         float GetAnchorYscale();
134         float GetAnchorWscale();
135         float GetAnchorHscale();
136         float CalculateScale(float min, float max, int index, int maxStride);
137
138         // Nms param
139         int ParseNms(JsonObject *root);
140         int GetNmsMode();
141         float GetNmsIouThreshold();
142
143         // Rotate param
144         int ParseRotate(JsonObject *root);
145         int GetRotStartPointIndex();
146         int GetRotEndPointIndex();
147         float GetBaseAngle();
148
149         // Roi option param
150         int ParseRoiOption(JsonObject *root);
151         int GetRoiMode();
152         int GetRoiCenterPointIndex();
153         int GetRoiStartPointIndex();
154         int GetRoiEndPointIndex();
155         float GetShiftX();
156         float GetShiftY();
157         float GetScaleX();
158         float GetScaleY();
159 };
160 } /* box */
161 } /* Inference */
162 } /* MediaVision */
163
164 #endif