コード例 #1
0
        //, ColorImageFrame colorFrame, DepthImageFrame depthFrame)
        private void SetImageShot(KinectSensor kinectDevice)
        {
            if (kinectDevice != null)// && depthFrame != null && colorFrame != null)
            {
                int depthPixelIndex = 0;
                int playerIndex = 0;
                int colorPixelIndex = 0;
                ColorImagePoint colorPoint;
                byte[] playerImage = new byte[depthFrameHeight * depthFrameStride];
                int playerImageIndex = 0;

                bool isSomeoneHere = false;

                for (int depthY = 0; depthY < depthFrameHeight; depthY++)
                {
                    for (int depthX = 0; depthX < colorFrameWidth; depthX++, playerImageIndex += BytesPerPixel)
                    {
                        depthPixelIndex = depthX + (depthY * colorFrameWidth);
                        playerIndex = depthPixelData[depthPixelIndex] & DepthImageFrame.PlayerIndexBitmask;

                        if (playerIndex != 0)
                        {

                            //
                            isSomeoneHere = true;
                            break;
                            //
                            //colorPoint = kinectDevice.MapDepthToColorImagePoint(depthImageFormat, depthX, depthY, this.depthPixelData[depthPixelIndex], colorImageFormat);
                            //colorPixelIndex = (colorPoint.X * BytesPerPixel) + (colorPoint.Y * colorFrameStride);

                            //playerImage[playerImageIndex] = colorPixelData[colorPixelIndex];         //Blue
                            //playerImage[playerImageIndex + 1] = colorPixelData[colorPixelIndex + 1];     //Green
                            //playerImage[playerImageIndex + 2] = colorPixelData[colorPixelIndex + 2];     //Red
                            //playerImage[playerImageIndex + 3] = 0xFF;                                          //Alpha
                        }
                    }
                }

                //
                if (isSomeoneHere)
                {
                    VideoShotCount++;
                    VideoShot videoShot = new VideoShot(this, _windowUI, VideoShotCount,
                        _kinectDevice,
                    depthFrameWidth, depthFrameHeight,
                    colorFrameWidth, colorFrameHeight,
                    depthImageFormat, colorImageFormat);

                    //Image temp = new Image();
                    //temp.Stretch = Stretch.Fill;
                    //temp.Height = 120;
                    //temp.Width = 160;

                    //temp.Source = BitmapImage.Create(colorFrameWidth, colorFrameHeight, 96, 96,
                    //                                         PixelFormats.Bgra32, null, playerImage,
                    //                                         colorFrameStride);
                    //Canvas.SetTop(temp, 600);
                    //Canvas.SetLeft(temp, (_windowUI.ImageLayer.Children.Count - 1) * 170);
                    //_windowUI.ImageLayer.Children.Add(temp);
                }
            }
        }
コード例 #2
0
        private void SetImageShot(KinectSensor kinectDevice) //, ColorImageFrame colorFrame, DepthImageFrame depthFrame)
        {
            if (kinectDevice != null)                        // && depthFrame != null && colorFrame != null)
            {
                int             depthPixelIndex = 0;
                int             playerIndex     = 0;
                int             colorPixelIndex = 0;
                ColorImagePoint colorPoint;
                byte[]          playerImage      = new byte[depthFrameHeight * depthFrameStride];
                int             playerImageIndex = 0;

                bool isSomeoneHere = false;

                for (int depthY = 0; depthY < depthFrameHeight; depthY++)
                {
                    for (int depthX = 0; depthX < colorFrameWidth; depthX++, playerImageIndex += BytesPerPixel)
                    {
                        depthPixelIndex = depthX + (depthY * colorFrameWidth);
                        playerIndex     = depthPixelData[depthPixelIndex] & DepthImageFrame.PlayerIndexBitmask;

                        if (playerIndex != 0)
                        {
                            //
                            isSomeoneHere = true;
                            break;
                            //
                            //colorPoint = kinectDevice.MapDepthToColorImagePoint(depthImageFormat, depthX, depthY, this.depthPixelData[depthPixelIndex], colorImageFormat);
                            //colorPixelIndex = (colorPoint.X * BytesPerPixel) + (colorPoint.Y * colorFrameStride);

                            //playerImage[playerImageIndex] = colorPixelData[colorPixelIndex];         //Blue
                            //playerImage[playerImageIndex + 1] = colorPixelData[colorPixelIndex + 1];     //Green
                            //playerImage[playerImageIndex + 2] = colorPixelData[colorPixelIndex + 2];     //Red
                            //playerImage[playerImageIndex + 3] = 0xFF;                                          //Alpha
                        }
                    }
                }

                //
                if (isSomeoneHere)
                {
                    VideoShotCount++;
                    VideoShot videoShot = new VideoShot(this, _windowUI, VideoShotCount,
                                                        _kinectDevice,
                                                        depthFrameWidth, depthFrameHeight,
                                                        colorFrameWidth, colorFrameHeight,
                                                        depthImageFormat, colorImageFormat);

                    //Image temp = new Image();
                    //temp.Stretch = Stretch.Fill;
                    //temp.Height = 120;
                    //temp.Width = 160;

                    //temp.Source = BitmapImage.Create(colorFrameWidth, colorFrameHeight, 96, 96,
                    //                                         PixelFormats.Bgra32, null, playerImage,
                    //                                         colorFrameStride);
                    //Canvas.SetTop(temp, 600);
                    //Canvas.SetLeft(temp, (_windowUI.ImageLayer.Children.Count - 1) * 170);
                    //_windowUI.ImageLayer.Children.Add(temp);
                }
            }
        }