/// <summary>
        /// Updates pixel data and if necessary bitmap as well.
        /// </summary>
        /// <param name="frame"></param>
        /// <param name="updateDisplay">Updates the bitmap if true.</param>
        public void Update(ReplayColorImageFrame frame, bool updateDisplay = true)
        {
            PixelData = new byte[frame.PixelDataLength];

            frame.CopyPixelDataTo(PixelData);

            if (!updateDisplay)
            {
                return;
            }

            if (Bitmap == null)
            {
                Bitmap = new WriteableBitmap(frame.Width, frame.Height,
                                             96, 96, PixelFormats.Bgr32, null);
            }

            int       stride    = Bitmap.PixelWidth * Bitmap.Format.BitsPerPixel / 8;
            Int32Rect dirtyRect = new Int32Rect(0, 0, Bitmap.PixelWidth, Bitmap.PixelHeight);

            if (frame.Format == ColorImageFormat.RawYuvResolution640x480Fps15)
            {
                if (yuvTemp == null)
                {
                    yuvTemp = new int[frame.Width * frame.Height];
                }

                int current = 0;

                for (int uyvyIndex = 0; uyvyIndex < PixelData.Length; uyvyIndex += 4)
                {
                    byte u  = PixelData[uyvyIndex];
                    byte y1 = PixelData[uyvyIndex + 1];
                    byte v  = PixelData[uyvyIndex + 2];
                    byte y2 = PixelData[uyvyIndex + 3];

                    yuvTemp[current++] = ConvertFromYUV(y1, u, v);
                    yuvTemp[current++] = ConvertFromYUV(y2, u, v);
                }

                Bitmap.WritePixels(dirtyRect, yuvTemp, stride, 0);
            }
            else
            {
                Bitmap.WritePixels(dirtyRect, PixelData, stride, 0);
            }

            RaisePropertyChanged(() => Bitmap);
        }
Esempio n. 2
0
        private void UpdateColorFrame(ReplayColorImageFrame frame)
        {
            var pixelData = new byte[frame.PixelDataLength];

            frame.CopyPixelDataTo(pixelData);
            if (ImageSource == null)
            {
                ImageSource = new WriteableBitmap(frame.Width, frame.Height, 96, 96,
                                                  PixelFormats.Bgr32, null);
            }

            var stride = frame.Width * PixelFormats.Bgr32.BitsPerPixel / 8;

            ImageSource.WritePixels(new Int32Rect(0, 0, frame.Width, frame.Height), pixelData, stride, 0);
        }
Esempio n. 3
0
        private void UpdateColorFrame(ReplayColorImageFrame frame)
        {
            //System.Console.WriteLine("update color frame");
            // var uri = new Uri("C:\\Users\\WenxuanZhou\\Desktop\\881856_475135009220488_407602784_o.jpg");
            // img1.Source = new BitmapImage(uri);

            var pixelData = new byte[frame.PixelDataLength];

            frame.CopyPixelDataTo(pixelData);
            //if (ImageSource == null)
            //    ImageSource = new WriteableBitmap(frame.Width, frame.Height, 96, 96,
            //                                                PixelFormats.Bgr32, null);

            var stride = frame.Width * PixelFormats.Bgr32.BitsPerPixel / 8;

            //ImageSource.WritePixels(new Int32Rect(0, 0, frame.Width, frame.Height), pixelData, stride, 0);
            img1.Source = BitmapSource.Create(frame.Width, frame.Height, 96, 96, PixelFormats.Bgr32, null, pixelData, stride);
        }
Esempio n. 4
0
        public void synchronize(
            ReplayDepthImageFrame depthFrame,
            ReplayColorImageFrame colorFrame,
            ReplaySkeletonFrame skletonFrame,
            Boolean isPauseMode
            )
        {
            IsPauseMode = isPauseMode;
            colorFrame.CopyPixelDataTo(_colorByte);
            depthFrame.CopyPixelDataTo(_depthShort);
            for (int i = 0; i < _pixelDepthDataLength; i++)
            {
                _depthByte[i] = (byte)(_depthShort[i] * 0.064 - 1);
            }

            _isCreation        = true;
            IsSkeletonDetected = skletonFrame.IsSkeletonDetected;

            if (skletonFrame.IsSkeletonDetected)
            {
                UserSkeleton[SkeletonDataType.RIGHT_HAND] = new Point(
                    skletonFrame.RightHandPositionX,
                    skletonFrame.RightHandPositionY
                    );

                UserSkeleton[SkeletonDataType.LEFT_HAND] = new Point(
                    skletonFrame.LeftHandPositionX,
                    skletonFrame.LeftHandPositionY
                    );

                UserSkeleton[SkeletonDataType.SPINE] = new Point(
                    skletonFrame.SpinePositionX,
                    skletonFrame.SpinePositionY
                    );
            }
            _isCreation = false;
        }