-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.cpp
40 lines (36 loc) · 1.27 KB
/
demo.cpp
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
#include "Faster_Retinaface.h"
using namespace std;
void Draw(Mat& src, vector<Face> faces, bool use_landmarks, double fontsize = 0.5, int thickness = 1)
{
int offset = 40.0 * fontsize;
//cout << "find " << faces.size() << " faces fps " << fps / times << endl;
for (size_t i = 0; i < faces.size(); i++)
{
rectangle(src, faces[i].boundingbox, Scalar(0, 255, 0), 2);
Point p(faces[i].boundingbox.br().x + 2, faces[i].boundingbox.y + offset);
putText(src, to_string(faces[i].score), p, FONT_HERSHEY_COMPLEX, fontsize, Scalar(255, 0, 0), thickness);
if (use_landmarks)
{
for (size_t j = 0; j < faces[i].landmarks.size(); j++)
{
circle(src, faces[i].landmarks[j], 1, Scalar(255, 0, 0), 2);
}
}
}
}
int main(int argc, char* args[])
{
bool use_gpu=false;
RetinaFace m_facedetector(use_gpu);
m_facedetector.Loadmodel("models", "mnet.25");
string path="your_image.jpg";
cout << "image_path :" << path << endl;
Mat src = imread(path);
mx_float score = 0.8; //score threshold
mx_float scale = 1.0; //image tensor scale,smaller and faster,and lower accuracy
vector<Face> faces = m_facedetector.detect(src, score, vector<mx_float> {scale});
cout << "find " << faces.size() << " faces" << endl;
Draw(src, faces, use_lankmarks);
imshow(path, src);
waitKey(0);
}