mv_machine_learning: use carnel notation
[platform/core/api/mediavision.git] / mv_machine_learning / training / src / data_augment_rotate.cpp
1 /**
2  * Copyright (c) 2022 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 "machine_learning_exception.h"
18 #include "data_augment_rotate.h"
19
20 using namespace std;
21 using namespace mediavision::machine_learning::exception;
22
23 DataAugmentRotate::DataAugmentRotate(unsigned int degree) : _degree(degree)
24 {}
25
26 DataAugmentRotate::~DataAugmentRotate()
27 {}
28
29 void DataAugmentRotate::preprocess(vector<float> &in_vec, vector<float> &out_vec, int width, int height)
30 {
31         cv::Mat cvSrc = cv::Mat(cv::Size(width, height), CV_32FC3, in_vec.data()).clone();
32
33         cv::Mat cvRotate;
34         int rotate_code = 0;
35
36         switch (_degree) {
37         case 90:
38                 rotate_code = cv::ROTATE_90_CLOCKWISE;
39                 break;
40         case -90:
41         case 270:
42                 rotate_code = cv::ROTATE_90_COUNTERCLOCKWISE;
43                 break;
44         case 180:
45                 rotate_code = cv::ROTATE_180;
46                 break;
47         default:
48                 throw InvalidParameter("Invalid degree value.");
49         }
50
51         cv::rotate(cvSrc, cvRotate, rotate_code);
52
53         out_vec.assign((float *) cvRotate.data, (float *) cvRotate.data + cvRotate.total() * cvRotate.channels());
54 }