source: pacpussensors/trunk/OpencvVideo/WebcamWorker.cpp

Last change on this file was 122, checked in by ldecherf, 8 years ago

porting for linux

File size: 1.2 KB
Line 
1//0/ Includes, project.
2#include "WebcamWorker.hpp"
3
4// Includes, qt.
5#include <QDebug>
6
7// Includes, standard.
8#include <cassert>
9#include <stdexcept>
10
11using namespace pacpus;
12
13WebcamWorker::WebcamWorker()
14{
15 mHeartbeat = new QTimer(this);
16}
17
18WebcamWorker::~WebcamWorker()
19{
20 close();
21}
22
23void
24WebcamWorker::open(int device, int width, int height, int msec)
25{
26 if (!mWebcam.open(device))
27 throw std::runtime_error("cannot open the requested device");
28#ifdef WIN32
29 if (!mWebcam.set(CV_CAP_PROP_FRAME_WIDTH, width))
30 throw std::runtime_error("cannot set the requested width");
31 if (!mWebcam.set(CV_CAP_PROP_FRAME_HEIGHT, height))
32 throw std::runtime_error("cannot set the requested height");
33#endif
34
35 mHeartbeat->setInterval(msec);
36 connect(mHeartbeat, SIGNAL(timeout()), this, SLOT(retrieveFrame()));
37}
38
39void
40WebcamWorker::close()
41{
42 disconnect(mHeartbeat, SIGNAL(timeout()), this, SLOT(retrieveFrame()));
43 mWebcam.release();
44}
45
46void
47WebcamWorker::retrieveFrame()
48{
49 if (mWebcam.isOpened())
50 {
51 mWebcam >> mFrame;
52 if (mFrame.data)
53 emit gotFrame(mFrame);
54 }
55}
56
57void
58WebcamWorker::setup()
59{
60 mHeartbeat->start();
61}
62
63void
64WebcamWorker::cleanup()
65{
66}
Note: See TracBrowser for help on using the repository browser.