This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
PCN.h
77 lines (67 loc) · 2.23 KB
/
PCN.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef __PCN__
#define __PCN__
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include "opencv2/opencv.hpp"
#define M_PI 3.14159265358979323846
#define CLAMP(x, l, u) ((x) < (l) ? (l) : ((x) > (u) ? (u) : (x)))
#define EPS 1e-5
struct Window
{
int x, y, width;
float angle, score;
Window(int x_, int y_, int w_, float a_, float s_)
: x(x_), y(y_), width(w_), angle(a_), score(s_)
{}
};
cv::Point RotatePoint(int x, int y, float centerX, float centerY, float angle)
{
x -= centerX;
y -= centerY;
float theta = -angle * M_PI / 180;
int rx = int(centerX + x * std::cos(theta) - y * std::sin(theta));
int ry = int(centerY + x * std::sin(theta) + y * std::cos(theta));
return cv::Point(rx, ry);
}
void DrawLine(cv::Mat img, std::vector<cv::Point> pointList)
{
int thick = 2;
CvScalar cyan = CV_RGB(0, 255, 255);
CvScalar blue = CV_RGB(0, 0, 255);
cv::line(img, pointList[0], pointList[1], cyan, thick);
cv::line(img, pointList[1], pointList[2], cyan, thick);
cv::line(img, pointList[2], pointList[3], cyan, thick);
cv::line(img, pointList[3], pointList[0], blue, thick);
}
void DrawFace(cv::Mat img, Window face)
{
int x1 = face.x;
int y1 = face.y;
int x2 = face.width + face.x - 1;
int y2 = face.width + face.y - 1;
int centerX = (x1 + x2) / 2;
int centerY = (y1 + y2) / 2;
std::vector<cv::Point> pointList;
pointList.push_back(RotatePoint(x1, y1, centerX, centerY, face.angle));
pointList.push_back(RotatePoint(x1, y2, centerX, centerY, face.angle));
pointList.push_back(RotatePoint(x2, y2, centerX, centerY, face.angle));
pointList.push_back(RotatePoint(x2, y1, centerX, centerY, face.angle));
DrawLine(img, pointList);
}
class PCN
{
public:
PCN(const std::string model1,const std::string model2,const std::string model3,const std::string net1, const std::string net2, const std::string net3);
void SetMinFaceSize(int minFace);
void SetScoreThresh(float thresh1, float thresh2, float thresh3);
void SetImagePyramidScaleFactor(float factor);
void SetVideoSmooth(bool smooth);
std::vector<Window> DetectFace(cv::Mat img);
private:
void* impl_;
};
#endif