Exemplo n.º 1
0
 public KinectImageStream(IntPtr streamHandle, IntPtr waitHandle
     , KinectImageResolution resolution, int bytesPerPixel):base(1000)
 {
     _phStreamHandle = streamHandle;
     _resolution = resolution;
     _bytesPerPixel = bytesPerPixel;
 }
Exemplo n.º 2
0
        void StartColorImageHandler(KinectImageResolution resolution)
        {
            var bitmap = new Bitmap(resolution.Width(), resolution.Height());
            var buffer = new Byte[resolution.Width() * resolution.Height() * 4];
            Action <KinectBaseImageFrame> UpdatePictureBox = frame =>
            {
                frame.CopyTo(buffer);
                bitmap.SetPixels(buffer);
                pictureBoxForImage.Image = bitmap;
            };

            _colorImageHandler = _timerEvent
                                 .Where(_ => _sensor.ColorImageStream != null)
                                 .Subscribe(_ => Observable.Using(
                                                () => _sensor.ColorImageStream.GetFrame()
                                                , frame => Observable.Return(frame)
                                                )
                                            .Where(frame => frame != null)
                                            .Subscribe(
                                                frame => UpdatePictureBox(frame)
                                                , ex => { } // Console.WriteLine("error")
                                                )
                                            )
            ;
        }
Exemplo n.º 3
0
        public static int Width(this KinectImageResolution resolution)
        {
            switch (resolution)
            {
            case KinectImageResolution.Resolution_80x60:
                return(80);

            case KinectImageResolution.Resolution_320x240:
                return(320);

            case KinectImageResolution.Resolution_640x480:
                return(640);

            case KinectImageResolution.Resolution_1280x960:
                return(1280);

            case KinectImageResolution.Resolution_512x424:
                return(512);

            case KinectImageResolution.Resolution_1920x1080:
                return(1920);

            default:
                return(0);
            }
        }
Exemplo n.º 4
0
 public KinectImageStream(IntPtr streamHandle, IntPtr waitHandle
                          , KinectImageResolution resolution, int bytesPerPixel) : base(1000)
 {
     _phStreamHandle = streamHandle;
     _resolution     = resolution;
     _bytesPerPixel  = bytesPerPixel;
 }
Exemplo n.º 5
0
        public static int Height(this KinectImageResolution resolution)
        {
            switch (resolution)
            {
            case KinectImageResolution.Resolution_80x60:
                return(60);

            case KinectImageResolution.Resolution_320x240:
                return(240);

            case KinectImageResolution.Resolution_640x480:
                return(480);

            case KinectImageResolution.Resolution_1280x960:
                return(960);

            case KinectImageResolution.Resolution_512x424:
                return(424);

            case KinectImageResolution.Resolution_1920x1080:
                return(1080);

            default:
                return(0);
            }
        }
Exemplo n.º 6
0
        void CreateColorImageStream(KinectImageResolution resolution)
        {
            StopColorImage();
            if (resolution == KinectImageResolution.None)
            {
                return;
            }

            _colorImageStream = new V2ImageStream(Sensor);
        }
Exemplo n.º 7
0
        void CreateIndexImageStream(KinectImageResolution resolution)
        {
            StopIndexImage();
            if (resolution == KinectImageResolution.None)
            {
                return;
            }

            _indexImageStream = new V2BodyIndexStream(Sensor);
        }
Exemplo n.º 8
0
        void CreateDepthImageStream(KinectImageResolution resolution)
        {
            StopDepthImage();
            if (resolution == KinectImageResolution.None)
            {
                return;
            }

            _depthImageStream = new V2DepthStream(Sensor);
        }
Exemplo n.º 9
0
        void CreateColorImageStream(KinectImageResolution resolution)
        {
            StopColorImage();
            if (resolution == KinectImageResolution.None)
            {
                return;
            }

            _colorImageStream = new V2ImageStream(Sensor);
        }
Exemplo n.º 10
0
        void CreateColorImageStream(IntPtr waitHandle, KinectImageResolution resolution)
        {
            StopColorImage();
            if (resolution == KinectImageResolution.None)
            {
                return;
            }

            var type = Nui.NuiImageType.Color;
            IntPtr phStreamHandle=_sensor.NuiImageStreamOpen(type, resolution.ToNui()
                , 0
                , 2, waitHandle);
            _colorImageStream = new KinectImageStream(phStreamHandle, waitHandle, resolution, 4);
        }
Exemplo n.º 11
0
        void CreateDepthImageStream(IntPtr waitHandle, KinectImageResolution resolution)
        {
            StopDepthImage();
            if (resolution == KinectImageResolution.None)
            {
                return;
            }

            var    type           = Nui.NuiImageType.DepthAndPlayerIndex;
            IntPtr phStreamHandle = _sensor.NuiImageStreamOpen(type, resolution.ToNui()
                                                               , 0, 2, waitHandle);

            _depthImageStream = new KinectImageStream(phStreamHandle, waitHandle, resolution, 2);
        }
Exemplo n.º 12
0
        void CreateColorImageStream(IntPtr waitHandle, KinectImageResolution resolution)
        {
            StopColorImage();
            if (resolution == KinectImageResolution.None)
            {
                return;
            }

            var    type           = Nui.NuiImageType.Color;
            IntPtr phStreamHandle = _sensor.NuiImageStreamOpen(type, resolution.ToNui()
                                                               , 0
                                                               , 2, waitHandle);

            _colorImageStream = new KinectImageStream(phStreamHandle, waitHandle, resolution, 4);
        }
Exemplo n.º 13
0
        public static Nui.NuiImageResolution ToNui(this KinectImageResolution resolution)
        {
            switch (resolution)
            {
            case KinectImageResolution.Resolution_80x60:
                return(Nui.NuiImageResolution.resolution80x60);

            case KinectImageResolution.Resolution_320x240:
                return(Nui.NuiImageResolution.resolution320x240);

            case KinectImageResolution.Resolution_640x480:
                return(Nui.NuiImageResolution.resolution640x480);

            case KinectImageResolution.Resolution_1280x960:
                return(Nui.NuiImageResolution.resolution1280x1024);

            default:
                return(Nui.NuiImageResolution.resolutionInvalid);
            }
        }
Exemplo n.º 14
0
        void CreateDepthImageStream(IntPtr waitHandle, KinectImageResolution resolution)
        {
            StopDepthImage();
            if (resolution == KinectImageResolution.None)
            {
                return;
            }

            var type = Nui.NuiImageType.DepthAndPlayerIndex;
            IntPtr phStreamHandle = _sensor.NuiImageStreamOpen(type, resolution.ToNui()
                , 0, 2, waitHandle);
            _depthImageStream = new KinectImageStream(phStreamHandle, waitHandle, resolution, 2);
        }
Exemplo n.º 15
0
        void StartColorImageHandler(KinectImageResolution resolution)
        {
            var bitmap = new Bitmap(resolution.Width(), resolution.Height());
            var buffer=new Byte[resolution.Width() * resolution.Height() *4 ];
            Action<KinectBaseImageFrame> UpdatePictureBox = frame =>
            {
                frame.CopyTo(buffer);
                bitmap.SetPixels(buffer);
                pictureBoxForImage.Image = bitmap;
            };

            _colorImageHandler = _timerEvent
                .Where(_ => _sensor.ColorImageStream != null)
                .Subscribe(_ => Observable.Using(
                    () => _sensor.ColorImageStream.GetFrame()
                    , frame => Observable.Return(frame)
                    )
                    .Where(frame => frame != null)
                    .Subscribe(
                        frame => UpdatePictureBox(frame)
                        , ex => { } // Console.WriteLine("error")
                    )
                )
                ;
        }
Exemplo n.º 16
0
        void StartDepthHandler(Int32 apiVersion, KinectImageResolution resolution)
        {
            var bitmap = new Bitmap(resolution.Width(), resolution.Height());
            var buffer = new Int16[resolution.Width() * resolution.Height()];


            if (apiVersion == 1)
            {
                Action<KinectBaseImageFrame> UpdatePictureBox = frame =>
                {
                    Marshal.Copy(frame.Ptr, buffer, 0, buffer.Length);
                    bitmap.SetPixels(buffer.SelectMany(d =>
                    {
                        var depth = ((Int32)d) >> 3;
                        if (depth > _tmpMaxDepth)
                        {
                            _tmpMaxDepth = depth;
                        }

                        var player= ((Int32)d) & 0x7;
                        var color = ColorMap[player];

                        return new Byte[]{
                        (Byte)(color.R * depth / MaxDepth)
                        , (Byte)(color.G * depth / MaxDepth)
                        , (Byte)(color.B * depth / MaxDepth)
                        , 255
                    };
                    }).ToArray());

                    pictureBoxForDepth.Image = bitmap;
                    if (_tmpMaxDepth > MaxDepth)
                    {
                        MaxDepth = _tmpMaxDepth;
                    }
                };
                _depthHandler = _timerEvent
                    .Where(_ => _sensor.DepthImageStream != null)
                    .Subscribe(_ => Observable.Using(
                        () => _sensor.DepthImageStream.GetFrame()
                        , frame => Observable.Return(frame)
                        )
                        .Where(frame => frame != null)
                        .Subscribe(
                            frame => UpdatePictureBox(frame)
                            , ex => {} // Console.WriteLine("error")
                        )
                    )
                    ;
            }
            else if(apiVersion==2)
            {
                Action<IEnumerable<Int16>, Byte[]> UpdatePictureBox = (db, ib) =>
                {
                    bitmap.SetPixels(db.Zip(ib.Select(index => (SByte)index), (depth, player) =>
                    {
                        if (depth > _tmpMaxDepth)
                        {
                            _tmpMaxDepth = depth;
                        }

                        var color = ColorMap[player+1];

                        return new Byte[]{
                        (Byte)(color.R * depth / MaxDepth)
                        , (Byte)(color.G * depth / MaxDepth)
                        , (Byte)(color.B * depth / MaxDepth)
                        , 255
                        };
                    }).SelectMany(pixel => pixel).ToArray());
                    pictureBoxForDepth.Image = bitmap;
                    if (_tmpMaxDepth > MaxDepth)
                    {
                        MaxDepth = _tmpMaxDepth;
                    }
                };

                var depthImage = _timerEvent
                    .Where(_ => _sensor.DepthImageStream != null)
                    .SelectMany(_ => Observable.Using(
                        ()=>_sensor.DepthImageStream.GetFrame()
                        , frame=>Observable.Return(frame)
                     )
                     .Catch((COMException ex)=>Observable.Return((KinectBaseImageFrame)null))
                     .Where(frame=>frame!=null)
                     .Select(frame =>
                     {
                         Marshal.Copy(frame.Ptr, buffer, 0, buffer.Length);
                         return new { Buffer = buffer, Time = frame.Time };
                     }
                     ))
                    ;

                var indexBuffer=new Byte[resolution.Width()*resolution.Height()];
                var indexImage = _timerEvent
                    .Where(_ => _sensor.IndexImageStream != null)
                    .SelectMany(_ => Observable.Using(
                        () => _sensor.IndexImageStream.GetFrame()
                            , frame => Observable.Return(frame)
                                )
                     .Catch((COMException ex) => Observable.Return((KinectBaseImageFrame)null))
                     .Where(frame => frame != null)
                                .Select(frame =>
                                {
                                    Marshal.Copy(frame.Ptr, indexBuffer, 0, indexBuffer.Length);
                                    return new { Buffer = indexBuffer, Time = frame.Time };
                                }))
                                ;

                _depthHandler = depthImage.CombineLatest(indexImage,
                    (l, r) => new { Depth = l, Index = r })
                    .Where(pair => pair.Depth.Time == pair.Index.Time)
                    .Subscribe(
                        pair => UpdatePictureBox(pair.Depth.Buffer, pair.Index.Buffer)
                        );
                    ;
            }
            else
            {
                throw new ArgumentException("apiVersion");
            }

        }
Exemplo n.º 17
0
        void StartDepthHandler(Int32 apiVersion, KinectImageResolution resolution)
        {
            var bitmap = new Bitmap(resolution.Width(), resolution.Height());
            var buffer = new Int16[resolution.Width() * resolution.Height()];


            if (apiVersion == 1)
            {
                Action <KinectBaseImageFrame> UpdatePictureBox = frame =>
                {
                    Marshal.Copy(frame.Ptr, buffer, 0, buffer.Length);
                    bitmap.SetPixels(buffer.SelectMany(d =>
                    {
                        var depth = ((Int32)d) >> 3;
                        if (depth > _tmpMaxDepth)
                        {
                            _tmpMaxDepth = depth;
                        }

                        var player = ((Int32)d) & 0x7;
                        var color  = ColorMap[player];

                        return(new Byte[] {
                            (Byte)(color.R * depth / MaxDepth)
                            , (Byte)(color.G * depth / MaxDepth)
                            , (Byte)(color.B * depth / MaxDepth)
                            , 255
                        });
                    }).ToArray());

                    pictureBoxForDepth.Image = bitmap;
                    if (_tmpMaxDepth > MaxDepth)
                    {
                        MaxDepth = _tmpMaxDepth;
                    }
                };
                _depthHandler = _timerEvent
                                .Where(_ => _sensor.DepthImageStream != null)
                                .Subscribe(_ => Observable.Using(
                                               () => _sensor.DepthImageStream.GetFrame()
                                               , frame => Observable.Return(frame)
                                               )
                                           .Where(frame => frame != null)
                                           .Subscribe(
                                               frame => UpdatePictureBox(frame)
                                               , ex => {}  // Console.WriteLine("error")
                                               )
                                           )
                ;
            }
            else if (apiVersion == 2)
            {
                Action <IEnumerable <Int16>, Byte[]> UpdatePictureBox = (db, ib) =>
                {
                    bitmap.SetPixels(db.Zip(ib.Select(index => (SByte)index), (depth, player) =>
                    {
                        if (depth > _tmpMaxDepth)
                        {
                            _tmpMaxDepth = depth;
                        }

                        var color = ColorMap[player + 1];

                        return(new Byte[] {
                            (Byte)(color.R * depth / MaxDepth)
                            , (Byte)(color.G * depth / MaxDepth)
                            , (Byte)(color.B * depth / MaxDepth)
                            , 255
                        });
                    }).SelectMany(pixel => pixel).ToArray());
                    pictureBoxForDepth.Image = bitmap;
                    if (_tmpMaxDepth > MaxDepth)
                    {
                        MaxDepth = _tmpMaxDepth;
                    }
                };

                var depthImage = _timerEvent
                                 .Where(_ => _sensor.DepthImageStream != null)
                                 .SelectMany(_ => Observable.Using(
                                                 () => _sensor.DepthImageStream.GetFrame()
                                                 , frame => Observable.Return(frame)
                                                 )
                                             .Catch((COMException ex) => Observable.Return((KinectBaseImageFrame)null))
                                             .Where(frame => frame != null)
                                             .Select(frame =>
                {
                    Marshal.Copy(frame.Ptr, buffer, 0, buffer.Length);
                    return(new { Buffer = buffer, Time = frame.Time });
                }
                                                     ))
                ;

                var indexBuffer = new Byte[resolution.Width() * resolution.Height()];
                var indexImage  = _timerEvent
                                  .Where(_ => _sensor.IndexImageStream != null)
                                  .SelectMany(_ => Observable.Using(
                                                  () => _sensor.IndexImageStream.GetFrame()
                                                  , frame => Observable.Return(frame)
                                                  )
                                              .Catch((COMException ex) => Observable.Return((KinectBaseImageFrame)null))
                                              .Where(frame => frame != null)
                                              .Select(frame =>
                {
                    Marshal.Copy(frame.Ptr, indexBuffer, 0, indexBuffer.Length);
                    return(new { Buffer = indexBuffer, Time = frame.Time });
                }))
                ;

                _depthHandler = depthImage.CombineLatest(indexImage,
                                                         (l, r) => new { Depth = l, Index = r })
                                .Where(pair => pair.Depth.Time == pair.Index.Time)
                                .Subscribe(
                    pair => UpdatePictureBox(pair.Depth.Buffer, pair.Index.Buffer)
                    );
                ;
            }
            else
            {
                throw new ArgumentException("apiVersion");
            }
        }
Exemplo n.º 18
0
        void CreateIndexImageStream(KinectImageResolution resolution)
        {
            StopIndexImage();
            if (resolution == KinectImageResolution.None)
            {
                return;
            }

            _indexImageStream = new V2BodyIndexStream(Sensor);
        }
Exemplo n.º 19
0
        void CreateDepthImageStream(KinectImageResolution resolution)
        {
            StopDepthImage();
            if (resolution == KinectImageResolution.None)
            {
                return;
            }

            _depthImageStream = new V2DepthStream(Sensor);
        }