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 |
|
---|
11 | using namespace pacpus;
|
---|
12 |
|
---|
13 | WebcamWorker::WebcamWorker()
|
---|
14 | {
|
---|
15 | mHeartbeat = new QTimer(this);
|
---|
16 | }
|
---|
17 |
|
---|
18 | WebcamWorker::~WebcamWorker()
|
---|
19 | {
|
---|
20 | close();
|
---|
21 | }
|
---|
22 |
|
---|
23 | void
|
---|
24 | WebcamWorker::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 |
|
---|
37 | void
|
---|
38 | WebcamWorker::close()
|
---|
39 | {
|
---|
40 | disconnect(mHeartbeat, SIGNAL(timeout()), this, SLOT(retrieveFrame()));
|
---|
41 | mWebcam.release();
|
---|
42 | }
|
---|
43 |
|
---|
44 | void
|
---|
45 | WebcamWorker::retrieveFrame()
|
---|
46 | {
|
---|
47 | if (mWebcam.isOpened())
|
---|
48 | {
|
---|
49 | mWebcam >> mFrame;
|
---|
50 | if (mFrame.data)
|
---|
51 | emit gotFrame(mFrame);
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 | void
|
---|
56 | WebcamWorker::setup()
|
---|
57 | {
|
---|
58 | mHeartbeat->start();
|
---|
59 | }
|
---|
60 |
|
---|
61 | void
|
---|
62 | WebcamWorker::cleanup()
|
---|
63 | {
|
---|
64 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.