Go to the documentation of this file.00001 #include "openni.h"
00002
00003 namespace pangolin
00004 {
00005
00006 OpenNiVideo::OpenNiVideo(OpenNiSensorType s1, OpenNiSensorType s2)
00007 :s1(s1), s2(s2)
00008 {
00009 XnStatus nRetVal = XN_STATUS_OK;
00010 nRetVal = context.Init();
00011 if (nRetVal != XN_STATUS_OK)
00012 {
00013 std::cerr << "context.Init: " << xnGetStatusString(nRetVal) << std::endl;
00014 }
00015
00016 XnMapOutputMode mapMode;
00017 mapMode.nXRes = XN_VGA_X_RES;
00018 mapMode.nYRes = XN_VGA_Y_RES;
00019 mapMode.nFPS = 30;
00020
00021 switch(s1)
00022 {
00023 case OpenNiDepth:
00024 case OpenNiIr:
00025 s1SizeBytes = XN_VGA_X_RES * XN_VGA_Y_RES * sizeof(XnDepthPixel);
00026 break;
00027 case OpenNiRgb:
00028 s1SizeBytes = XN_VGA_X_RES * XN_VGA_Y_RES * sizeof(XnUInt8) * 3;
00029 break;
00030 case OpenNiUnassigned:
00031 default:
00032 s1SizeBytes = 0;
00033 }
00034
00035 switch(s2)
00036 {
00037 case OpenNiDepth:
00038 case OpenNiIr:
00039 s2SizeBytes = XN_VGA_X_RES * XN_VGA_Y_RES * sizeof(XnDepthPixel);
00040 break;
00041 case OpenNiRgb:
00042 s1SizeBytes = XN_VGA_X_RES * XN_VGA_Y_RES * sizeof(XnUInt8) * 3;
00043 break;
00044 case OpenNiUnassigned:
00045 default:
00046 s2SizeBytes = 0;
00047 }
00048
00049 sizeBytes = s1SizeBytes + s2SizeBytes;
00050
00051 if( s1 == OpenNiDepth || s2 == OpenNiDepth )
00052 {
00053 nRetVal = depthNode.Create(context);
00054 if (nRetVal != XN_STATUS_OK)
00055 {
00056 std::cerr << "depthNode.Create: " << xnGetStatusString(nRetVal) << std::endl;
00057 }
00058 else
00059 {
00060 nRetVal = depthNode.SetMapOutputMode(mapMode);
00061 if (nRetVal != XN_STATUS_OK)
00062 {
00063 std::cerr << "depthNode.SetMapOutputMode: " << xnGetStatusString(nRetVal) << std::endl;
00064 }
00065 }
00066 }
00067
00068 if( s1 == OpenNiIr || s2 == OpenNiIr )
00069 {
00070 nRetVal = irNode.Create(context);
00071 if (nRetVal != XN_STATUS_OK)
00072 {
00073 std::cerr << "irNode.Create: " << xnGetStatusString(nRetVal) << std::endl;
00074 }
00075 else
00076 {
00077 nRetVal = irNode.SetMapOutputMode(mapMode);
00078 if (nRetVal != XN_STATUS_OK)
00079 {
00080 std::cerr << "irNode.SetMapOutputMode: " << xnGetStatusString(nRetVal) << std::endl;
00081 }
00082 }
00083 }
00084
00085 if( s1 == OpenNiRgb || s2 == OpenNiRgb )
00086 {
00087 nRetVal = imageNode.Create(context);
00088 if (nRetVal != XN_STATUS_OK)
00089 {
00090 std::cerr << "imageNode.Create: " << xnGetStatusString(nRetVal) << std::endl;
00091 }
00092 else
00093 {
00094 nRetVal = imageNode.SetMapOutputMode(mapMode);
00095 if (nRetVal != XN_STATUS_OK)
00096 {
00097 std::cerr << "imageNode.SetMapOutputMode: " << xnGetStatusString(nRetVal) << std::endl;
00098 }
00099 }
00100 }
00101
00102 Start();
00103 }
00104
00105 OpenNiVideo::~OpenNiVideo()
00106 {
00107 context.Shutdown();
00108 }
00109
00110 unsigned OpenNiVideo::Width() const
00111 {
00112 return XN_VGA_X_RES;
00113 }
00114
00115 unsigned OpenNiVideo::Height() const
00116 {
00117 return XN_VGA_Y_RES;
00118 }
00119
00120 size_t OpenNiVideo::SizeBytes() const
00121 {
00122 return sizeBytes;
00123 }
00124
00125 std::string OpenNiVideo::PixFormat() const
00126 {
00127 if(s1 == OpenNiRgb)
00128 {
00129 return "RGB24";
00130 }
00131 else
00132 {
00133 return "GRAY16LE";
00134 }
00135 }
00136
00137 void OpenNiVideo::Start()
00138 {
00139 XnStatus nRetVal = context.StartGeneratingAll();
00140 }
00141
00142 void OpenNiVideo::Stop()
00143 {
00144 context.StopGeneratingAll();
00145 }
00146
00147 bool OpenNiVideo::GrabNext( unsigned char* image, bool wait )
00148 {
00149 ;
00150
00151 XnStatus nRetVal = context.WaitAnyUpdateAll();
00152
00153
00154 if (nRetVal != XN_STATUS_OK)
00155 {
00156 std::cerr << "Failed updating data: " << xnGetStatusString(nRetVal) << std::endl;
00157 }
00158 else
00159 {
00160 if(s1==OpenNiDepth)
00161 {
00162 const XnDepthPixel* pDepthMap = depthNode.GetDepthMap();
00163 memcpy(image,pDepthMap, s1SizeBytes );
00164 }
00165 else if(s1==OpenNiIr)
00166 {
00167 const XnIRPixel* pIrMap = irNode.GetIRMap();
00168 memcpy(image,pIrMap, s1SizeBytes);
00169 }
00170 else if(s1==OpenNiRgb)
00171 {
00172 const XnUInt8* pImageMap = imageNode.GetImageMap();
00173 memcpy(image,pImageMap, s1SizeBytes);
00174 }
00175
00176 if(s2==OpenNiDepth)
00177 {
00178 const XnDepthPixel* pDepthMap = depthNode.GetDepthMap();
00179 memcpy(image+s1SizeBytes,pDepthMap, s2SizeBytes);
00180 }
00181 else if(s2==OpenNiIr)
00182 {
00183 const XnIRPixel* pIrMap = irNode.GetIRMap();
00184 memcpy(image+s1SizeBytes,pIrMap, s2SizeBytes);
00185 }
00186 else if(s2==OpenNiRgb)
00187 {
00188 const XnUInt8* pImageMap = imageNode.GetImageMap();
00189 memcpy(image+s1SizeBytes,pImageMap, s2SizeBytes);
00190 }
00191
00192
00193 }
00194 }
00195
00196 bool OpenNiVideo::GrabNewest( unsigned char* image, bool wait )
00197 {
00198 return GrabNext(image,wait);
00199 }
00200
00201 }
00202