1 #pragma once
2 
3 #include <pangolin/pangolin.h>
4 
5 #include <pangolin/video/video.h>
6 #include <pangolin/video/drivers/openni_common.h>
7 
8 // Workaround poor OpenNI Platform test on Linux before including XnCppWrapper.h
9 // See https://github.com/dennishamester/OpenNI/commit/ca99f6181234c682bba42a6ba
10 #ifdef _LINUX_
11 #define linux 1
12 #endif // _LINUX_
13 
14 // OpenNI generates SO MANY warnings, we'll just disable all for this header(!)
15 // GCC and clang will listen to this pramga.
16 #ifndef _MSVC_
17 #pragma GCC system_header
18 #endif
19 #include <XnCppWrapper.h>
20 
21 namespace pangolin
22 {
23 
24 //! Interface to video capture sources
25 struct PANGOLIN_EXPORT OpenNiVideo : public VideoInterface
26 {
27 public:
28     OpenNiVideo(OpenNiSensorType s1, OpenNiSensorType s2, ImageDim dim = ImageDim(640,480), int fps = 30);
29     ~OpenNiVideo();
30 
31     //! Implement VideoInput::Start()
32     void Start();
33 
34     //! Implement VideoInput::Stop()
35     void Stop();
36 
37     //! Implement VideoInput::SizeBytes()
38     size_t SizeBytes() const;
39 
40     //! Implement VideoInput::Streams()
41     const std::vector<StreamInfo>& Streams() const;
42 
43     //! Implement VideoInput::GrabNext()
44     bool GrabNext( unsigned char* image, bool wait = true );
45 
46     //! Implement VideoInput::GrabNewest()
47     bool GrabNewest( unsigned char* image, bool wait = true );
48 
SetAutoExposureOpenNiVideo49     void SetAutoExposure(bool enabled)
50     {
51 #if XN_MINOR_VERSION > 5 || (XN_MINOR_VERSION == 5 && XN_BUILD_VERSION >= 7)
52         if(imageNode.IsValid()) {
53             imageNode.GetAutoExposureCap().Set(enabled ? 1 : 0);
54         }
55 #else
56         throw pangolin::VideoException("SetAutoExposure Not supported for this version of OpenNI.");
57 #endif
58     }
59 
60 protected:
61     std::vector<StreamInfo> streams;
62     OpenNiSensorType sensor_type[2];
63 
64     xn::Context context;
65     xn::DepthGenerator depthNode;
66     xn::ImageGenerator imageNode;
67     xn::IRGenerator irNode;
68 
69     size_t sizeBytes;
70 };
71 
72 }
73