Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
VideoSource_Kinect2Net.hh
1 #ifndef VideoSource_Kinect2Net_HH
2 #define VideoSource_Kinect2Net_HH
3 
4 #include <VideoSource/VideoSource_Base.hh>
5 #include <Image/Camera.hh>
6 #include <semaphore.h>
7 #include <NetworkComm/CScommClient.hh>
8 
9 namespace BIAS
10 {
11  /** @class VideoSource_Kinect2Net
12  @brief Provides remote access to a Microsoft Kinect2 camera.
13  @author fkellner 04/15
14  */
15  class BIASVideoSource_EXPORT VideoSource_Kinect2Net : public VideoSource
16  {
17  public:
18 
20 
21  virtual ~VideoSource_Kinect2Net();
22 
23  /// Opens first device found, OpenDevice(0)
24  /// @return Returns -1 if no device is available and -2 if an error happened while opening
25  virtual int OpenDevice();
26 
27  /// Opens device by id. Use GetNumDevices() to determine the number of available Kinect2s
28  /// @return Returns -1 if no device is available and -2 if an error happened while opening
29  virtual int OpenDevice(std::string host, int port=8090);
30 
31  /// Close device, if no other kinect cameras are in use, context is deleted (i.e. close usb bus connection)
32  virtual int CloseDevice();
33 
34  /// Start grabbing
35  virtual int PreGrab();
36 
37  /// Stop grabbing
38  virtual int PostGrab();
39 
40  /// kinect 2 depth image will be 512x424, float in Millimeters
41  virtual int InitDepthImage(BIAS::ImageBase &Image);
42 
43  /// kinect 2 ir image will be 512x424, single channel unsigned char
44  virtual int InitIrImage(BIAS::ImageBase &Image);
45 
46  /// grab the ir sum image computed from the phase images.
47  virtual int GrabSingleIR(BIAS::Camera <float> &image);
48 
49  /// grab the depth image (slow). Use this function only if no high framerates are required, since
50  /// the conversion from ir to depth image is done on the cpu and requires a lot computation.
51  virtual int GrabSingleDepth(BIAS::Camera <float> &image);
52 
53  /// Return the number of available Kinect 2 devices
54  virtual int GetNumDevices();
55 
56  /// No standard capabilities here
57  virtual int GetCapabilities(VideoSourceCapabilities &caps);
58 
59  /// No standard capabilities here
60  virtual int GetCapabilities(const char *device, VideoSourceCapabilities &caps);
61 
62  protected:
63 
64  static void* runner(void *args);
65 
66  private:
67 
68  static const int buffersize_ = 4;
69 
70  class imbuffer
71  {
72  public:
73  imbuffer() : curProd(0), curCons(0) {
74  sem_init(&sProd,true,buffersize_);
75  sem_init(&sCons,true,0);
76  for (int i=0;i<buffersize_;i++) buffer[i].Init(512,424,1);
77  }
78  Image<float> buffer[buffersize_];
79  sem_t sProd;
80  sem_t sCons;
81  int curProd, curCons;
82  };
83 
84  imbuffer depthbuffer_;
85  imbuffer irbuffer_;
86  int numDevices_;
87 
88  pthread_t grabThread_;
89 
90  CScommClient client_;
91  std::string host_;
92  int port_;
93  bool stopThread_;
94 
95  };
96 
97 }
98 
99 #endif // VideoSource_Kinect2Net_HH
Defines a common interface to different devices.
class for sending/receiving data between clients and servers
Definition: CScommClient.hh:54
The image template class for specific storage types.
Definition: Image.hh:78
Checks for VideoSource capabilities.
This is the base class for images in BIAS.
Definition: ImageBase.hh:102
Provides remote access to a Microsoft Kinect2 camera.