-
Notifications
You must be signed in to change notification settings - Fork 0
/
YuNet.h
47 lines (39 loc) · 1.5 KB
/
YuNet.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#pragma once
#include "opencv2/opencv.hpp"
#include <string>
#include <vector>
#include <iostream>
#include <fstream>
class YuNet
{
public:
YuNet(const std::string& model_path,
const cv::Size& input_size = cv::Size(320, 320),
float conf_threshold = 0.6f,
float nms_threshold = 0.3f,
int top_k = 5000,
int backend_id = 0,
int target_id = 0);
void setBackendAndTarget(int backend_id, int target_id);
/* Overwrite the input size when creating the model. Size format: [Width, Height].
*/
void setInputSize(const cv::Size& input_size);
cv::Mat infer(const cv::Mat image);
private:
cv::Ptr<cv::FaceDetectorYN> model;
std::string model_path_;
cv::Size input_size_;
float conf_threshold_;
float nms_threshold_;
int top_k_;
int backend_id_;
int target_id_;
};
// Function to find the most frequent element in a vector of strings
std::string mostFrequentElement(const std::vector<std::string>& vec);
std::string get_recognition(cv::flann::Index& index, std::vector<std::string>& labels, cv::Mat& feature);
std::tuple<cv::Mat, std::vector<std::string>> get_feature(YuNet detector, cv::Ptr<cv::FaceRecognizerSF> faceRecognizer, cv::flann::Index& index, std::vector<std::string>& labels, cv::Mat image);
// Function to save a vector of cv::Mat to a file
void saveMat(const cv::Mat mat, const std::string& filename);
cv::Mat readMat(const std::string& filename);
cv::Mat convertMatVectorToMat(const std::vector<cv::Mat>& matVector);