private void PaintGray16(WriteableBitmap b, XnMDepthMetaData depthMeta) { b.Lock(); short* pDepthRow = (short*) depthMeta.Data; int nTexMapX = b.BackBufferStride / (b.Format.BitsPerPixel / 8); short* pTexRow = (short*) b.BackBuffer + depthMeta.YOffset*nTexMapX; for (int y = 0; y < depthMeta.YRes; y++) { short* pDepth = pDepthRow; short* pTex = pTexRow + depthMeta.XOffset; for (int x = 0; x < depthMeta.XRes; x++) { if (*pDepth != 0) { *pTex = (short) _depthHist[*pDepth]; } else { *pTex = 0; } pDepth++; pTex++; } pDepthRow += depthMeta.XRes; pTexRow += nTexMapX; } b.AddDirtyRect(new Int32Rect(0, 0, b.PixelWidth, b.PixelHeight)); b.Unlock(); }
private void PaintGray16(WriteableBitmap b, XnMDepthMetaData depthMeta) { b.Lock(); short *pDepthRow = (short *)depthMeta.Data; int nTexMapX = b.BackBufferStride / (b.Format.BitsPerPixel / 8); short *pTexRow = (short *)b.BackBuffer + depthMeta.YOffset * nTexMapX; for (int y = 0; y < depthMeta.YRes; y++) { short *pDepth = pDepthRow; short *pTex = pTexRow + depthMeta.XOffset; for (int x = 0; x < depthMeta.XRes; x++) { if (*pDepth != 0) { *pTex = (short)_depthHist[*pDepth]; } else { *pTex = 0; } pDepth++; pTex++; } pDepthRow += depthMeta.XRes; pTexRow += nTexMapX; } b.AddDirtyRect(new Int32Rect(0, 0, b.PixelWidth, b.PixelHeight)); b.Unlock(); }
public void Paint(XnMDepthMetaData depthMeta, WriteableBitmap b) { if (b.Format == PixelFormats.Gray16) PaintGray16(b, depthMeta); else if (b.Format == PixelFormats.Pbgra32) PaintPbgra32(b, depthMeta); }
private void InitOpenNi(AsyncStateData asyncData) { _niContext = new XnMOpenNIContextEx(); _niContext.InitFromXmlFile("openni.xml"); _imageNode = (XnMImageGenerator)_niContext.FindExistingNode(XnMProductionNodeType.Image); _imageMeta = new XnMImageMetaData(); _imageNode.GetMetaData(_imageMeta); // create the image bitmap source on asyncData.AsyncOperation.SynchronizationContext.Send( md => CreateImageBitmap(_imageMeta, out _rgbImageSource), null); // add depth node _depthNode = (XnMDepthGenerator)_niContext.FindExistingNode(XnMProductionNodeType.Depth); _depthMeta = new XnMDepthMetaData(); _depthNode.GetMetaData(_depthMeta); asyncData.AsyncOperation.SynchronizationContext.Send( state => CreateImageBitmap(_depthMeta, out _depthImageSource, PixelFormats.Pbgra32), null); // add scene node _sceneNode = (XnMSceneAnalyzer)_niContext.FindExistingNode(XnMProductionNodeType.Scene); _sceneMeta = new XnMSceneMetaData(); _sceneNode.GetMetaData(_sceneMeta); asyncData.AsyncOperation.SynchronizationContext.Send( state => CreateImageBitmap(_sceneMeta, out _sceneImageSource, PixelFormats.Pbgra32), null); }
public void Paint(XnMDepthMetaData depthMeta, WriteableBitmap b) { if (b.Format == PixelFormats.Gray16) { PaintGray16(b, depthMeta); } else if (b.Format == PixelFormats.Pbgra32) { PaintPbgra32(b, depthMeta); } }
private bool InitOpenNi(AsyncStateData asyncData) { try { _niContext = new XnMOpenNIContextEx(); _niContext.InitFromXmlFile("openni.xml"); _imageNode = (XnMImageGenerator)_niContext.FindExistingNode(XnMProductionNodeType.Image); _imageMeta = new XnMImageMetaData(); _imageNode.GetMetaData(_imageMeta); if (_imageMeta.PixelFormat != XnMPixelFormat.Rgb24) { throw new InvalidOperationException("Only RGB24 pixel format is supported"); } // add depth node _depthNode = (XnMDepthGenerator)_niContext.FindExistingNode(XnMProductionNodeType.Depth); _depthMeta = new XnMDepthMetaData(); _depthNode.GetMetaData(_depthMeta); if (_depthMeta.PixelFormat != XnMPixelFormat.Grayscale16Bit) { throw new InvalidOperationException("Only 16-bit depth precission is supported"); } if (_depthMeta.XRes != _imageMeta.XRes || _depthMeta.YRes != _imageMeta.YRes) { throw new InvalidOperationException("Image and depth map must have the same resolution"); } // add scene node _sceneNode = (XnMSceneAnalyzer)_niContext.FindExistingNode(XnMProductionNodeType.Scene); _sceneMeta = new XnMSceneMetaData(); _sceneNode.GetMetaData(_sceneMeta); asyncData.AsyncOperation.SynchronizationContext.Send( delegate { UpdateCameraInfo(); UpdateFrameData(); InvokeTrackinkgStarted(EventArgs.Empty); }, null); return(true); } catch (Exception ex) { return(false); } }
private void PaintPbgra32(WriteableBitmap b, XnMDepthMetaData depthMeta) { b.Lock(); short *pDepthRow = (short *)depthMeta.Data; int nTexMapX = b.BackBufferStride; byte *pTexRow = (byte *)b.BackBuffer + depthMeta.YOffset * nTexMapX; for (int y = 0; y < depthMeta.YRes; y++) { short *pDepth = pDepthRow; byte * pTex = pTexRow + depthMeta.XOffset; for (int x = 0; x < depthMeta.XRes; x++) { if (*pDepth != 0) { // paint as yellow byte val = (byte)(_depthHist[*pDepth] / 256); pTex[0] = 0; // B pTex[1] = val; // G pTex[2] = val; // R pTex[3] = 255; // A } else { pTex[0] = 0; // B pTex[1] = 0; // G pTex[2] = 0; // R pTex[3] = 0; // A } pDepth++; pTex += 4; } pDepthRow += depthMeta.XRes; pTexRow += nTexMapX; } b.AddDirtyRect(new Int32Rect(0, 0, b.PixelWidth, b.PixelHeight)); b.Unlock(); }
public void Update(XnMDepthMetaData depthMeta) { if (_depthHist == null) { _depthHist = new float[MaxDepth]; } Array.Clear(_depthHist, 0, _depthHist.Length); int numPoints = 0; short *ptrDepth = (short *)depthMeta.Data; for (int y = 0; y < depthMeta.YRes; y++) { for (int x = 0; x < depthMeta.XRes; x++) { if (*ptrDepth != 0) { _depthHist[*ptrDepth]++; numPoints++; } ptrDepth++; } } for (int i = 1; i < MaxDepth; i++) { _depthHist[i] += _depthHist[i - 1]; } if (numPoints > 0) { for (int nIndex = 1; nIndex < MaxDepth; nIndex++) { _depthHist[nIndex] = Int16.MaxValue * (1.0f - (_depthHist[nIndex] / numPoints)); } } }
public void Update(XnMDepthMetaData depthMeta) { if (_depthHist == null) _depthHist = new float[MaxDepth]; Array.Clear(_depthHist, 0, _depthHist.Length); int numPoints = 0; short* ptrDepth = (short*)depthMeta.Data; for (int y = 0; y < depthMeta.YRes; y++) { for (int x = 0; x < depthMeta.XRes; x++) { if (*ptrDepth != 0) { _depthHist[*ptrDepth]++; numPoints++; } ptrDepth++; } } for (int i = 1; i < MaxDepth; i++) { _depthHist[i] += _depthHist[i - 1]; } if (numPoints > 0) { for (int nIndex = 1; nIndex < MaxDepth; nIndex++) { _depthHist[nIndex] = Int16.MaxValue * (1.0f - (_depthHist[nIndex] / numPoints)); } } }
private bool InitOpenNi(AsyncStateData asyncData) { try { _niContext = new XnMOpenNIContextEx(); _niContext.InitFromXmlFile("openni.xml"); _imageNode = (XnMImageGenerator)_niContext.FindExistingNode(XnMProductionNodeType.Image); _imageMeta = new XnMImageMetaData(); _imageNode.GetMetaData(_imageMeta); if (_imageMeta.PixelFormat != XnMPixelFormat.Rgb24) throw new InvalidOperationException("Only RGB24 pixel format is supported"); // add depth node _depthNode = (XnMDepthGenerator)_niContext.FindExistingNode(XnMProductionNodeType.Depth); _depthMeta = new XnMDepthMetaData(); _depthNode.GetMetaData(_depthMeta); if (_depthMeta.PixelFormat != XnMPixelFormat.Grayscale16Bit) throw new InvalidOperationException("Only 16-bit depth precission is supported"); if (_depthMeta.XRes != _imageMeta.XRes || _depthMeta.YRes != _imageMeta.YRes) throw new InvalidOperationException("Image and depth map must have the same resolution"); // add scene node _sceneNode = (XnMSceneAnalyzer)_niContext.FindExistingNode(XnMProductionNodeType.Scene); _sceneMeta = new XnMSceneMetaData(); _sceneNode.GetMetaData(_sceneMeta); asyncData.AsyncOperation.SynchronizationContext.Send( delegate { UpdateCameraInfo(); UpdateFrameData(); InvokeTrackinkgStarted(EventArgs.Empty); }, null); return true; } catch (Exception ex) { return false; } }
private void InitOpenNi(AsyncStateData asyncData) { _niContext = new XnMOpenNIContextEx(); _niContext.InitFromXmlFile("openni.xml"); _imageNode = (XnMImageGenerator)_niContext.FindExistingNode(XnMProductionNodeType.Image); _imageMeta = new XnMImageMetaData(); _imageNode.GetMetaData(_imageMeta); // create the image bitmap source on asyncData.AsyncOperation.SynchronizationContext.Send( md => CreateImageBitmap(_imageMeta, out _rgbImageSource), null); // add depth node _depthNode = (XnMDepthGenerator) _niContext.FindExistingNode(XnMProductionNodeType.Depth); _depthMeta = new XnMDepthMetaData(); _depthNode.GetMetaData(_depthMeta); asyncData.AsyncOperation.SynchronizationContext.Send( state => CreateImageBitmap(_depthMeta, out _depthImageSource, PixelFormats.Pbgra32), null); // add scene node _sceneNode = (XnMSceneAnalyzer) _niContext.FindExistingNode(XnMProductionNodeType.Scene); _sceneMeta = new XnMSceneMetaData(); _sceneNode.GetMetaData(_sceneMeta); asyncData.AsyncOperation.SynchronizationContext.Send( state => CreateImageBitmap(_sceneMeta, out _sceneImageSource, PixelFormats.Pbgra32), null); }
private void PaintPbgra32(WriteableBitmap b, XnMDepthMetaData depthMeta) { b.Lock(); short* pDepthRow = (short*)depthMeta.Data; int nTexMapX = b.BackBufferStride; byte* pTexRow = (byte*)b.BackBuffer + depthMeta.YOffset * nTexMapX; for (int y = 0; y < depthMeta.YRes; y++) { short* pDepth = pDepthRow; byte* pTex = pTexRow + depthMeta.XOffset; for (int x = 0; x < depthMeta.XRes; x++) { if (*pDepth != 0) { // paint as yellow byte val = (byte) (_depthHist[*pDepth]/256); pTex[0] = 0; // B pTex[1] = val; // G pTex[2] = val; // R pTex[3] = 255; // A } else { pTex[0] = 0; // B pTex[1] = 0; // G pTex[2] = 0; // R pTex[3] = 0; // A } pDepth++; pTex+=4; } pDepthRow += depthMeta.XRes; pTexRow += nTexMapX; } b.AddDirtyRect(new Int32Rect(0, 0, b.PixelWidth, b.PixelHeight)); b.Unlock(); }