-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathcamera.cpp
55 lines (48 loc) · 1.04 KB
/
camera.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
#include "camera.h"
Camera::~Camera()
{
}
void Camera::runSlot()
{
// TODO: clean up. Would be nice not to have nested `if` statements
if (!videoCapture_ or !usingVideoCamera_)
{
if (usingVideoCamera_)
videoCapture_.reset(new cv::VideoCapture(cameraIndex_));
else
videoCapture_.reset(new cv::VideoCapture(videoFileName_));
}
if (videoCapture_->isOpened())
{
timer_.start(0, this);
emit started();
}
}
void Camera::stopped()
{
timer_.stop();
}
void Camera::timerEvent(QTimerEvent *ev)
{
if (ev->timerId() != timer_.timerId())
return;
cv::Mat frame;
if (!videoCapture_->read(frame)) // Blocks until a new frame is ready
{
timer_.stop();
return;
}
emit matReady(frame);
}
void Camera::usingVideoCameraSlot(bool value)
{
usingVideoCamera_ = value;
}
void Camera::cameraIndexSlot(int index)
{
cameraIndex_ = index;
}
void Camera::videoFileNameSlot(QString fileName)
{
videoFileName_ = fileName.toStdString().c_str();
}