direcs  2012-09-30
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
camThread.h
Go to the documentation of this file.
1 /*************************************************************************
2  * Copyright (C) Markus Knapp *
3  * www.direcs.de *
4  * *
5  * This file is part of direcs. *
6  * *
7  * direcs is free software: you can redistribute it and/or modify it *
8  * under the terms of the GNU General Public License as published *
9  * by the Free Software Foundation, version 3 of the License. *
10  * *
11  * direcs is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License *
17  * along with direcs. If not, see <http://www.gnu.org/licenses/>. *
18  * *
19  *************************************************************************/
20 
21 #ifndef CAMTHREAD_H
22 #define CAMTHREAD_H
23 
24 //-------------------------------------------------------------------
25 #include <QtGlobal> // for Q_OS_* Makro!
26 #include <QThread>
27 #include <QImage>
28 #include <QtDebug> // for a more convenient use of qDebug
29 #include <QFile>
30 #include <QMutex>
31 //-------------------------------------------------------------------
32 #include <opencv/cv.h>
33 #include <opencv/highgui.h>
34 
35 #ifdef Q_OS_MAC
36 #include <libfreenect/libfreenect_sync.h>
37 #else
38 #include <libfreenect_sync.h>
39 #endif
40 
41 
42 #include <iostream>
43 #include <vector>
44 #include <cmath>
45 
46 using namespace cv;
47 using namespace std;
48 
49 //-------------------------------------------------------------------
50 
51 
56 class CamThread : public QThread
57 {
58  Q_OBJECT
59 
60 
61  public:
62  CamThread();
63 
64  ~CamThread();
65 
69  bool init();
70 
73  bool isConnected(void);
74 
79  void setCascadePath(QString haarClassifierCascade);
80 
81  void stop();
82  virtual void run();
83 
84 
85  public slots:
90  void enableFaceDetection(int state);
91 
96  void setThreshold(int threshold);
97 
98 
99  signals:
104  void camImageComplete(QImage* image);
105 
110  void camImageDepthComplete(QImage* image);
111 
116  void camImageOpenCVComplete(QImage* image);
117 
121  void disableFaceDetection();
122 
126  void disableCamera();
127 
139  void faceDetected(int faces, int faceX, int faceY, int faceRadius, int lastFaceX, int lastFaceY);
140 
146  void message(QString text);
147 
148 
149  private:
150  freenect_context *f_ctx;
151  freenect_device *f_dev;
152 
153  char *data; // the 'raw' data from the Kinect image
154  char *dataDepth;
155  unsigned int timestamp;
156 
157  QImage qimage; // for sending a QImage to the GUI (Signal)
158  QImage qimageDepth; // for sending a QImage to the GUI (Signal)
159  QImage qimageOpenCV; // for sending a QImage to the GUI (Signal)
160  Mat gray; // for OpencV
161 
163 
164  std::vector<uint16_t> m_gamma;
165 
166  //mutable QMutex m_rgb_mutex;
167  //mutable QMutex m_depth_mutex;
168 
169 
170  bool initDone;
175  volatile bool stopped;
176 
177  // Every thread sleeps some time, for having a bit more time for the other threads!
178  // Time in milliseconds
179  static const unsigned long THREADSLEEPTIME = 50; // Default: 100 ms
180 };
181 
182 #endif