the first submit
0 parents
Showing
9 changed files
with
141 additions
and
0 deletions
README.md
0 → 100644
1 | |||
2 | opencv4.5.5 | ||
3 | |||
4 | 模型初始化 | ||
5 | |||
6 | FaceRecognize face_rec=FaceRecognize(det_model_path,landm_model_path,rec_model_path) | ||
7 | |||
8 | det_model_path:人脸检测模型retinaface的onnx模型路径 | ||
9 | landm_model_path:106人脸关键点模型的onnx模型路径 | ||
10 | rec_model_path:人脸识别模型的onnx模型路径 | ||
11 | |||
12 | 重要参数(.h文件) | ||
13 | |||
14 | bool use_gpu=true; //是否使用gpu | ||
15 | float confidence_threshold = 0.5; //人脸检测阈值 | ||
16 | float nms_threshold = 0.4; //nms阈值 | ||
17 | double face_recongnize_thr = 0.2; //人脸相似度阈值 | ||
18 | |||
19 | 接口(返回结果 bool:true/false) | ||
20 | |||
21 | bool face_recognize(string image1_path,string image2_path);参数为两张图像地址,其中iamge1_path为face_id图像输入 | ||
22 | bool face_recognize_image(Mat image1,Mat image2);参数为两张opencv读取的图像矩阵,其中iamge1为face_id图像输入 | ||
23 | |||
24 | 编译 | ||
25 | |||
26 | g++ main.cpp -L . -lfacerecognize -o main | ||
27 | 如果报错无法找到改用:g++ main.cpp -L . -lfacerecognize -o main pkg-config --libs --cflags opencv4 | ||
28 | ./main |
det_face_retina_torch_1.4_v0.0.2.onnx
0 → 100644
No preview for this file type
det_landmarks_106_v0.0.1.onnx
0 → 100644
No preview for this file type
facerecognize.cpp
0 → 100644
This diff is collapsed.
Click to expand it.
facerecognize.h
0 → 100644
1 | #ifndef FACERECOGNIZE_H | ||
2 | #define FACERECOGNIZE_H | ||
3 | #include<opencv2/opencv.hpp> | ||
4 | |||
5 | using namespace std; | ||
6 | using namespace cv; | ||
7 | struct Bbox{ | ||
8 | float xmin; | ||
9 | float ymin; | ||
10 | float xmax; | ||
11 | float ymax; | ||
12 | float score; | ||
13 | float x1; | ||
14 | float y1; | ||
15 | float x2; | ||
16 | float y2; | ||
17 | float x3; | ||
18 | float y3; | ||
19 | float x4; | ||
20 | float y4; | ||
21 | float x5; | ||
22 | float y5; | ||
23 | }; | ||
24 | class FaceRecognize{ | ||
25 | |||
26 | private: | ||
27 | //是否使用gpu? | ||
28 | bool use_gpu=true; | ||
29 | |||
30 | //人脸检测 | ||
31 | vector<float> input_size={640,640}; | ||
32 | vector<float> variances={0.1,0.2}; | ||
33 | vector<float> mean_data={104,117,128}; | ||
34 | float confidence_threshold = 0.5; //人脸检测阈值 | ||
35 | float keep_top_k = 100; | ||
36 | float vis_threshold = 0.5; | ||
37 | float nms_threshold = 0.4; | ||
38 | float resize_scale = 1.0; | ||
39 | bool is_bbox_process=true; //人脸外扩 | ||
40 | |||
41 | //人脸识别 | ||
42 | double face_recongnize_thr = 0.2; //人脸相似度阈值 | ||
43 | cv::dnn::Net det_net,landm_net,rec_net; | ||
44 | |||
45 | |||
46 | public: | ||
47 | FaceRecognize(); | ||
48 | FaceRecognize(string face_det_model_path,string face_landm_model_path,string face_rec_model_path){ | ||
49 | det_net = cv::dnn::readNetFromONNX(face_det_model_path); | ||
50 | landm_net = cv::dnn::readNetFromONNX(face_landm_model_path); | ||
51 | rec_net = cv::dnn::readNetFromONNX(face_rec_model_path); | ||
52 | if(use_gpu){ | ||
53 | det_net.setPreferableBackend(cv::dnn::DNN_BACKEND_CUDA); | ||
54 | det_net.setPreferableTarget(cv::dnn::DNN_TARGET_CUDA); | ||
55 | landm_net.setPreferableBackend(cv::dnn::DNN_BACKEND_CUDA); | ||
56 | landm_net.setPreferableTarget(cv::dnn::DNN_TARGET_CUDA); | ||
57 | rec_net.setPreferableBackend(cv::dnn::DNN_BACKEND_CUDA); | ||
58 | rec_net.setPreferableTarget(cv::dnn::DNN_TARGET_CUDA); | ||
59 | } | ||
60 | |||
61 | } | ||
62 | //人脸检测部分 | ||
63 | vector<vector<float>> priorBox(vector<float> image_size); | ||
64 | vector<Bbox> decode(vector<vector<float>> loc,vector<vector<float>> score,vector<vector<float>>pre,vector<vector<float>> priors,vector<float> variances); | ||
65 | void nms_cpu(std::vector<Bbox> &bboxes, float threshold); | ||
66 | vector<vector<float>> mat2vector(Mat mat); | ||
67 | vector<Bbox> select_score(vector<Bbox> bboxes,float threshold,float w_r,float h_r); | ||
68 | vector<Bbox> bbox_process(vector<Bbox> bboxes,float frame_w,float frame_h); | ||
69 | vector<Bbox> detect(string image_path); | ||
70 | vector<Bbox> detect_image(Mat image); | ||
71 | |||
72 | |||
73 | //人脸关键点部分 | ||
74 | vector<vector<float>> detect_landmarks(string image_path); | ||
75 | vector<vector<float>> detect_image_landmarks(cv::Mat image); | ||
76 | |||
77 | |||
78 | //人脸识部分 | ||
79 | cv::Mat meanAxis0(const cv::Mat &src); | ||
80 | cv::Mat elementwiseMinus(const cv::Mat &A,const cv::Mat &B); | ||
81 | cv::Mat varAxis0(const cv::Mat &src); | ||
82 | int MatrixRank(cv::Mat M); | ||
83 | cv::Mat similarTransform(cv::Mat src,cv::Mat dst); | ||
84 | Mat preprocess_face(Mat image,vector<vector<float>> land); | ||
85 | double getMold(const vector<double>& vec); | ||
86 | double cos_distance(const vector<double>& base, const vector<double>& target); | ||
87 | double get_samilar(Mat image1,Mat image2); | ||
88 | |||
89 | |||
90 | //整体 | ||
91 | bool face_recognize(string image1_path,string image2_path); | ||
92 | bool face_recognize_image(Mat image1,Mat image2); | ||
93 | }; | ||
94 | |||
95 | |||
96 | #endif | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
libfacerecognize.so
0 → 100755
No preview for this file type
main
0 → 100755
No preview for this file type
main.cpp
0 → 100644
1 | #include"facerecognize.h" | ||
2 | #include "ctime" | ||
3 | |||
4 | int main(){ | ||
5 | FaceRecognize face_rec=FaceRecognize("/home/situ/qfs/sdk_project/mobile_face_recognize/det_face_retina_torch_1.4_v0.0.2.onnx","/home/situ/qfs/sdk_project/mobile_face_recognize/det_landmarks_106_v0.0.1.onnx","/home/situ/qfs/sdk_project/mobile_face_recognize/ms1mv3_r18.onnx"); | ||
6 | clock_t start, end; | ||
7 | cv::Mat image1=cv::imread("/data/face_recognize/pipeline_test/59297ec0094211ecaf3d00163e514671/310faceImageContent163029410817774.jpg"); | ||
8 | cv::Mat image2=cv::imread("/data/face_recognize/pipeline_test/59297ec0094211ecaf3d00163e514671/310cardImageContent163029410836583.jpg"); | ||
9 | cout<<"start"<<endl; | ||
10 | start = clock(); | ||
11 | bool result=face_rec.face_recognize_image(image1,image2); | ||
12 | end = clock(); | ||
13 | double elapsedTime = static_cast<double>(end-start) / CLOCKS_PER_SEC ; | ||
14 | |||
15 | printf("PROCESSING TIME: %f",elapsedTime); | ||
16 | |||
17 | } |
ms1mv3_r18.onnx
0 → 100644
This file is too large to display.
-
Please register or sign in to post a comment