Пример #1
0
        static void Main(string[] args)
        {
            XnMOpenNIContextEx ctx = new XnMOpenNIContextEx();
            ctx.InitFromXmlFile("openni.xml");

            /*
            var depthNode = ctx.FindExistingNode(XnMProductionNodeType.Depth) as XnMDepthGenerator;
            PrintNodeInfo(depthNode);
            */

            var imageNode = ctx.FindExistingNode(XnMProductionNodeType.Image) as XnMImageGenerator;
            PrintNodeInfo(imageNode);

            Console.WriteLine("Press ESC to exit.");

            var imageMD = new XnMImageMetaData();

            while(true)
            {
                ctx.WaitAndUpdateAll();

                imageNode.GetMetaData(imageMD);
                PrintImageMetaData(imageMD);

                Console.WriteLine("-----------------");
                if (Console.KeyAvailable)
                {
                    if (Console.ReadKey().Key == ConsoleKey.Escape)
                        break;
                }
            }
            ctx.Shutdown();
        }
Пример #2
0
 private static void PrintImageMetaData(XnMImageMetaData imageMD)
 {
     Console.WriteLine("FrameID: " + imageMD.FrameID);
     Console.WriteLine("FPS: " + imageMD.FPS);
     Console.WriteLine("PixelFormat: " + imageMD.PixelFormat);
     Console.WriteLine("BytesPerPixel: " + imageMD.BytesPerPixel);
     Console.WriteLine("XRes: " + imageMD.XRes);
     Console.WriteLine("YRes: " + imageMD.YRes);
     Console.WriteLine("XOffset: " + imageMD.XOffset);
     Console.WriteLine("YOffset: " + imageMD.YOffset);
 }
Пример #3
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;
            }
        }
Пример #4
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);
        }