forked from trishume/eyeLike
-
Notifications
You must be signed in to change notification settings - Fork 1
/
camera_capture.cpp
executable file
·84 lines (71 loc) · 2.01 KB
/
camera_capture.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
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
78
79
80
81
82
83
84
#include "eyelib.hpp"
CascadeClassifier face_cascade;
void getGazePosition(Mat &frame);
Mat toHueScale(Mat img);
int main(int argc, char** argv) {
//check arguments
if(argc != 2){
cout << "Usage: camera_capture <video_stream>" << "\n";
return -1;
}
cout << "OpenCV version : " << CV_VERSION << "\n";
//cout << "Major version : " << CV_MAJOR_VERSION << "\n";
//cout << "Minor version : " << CV_MINOR_VERSION << "\n";
//cout << "Subminor version : " << CV_SUBMINOR_VERSION << "\n";
cout << "Loading video source...";
//get camera stream
VideoCapture stream1(argv[1], CAP_V4L); //id of video device
if (!stream1.isOpened()) {
stream1.release();
cout << "\nCould not open video source " << argv[1] << "\n";
return -1;
}
cout << " done\n";
cout << "Loading face cascade XML...";
//load up face detection
String face_cascade_name = "haarcascade_frontalface_alt.xml";
if(!face_cascade.load(face_cascade_name)){
cout << "\nCould not find face cascade file: " + face_cascade_name + "\n";
return -1;
}
cout << " done\n";
cout << "Calculating gradient lookup tables...";
//load lookup tables
calcGradientLookup();
cout << "done\n";
//loop forever
while (true) {
cout << "Getting a frame\n";
Mat cameraFrame;
stream1.read(cameraFrame);
getGazePosition(cameraFrame);
if (waitKey(30) >= 0)
break;
}
return 0;
}
//returns a 2D vector of where the eyes are pointing
void getGazePosition(Mat &frame){
std::vector<Rect> faces;
//get blue channel, less noisy
std::vector<Mat> rgbChannels(3);
split(frame, rgbChannels);
Mat frame_gray = rgbChannels[2];
//detect faces
face_cascade.detectMultiScale(
frame_gray,
faces,
1.1,
2, 0 | CASCADE_SCALE_IMAGE | CASCADE_FIND_BIGGEST_OBJECT,
Size(150, 150));
//show rectangle around faces
for(int i = 0; i < faces.size(); i++ )
{
rectangle(frame, faces[i], 1234);
}
//find eyes in the first (hopefully only) face
if (faces.size() > 0) {
getEyeVectors(frame, frame_gray, faces[0]);
}
//imshow("cam", frame);
}