コード例 #1
0
        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);
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        public void Paint(XnMSceneMetaData sceneMeta, WriteableBitmap b)
        {
            b.Lock();

            unsafe
            {
                short *pLabelRow = (short *)sceneMeta.Data;

                int   nTexMapX = b.BackBufferStride;
                byte *pTexRow  = (byte *)b.BackBuffer + sceneMeta.YOffset * nTexMapX;

                for (int y = 0; y < sceneMeta.YRes; y++)
                {
                    short *pLabel = pLabelRow;
                    byte * pTex   = pTexRow + sceneMeta.XOffset;

                    for (int x = 0; x < sceneMeta.XRes; x++)
                    {
                        //var label = sceneMeta.GetLabel((uint) x, (uint) y);
                        var label = (*pLabel);
                        if (label != 0)
                        {
                            var c = _colors[label % _colors.Length];
                            pTex[0] = c.B;  // B
                            pTex[1] = c.G;  // G
                            pTex[2] = c.R;  // R
                            pTex[3] = c.A;  // A
                        }
                        else
                        {
                            pTex[0] = 0;  // B
                            pTex[1] = 0;  // G
                            pTex[2] = 0;  // R
                            pTex[3] = 0;  // A
                        }
                        pLabel++;
                        pTex += 4;
                    }
                    pLabelRow += sceneMeta.XRes;
                    pTexRow   += nTexMapX;
                }
            }
            b.AddDirtyRect(new Int32Rect(0, 0, b.PixelWidth, b.PixelHeight));
            b.Unlock();
        }
コード例 #4
0
ファイル: SceneMap.cs プロジェクト: kobush/ManagedOpenNI
        public void Paint(XnMSceneMetaData sceneMeta, WriteableBitmap b)
        {
            b.Lock();

            unsafe
            {
                short* pLabelRow = (short*)sceneMeta.Data;

                int nTexMapX = b.BackBufferStride;
                byte* pTexRow = (byte*)b.BackBuffer + sceneMeta.YOffset * nTexMapX;

                for (int y = 0; y < sceneMeta.YRes; y++)
                {
                    short* pLabel = pLabelRow;
                    byte* pTex = pTexRow + sceneMeta.XOffset;

                    for (int x = 0; x < sceneMeta.XRes; x++)
                    {
                        //var label = sceneMeta.GetLabel((uint) x, (uint) y);
                        var label = (*pLabel);
                        if (label != 0)
                        {
                            var c = _colors[label%_colors.Length];
                            pTex[0] = c.B;  // B
                            pTex[1] = c.G;  // G
                            pTex[2] = c.R;  // R
                            pTex[3] = c.A;  // A
                        }
                        else
                        {
                            pTex[0] = 0;  // B
                            pTex[1] = 0;  // G
                            pTex[2] = 0;  // R
                            pTex[3] = 0;  // A
                        }
                        pLabel++;
                        pTex += 4;
                    }
                    pLabelRow += sceneMeta.XRes;
                    pTexRow += nTexMapX;
                }
            }
            b.AddDirtyRect(new Int32Rect(0, 0, b.PixelWidth, b.PixelHeight));
            b.Unlock();
        }
コード例 #5
0
ファイル: KinectTracker.cs プロジェクト: kobush/ManagedOpenNI
        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;
            }
        }
コード例 #6
0
 public void Update(XnMSceneMetaData sceneMeta)
 {
 }
コード例 #7
0
ファイル: KinectTracker.cs プロジェクト: kobush/ManagedOpenNI
        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);
        }
コード例 #8
0
ファイル: SceneMap.cs プロジェクト: kobush/ManagedOpenNI
 public void Update(XnMSceneMetaData sceneMeta)
 {
 }