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 |
|
---|
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 | #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 |
|
---|
39 | void
|
---|
40 | WebcamWorker::close()
|
---|
41 | {
|
---|
42 | disconnect(mHeartbeat, SIGNAL(timeout()), this, SLOT(retrieveFrame()));
|
---|
43 | mWebcam.release();
|
---|
44 | }
|
---|
45 |
|
---|
46 | void
|
---|
47 | WebcamWorker::retrieveFrame()
|
---|
48 | {
|
---|
49 | if (mWebcam.isOpened())
|
---|
50 | {
|
---|
51 | mWebcam >> mFrame;
|
---|
52 | if (mFrame.data)
|
---|
53 | emit gotFrame(mFrame);
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | void
|
---|
58 | WebcamWorker::setup()
|
---|
59 | {
|
---|
60 | mHeartbeat->start();
|
---|
61 | }
|
---|
62 |
|
---|
63 | void
|
---|
64 | WebcamWorker::cleanup()
|
---|
65 | {
|
---|
66 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.