source: pacpussensors/trunk/OpencvVideo/WebcamWorker.cpp@ 67

Last change on this file since 67 was 60, checked in by DHERBOMEZ Gérald, 10 years ago

Add the module opencv video acquisition (compatible with 0.1.x version of the framework).

File size: 1.2 KB
Line 
1// 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 if (!mWebcam.set(CV_CAP_PROP_FRAME_WIDTH, width))
29 throw std::runtime_error("cannot set the requested width");
30 if (!mWebcam.set(CV_CAP_PROP_FRAME_HEIGHT, height))
31 throw std::runtime_error("cannot set the requested height");
32
33 mHeartbeat->setInterval(msec);
34 connect(mHeartbeat, SIGNAL(timeout()), this, SLOT(retrieveFrame()));
35}
36
37void
38WebcamWorker::close()
39{
40 disconnect(mHeartbeat, SIGNAL(timeout()), this, SLOT(retrieveFrame()));
41 mWebcam.release();
42}
43
44void
45WebcamWorker::retrieveFrame()
46{
47 if (mWebcam.isOpened())
48 {
49 mWebcam >> mFrame;
50 if (mFrame.data)
51 emit gotFrame(mFrame);
52 }
53}
54
55void
56WebcamWorker::setup()
57{
58 mHeartbeat->start();
59}
60
61void
62WebcamWorker::cleanup()
63{
64}
Note: See TracBrowser for help on using the repository browser.