Project

General

Profile

Kinect Scol plugin
KinectDevice.h
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OpenSpace3D
4 For the latest info, see http://www.openspace3d.com
5 
6 Copyright (c) 2012 I-maginer
7 
8 This program is free software; you can redistribute it and/or modify it under
9 the terms of the GNU Lesser General Public License as published by the Free Software
10 Foundation; either version 2 of the License, or (at your option) any later
11 version.
12 
13 This program is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16 
17 You should have received a copy of the GNU Lesser General Public License along with
18 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20 http://www.gnu.org/copyleft/lesser.txt
21 
22 -----------------------------------------------------------------------------
23 */
24 
32 #ifndef __KINECTDEVICE_H__
33 #define __KINECTDEVICE_H__
34 
35 #include "lib/common.h"
36 #include "core/Thread.h"
37 #include "objects/KinectUser.h"
38 
39 class KinectDevice : public Thread, public openni::OpenNI::DeviceConnectedListener,
40  public openni::OpenNI::DeviceDisconnectedListener,
41  public openni::OpenNI::DeviceStateChangedListener
42 {
43  public:
44  KinectDevice(unsigned int id);
45  ~KinectDevice();
46 
47  // Get context instance
48  // Init and close device manager
49  openni::Device& GetDevice();
50  bool IsConnected();
51  void GoThread();
52 
53  // Get an existing user
54  KinectUser* CreateKinectUser();
55  void DestroyKinectUser(KinectUser* existingKinectUser);
56 
57  unsigned int GetId();
58  int GetExistingAvailableId();
59  void AddExistingId(unsigned int id);
60  void RemoveExistingId(unsigned int id);
61  void GetValidUsersMap(KinectUser** tUsers);
62  KinectUser* GetUser(int userId);
63 
64  Depth* GetDepthGenerator();
65  Image* GetImageGenerator();
66  User* GetUserGenerator();
67 
68  void GetGeneratorsSize(int &width, int &height);
69  void SetGeneratorsSize(int width, int height);
70 
71  void SetSkeletonSmoothing(float value);
72  float GetSkeletonSmoothing();
73 
74  void SetMirrorMode(bool state);
75  bool GetMirrorMode();
76 
77  void SetDistCutoff(int dist);
78  int GetDistCutoff();
79  void SetAngCutoff(float ang);
80  float GetAngCutoff();
81 
82  void GetHandsPixels(PtrObjBitmap Bcolor, PtrObjBitmap Balpha);
83  void GetDepthBuffer(PtrObjBitmap Bcolor);
84  void GetImageBuffer(PtrObjBitmap Bcolor);
85  void GetImageGreyBuffer(PtrObjBitmap Bcolor);
86  void GetValidUserPixels(PtrObjBitmap Bcolor, PtrObjBitmap Balpha);
87  void GetValidUserPixelsRGB(PtrObjBitmap Bcolor, PtrObjBitmap Balpha);
88 
89  bool GetSklMutexLock();
90  void ReleaseSklMutex();
91  public:
92 
93  private:
94  // List of detected users
95  KinectUserList listOfUsers;
96  boost::mutex uListMutex;
97  boost::mutex updateMutex;
98  boost::mutex updateHandsMutex;
99  boost::mutex uFingersUpdate;
100  boost::mutex uGeneratorsCreate;
101  boost::mutex uSklMutex;
102  OpenNIUserList listOfAvalaibleUsers;
103 
104  int mId;
105  bool bConnected;
106  bool bMirror;
107  float msklSmoothing;
108  int iDistCutoff;
109  float fAngCutoff;
110 
111  // Device object
112  openni::Device NiDevice;
113 
114  cv::Size mframeSize;
115  cv::Mat mfingersBgr;
116 
117  Depth* mDepthGenerator;
118  Image* mImageGenerator;
119  User* mUserGenerator;
120  //Gesture* mGestureGenerator; // $AS: Add gesture and hands generators
121  //Hands* mHandsGenerator;
122 
123  bool CreateAndStartGenerators();
124  void StopAndDestroyGenerators();
125  void DetectUsers();
126  void DetectHands();
127 
128  virtual void onDeviceStateChanged(const openni::DeviceInfo* pInfo, openni::DeviceState state);
129  virtual void onDeviceConnected(const openni::DeviceInfo* pInfo);
130  virtual void onDeviceDisconnected(const openni::DeviceInfo* pInfo);
131 
132  protected:
133  KinectDevice();
134 };
135 
136 #endif
Kinect user handling. .
Definition: KinectUser.h:38
User generator handling. .
Definition: User.h:37
Image generator handling. .
Definition: Image.h:37
Create Singleton type. .
Definition: Thread.h:37
Depth generator handling. .
Definition: Depth.h:38
Kinect device handling. .
Definition: KinectDevice.h:39