-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy patheyecapture.cpp
More file actions
64 lines (51 loc) · 1.7 KB
/
eyecapture.cpp
File metadata and controls
64 lines (51 loc) · 1.7 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
#include "eyecapture.h"
#include <iostream>
// opencv
#include "highgui.h"
//------------------------------------------------------------------------------
EyeCapture::EyeCapture(const unsigned cameraID, const bool convert_to_gray)
: m_convert_to_gray(convert_to_gray)
{
m_eye = new cv::VideoCapture(cameraID);
if (!(m_eye->isOpened()))
{
std::cout << "[Error] cannot open video file";
}
// Get video information
m_eye_width = (int)m_eye->get(CV_CAP_PROP_FRAME_WIDTH);
m_eye_height = (int)m_eye->get(CV_CAP_PROP_FRAME_HEIGHT);
}
//------------------------------------------------------------------------------
EyeCapture::~EyeCapture()
{
delete m_eye;
}
//------------------------------------------------------------------------------
cv::Mat EyeCapture::getFrame()
{
*(m_eye) >> m_frame;
// convert it and get the needed channel
if(m_convert_to_gray)
{
// YCrCb
cv::Mat Y(m_frame.rows, m_frame.cols, CV_8UC1, cv::Scalar(0));
cv::cvtColor(m_frame.clone(), m_frame, CV_BGR2YCrCb);
int from_to[] = {0, 0};
cv::mixChannels(&m_frame, 1, &Y, 1, from_to, 1);
// HLS
//cv::Mat Y(m_frame.rows, m_frame.cols, CV_8UC1, cv::Scalar(0));
//cv::cvtColor(m_frame.clone(), m_frame, CV_BGR2HLS);
//int from_to[] = {1, 0};
//cv::mixChannels(&m_frame, 1, &Y, 1, from_to, 1);
// HSV
//cv::Mat Y(m_frame.rows, m_frame.cols, CV_8UC1, cv::Scalar(0));
//cv::cvtColor(m_frame.clone(), m_frame, CV_BGR2HSV);
//int from_to[] = {2, 0};
//cv::mixChannels(&m_frame, 1, &Y, 1, from_to, 1);
// flip the image... this actually isn't necessary, but looks better
cv::flip(Y, Y, 1);
return Y.clone();
}
cv::flip(m_frame, m_frame, 1);
return m_frame;
}