OpenNIGrabber.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifdef INVT_HAVE_OPENNI
00039
00040 #include "Devices/OpenNIGrabber.H"
00041 #include "Devices/DeviceOpts.H"
00042
00043 #define MYLOGID itsFd
00044
00045 #define CHECK_RC(rc, what) \
00046 if (rc != XN_STATUS_OK) \
00047 { \
00048 LERROR("%s failed: %s\n", what, xnGetStatusString(rc)); \
00049 }
00050
00051
00052
00053 OpenNIGrabber::OpenNIGrabber(OptionManager& mgr, const std::string& descrName,
00054 const std::string& tagName, const ParamFlag flags) :
00055 FrameIstream(mgr, descrName, tagName),
00056
00057
00058
00059
00060
00061 itsDims(&OPT_FrameGrabberDims, this, Dims(GL_WIN_SIZE_X, GL_WIN_SIZE_Y), flags),
00062 itsListener()
00063 {
00064
00065 }
00066
00067
00068 void OpenNIGrabber::start1()
00069 {
00070
00071 NI_DMap = NULL;
00072 NI_DMapX = 0;
00073 NI_DMapY = 0;
00074
00075
00076 XnStatus rc;
00077
00078
00079 rc = NI_context.InitFromXmlFile(SAMPLE_XML_PATH);
00080 CHECK_RC(rc, "InitFromXmlFile");
00081
00082
00083 rc = NI_context.FindExistingNode(XN_NODE_TYPE_DEPTH, NI_depth);
00084 rc = NI_context.FindExistingNode(XN_NODE_TYPE_IMAGE, NI_image);
00085
00086
00087 NI_depth.GetMetaData(NI_depthMD);
00088 NI_image.GetMetaData(NI_imageMD);
00089
00090
00091 NI_DMapX = (((unsigned short)(NI_depthMD.XRes()-1) / 512) + 1) * 512;
00092 NI_DMapY = (((unsigned short)(NI_depthMD.YRes()-1) / 512) + 1) * 512;
00093 NI_DMap = (XnUInt16*)malloc(NI_DMapX * NI_DMapY * sizeof(XnUInt16));
00094 }
00095
00096
00097 void OpenNIGrabber::stop2()
00098 {
00099
00100 NI_context.Shutdown();
00101 }
00102
00103
00104 OpenNIGrabber::~OpenNIGrabber()
00105 { }
00106
00107
00108 void OpenNIGrabber::setListener(rutz::shared_ptr<FrameListener> listener)
00109 { itsListener = listener; }
00110
00111
00112 GenericFrameSpec OpenNIGrabber::peekFrameSpec()
00113 {
00114 GenericFrameSpec result;
00115
00116 result.nativeType = GenericFrame::RGBD;
00117 result.videoFormat = VIDFMT_RGB24;
00118 result.videoByteSwap = false;
00119 result.dims = itsDims.getVal();
00120 result.floatFlags = 0;
00121
00122 return result;
00123 }
00124
00125
00126 GenericFrame OpenNIGrabber::readFrame()
00127 {
00128 XnStatus rc = XN_STATUS_OK;
00129
00130
00131 rc = NI_context.WaitAnyUpdateAll();
00132 if (rc != XN_STATUS_OK)
00133 {
00134 LFATAL("Read failed: %s\n", xnGetStatusString(rc));
00135 }
00136
00137
00138 NI_depth.GetMetaData(NI_depthMD);
00139 NI_image.GetMetaData(NI_imageMD);
00140
00141
00142 const XnDepthPixel* pDepth = NI_depthMD.Data();
00143 XnUInt16* d_Tex = NI_DMap;
00144
00145 for (XnUInt y = 0; y < NI_depthMD.YRes(); ++y)
00146 {
00147 for (XnUInt x = 0; x < NI_depthMD.XRes(); ++x, ++pDepth, ++d_Tex)
00148 {
00149 if (*pDepth != 0)
00150 {
00151 int nHistValue = (*pDepth)/4;
00152 *d_Tex = nHistValue;
00153 }
00154 }
00155 }
00156 Image<uint16> img(static_cast<uint16*>(NI_DMap), NI_depthMD.XRes(), NI_depthMD.YRes());
00157 {
00158 itsDepthImage = img;
00159 }
00160
00161
00162
00163 Image<PixRGB<byte> > img2((PixRGB<byte>*)(NI_imageMD.RGB24Data()), NI_imageMD.XRes(), NI_imageMD.YRes());
00164 {
00165 itsColorImage = img2;
00166 }
00167
00168
00169 GenericFrame NIframe(itsColorImage, itsDepthImage);
00170
00171 return NIframe;
00172 }
00173
00174 xn::Context* OpenNIGrabber::getContext()
00175 {
00176 return &NI_context;
00177 }
00178
00179 #endif
00180
00181
00182
00183
00184
00185