f63bade1952cfa2ac861cd3e2f1444cb753e6e95
[platform/core/api/mediavision.git] / mv_machine_learning / training / include / feature_vector_manager.h
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 #ifndef __FEATURE_VECTOR_MANAGER_H__
18 #define __FEATURE_VECTOR_MANAGER_H__
19
20 #include <string>
21 #include <vector>
22
23 #include <opencv2/opencv.hpp>
24 #include <opencv2/imgproc/imgproc.hpp>
25
26 #include "file_util.h"
27
28 struct FeaVecHeader {
29         unsigned int signature;
30         size_t feature_size;
31         size_t label_cnt;
32         unsigned int data_set_cnt;
33 };
34
35 class FeatureVectorManager
36 {
37 protected:
38         std::string _feature_vector_file;
39
40 public:
41         FeatureVectorManager(const std::string feature_vector_file = "feature_vector_file.dat");
42         virtual ~FeatureVectorManager() = default;
43
44         const std::string &GetFileName();
45
46         static void GetVecFromImg(const std::string image_file, std::vector<float> &vec, unsigned int width,
47                                                           unsigned int height);
48         static void GetVecFromRGB(unsigned char *in_data, std::vector<float> &vec, unsigned int width, unsigned int height,
49                                                           size_t re_width, size_t re_height);
50         static void GetVecFromXRGB(unsigned char *in_data, std::vector<float> &vec, unsigned int in_width,
51                                                            unsigned int in_height, unsigned int re_width, unsigned int re_height);
52
53         virtual void WriteHeader(size_t feature_size, size_t label_cnt, unsigned int data_set_cnt) = 0;
54         virtual void StoreData(std::vector<std::vector<float> > &features_vec, std::vector<unsigned int> &label_index) = 0;
55         virtual void Remove() = 0;
56
57         static constexpr unsigned int feature_vector_signature = 0xFEA09841;
58 };
59
60 #endif