-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
99 lines (72 loc) · 1.67 KB
/
Copy pathmain.cpp
File metadata and controls
99 lines (72 loc) · 1.67 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <stdio.h>
#include "Headers/Candidate.h"
//NameSpaces
using namespace std;
int main(int argc, char *argv[])
{
if (argc == 2) {
VideoCapture video;
video.set(CV_CAP_PROP_FOURCC, CV_FOURCC('D','I','V','4'));
video.open(argv[1]);
video.set(CV_CAP_PROP_FPS, 30);
if (!video.isOpened())
{
cout<<"Failed to open file!!!"<<endl;
return -1;
}
Mat frame;
while(video.read(frame))
{
IplImage oriImg = frame;
IplImage *cvImg = cvCreateImage(cvGetSize(&oriImg), IPL_DEPTH_8U, 1);
cvCvtColor(&oriImg, cvImg, CV_RGB2GRAY);
CvBox2D pupil = findPupil(cvImg);
// exception check
if (pupil.size.width > 0) {
drawEllipse(pupil, &oriImg);
}
else {
printf("No pupil detected!!\n");
}
cvShowImage("Canny", cvImg);
cvShowImage("Cam", &oriImg);
if (cvWaitKey(10) >= 0) break;
cvReleaseImage(&cvImg);
}
}
else
{
CvCapture *capture = cvCaptureFromCAM(-1);
if (!capture) {
printf("No camera\n");
return -1;
}
IplImage *frame;
while(1){
frame = cvQueryFrame(capture);
if(!frame) {
printf("Cannot read cam\n");
cvReleaseCapture(&capture);
return -1;
}
IplImage *cvImg = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 1);
cvCvtColor(frame, cvImg, CV_RGB2GRAY);
CvBox2D pupil = findPupil(cvImg);
// exception
if (pupil.size.width > 0) {
drawEllipse(pupil, frame);
}
else {
printf("No pupil detected!!\n");
}
printf("Pupil size : %f\n", pupil.size.height);
cvShowImage("Canny", cvImg);
cvShowImage("Cam", frame);
if (cvWaitKey(10) >= 0) break;
cvReleaseImage(&cvImg);
}
cvReleaseImage(&frame);
cvReleaseCapture(&capture);
}
return 0;
}