Beispiel #1
0
        /// <summary>
        /// Draw the RGB Image
        /// </summary>
        /// <param name="framePreProcessor">Frame preprocessor</param>
        private void DrawRGBImage(FramePreProcessor framePreProcessor)
        {
            if (null == framePreProcessor.RawFrames.RawColorFrameData)
            {
                return;
            }

            BitmapSource bitmapSource = BitmapSource.Create(
                framePreProcessor.RawFrames.RawColorFrameInfo.Width,
                framePreProcessor.RawFrames.RawColorFrameInfo.Height,
                96,
                96,
                PixelFormats.Bgr32,
                null,
                framePreProcessor.RawFrames.RawColorFrameData,
                framePreProcessor.RawFrames.RawColorFrameInfo.Width *
                framePreProcessor.RawFrames.RawColorFrameInfo.BytesPerPixel);

            this.RgbImage.Source = bitmapSource;

            if (this.kinectUIService.IncludeVideoProcessed)
            {
                this.RgbImageProcessed.Visibility = System.Windows.Visibility.Visible;
                this.RgbImageProcessed.Source     = FramePreProcessor.ToBitmapSource(framePreProcessor.BitmapProcessed);
            }
            else
            {
                this.RgbImageProcessed.Visibility = System.Windows.Visibility.Hidden;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Overlay depth image
        /// </summary>
        /// <param name="framePreProcessor">Pre processed frame</param>
        private void DrawDepthImage(FramePreProcessor framePreProcessor)
        {
            byte[] depthImageBytes = framePreProcessor.GetDepthBytes();

            this.DepthImage.Source = BitmapSource.Create(
                framePreProcessor.RawFrames.RawDepthFrameInfo.Width,
                framePreProcessor.RawFrames.RawDepthFrameInfo.Height,
                96,
                96,
                PixelFormats.Bgr32,
                null,
                depthImageBytes,
                framePreProcessor.RawFrames.RawDepthFrameInfo.Width * PixelFormats.Bgr32.BitsPerPixel / 8);
        }
Beispiel #3
0
        private double canvasFactor;  // used for scaling lines and font to allow window resizing

        /// <summary>
        /// A method for drawing all joints and bones
        /// </summary>
        /// <param name="framePreProcessor">Pre processed frame, including skeletal data</param>
        private void DrawSkeletons(FramePreProcessor framePreProcessor)
        {
            this.SkeletonQualityText.Text = string.Empty;
            canvasFactor = this.SkeletonCanvas.ActualWidth + this.SkeletonCanvas.ActualHeight;

            var tmpAllSkeletons = framePreProcessor.AllSkeletons;  // get a snapshot of the pointer to allocated array, and then take sweet time processing it knowing it will not change

            foreach (var skeleton in tmpAllSkeletons.Where(skeleton => skeleton.IsSkeletonActive))
            {
                this.DrawBodySegments(skeleton, skeleton.IsMainSkeleton ? this.greenBrush : this.wheatBrush);

                this.DrawJoints(skeleton);

                this.UpdateAdditionalSkeletalInfoField(skeleton);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Initialize Kinect UI service
        /// </summary>
        /// <returns>Iterator</returns>
        private IEnumerator <ITask> InitializeKinectUI()
        {
            this.frameProcessor = new FramePreProcessor(this.kinectPort, this._state, this.useKinectNykoGlasses);

            var runWindow = this.wpfServicePort.RunWindow(() => new KinectUI(this));

            yield return((Choice)runWindow);

            var exception = (Exception)runWindow;

            if (exception != null)
            {
                LogError(exception);
                StartFailed();
                yield break;
            }

            // need double cast because WPF adapter doesn't know about derived window types
            this.userInterface = (Window)runWindow as KinectUI;

            yield return(this.kinectPort.Get().Choice(
                             kinectState =>
            {
                this.UpdateState(kinectState);
            },
                             failure =>
            {
                LogError(failure);
            }));

            yield return(this.kinectPort.GetDepthProperties().Choice(
                             GetDepthProperties =>
            {
                KinectUI.MaxValidDepth = GetDepthProperties.MaxDepthValue;
            },
                             failure =>
            {
                LogError(failure);
            }));

            SpawnIterator(this.ReadKinectLoop);
        }
Beispiel #5
0
        int cycleCounter = 0;     // helps to only draw every N-th frame

        /// <summary>
        /// Draw the frame
        /// </summary>
        /// <param name="framePreProcessor">Frame preprocessor</param>
        public void DrawFrame(FramePreProcessor framePreProcessor)
        {
            this.RegisterFrameRead();       // frame rate calculation

            if (cycleCounter % 2 == 0)      // only draw every N-th frame
            {
                bool doRgb   = (bool)this.VideoCB.IsChecked;
                bool doDepth = (bool)this.DepthCB.IsChecked;
                bool doSkel  = (bool)this.SkeletalCB.IsChecked;

                if (doRgb)
                {
                    this.DrawRGBImage(framePreProcessor);
                }

                if (doDepth)
                {
                    this.DrawDepthImage(framePreProcessor);
                }

                this.SkeletonCanvas.Children.Clear();

                if (doSkel)
                {
                    this.DrawSkeletons(framePreProcessor);
                }

                // infrequently adjust opacity
                if (cycleCounter % 20 == 0)
                {
                    this.RgbImage.Opacity   = doRgb ? 1.0d : 0.0d;
                    this.DepthImage.Opacity = doDepth ? (doRgb ? 0.6d : 1.0d) : 0.0d;
                }
            }

            cycleCounter++;
        }
        /// <summary>
        /// A method for drawing all joints and bones
        /// </summary>
        /// <param name="framePreProcessor">Pre processed frame, including skeletal data</param>
        private void DrawSkeletons(FramePreProcessor framePreProcessor)
        {
            this.SkeletonQualityText.Text = string.Empty;
            canvasFactor = this.SkeletonCanvas.ActualWidth + this.SkeletonCanvas.ActualHeight;

            var tmpAllSkeletons = framePreProcessor.AllSkeletons;  // get a snapshot of the pointer to allocated array, and then take sweet time processing it knowing it will not change

            foreach (var skeleton in tmpAllSkeletons.Where(skeleton => skeleton.IsSkeletonActive))
            {
                this.DrawBodySegments(skeleton, skeleton.IsMainSkeleton ? this.greenBrush : this.wheatBrush);

                this.DrawJoints(skeleton);

                this.UpdateAdditionalSkeletalInfoField(skeleton);
            }
        }
        /// <summary>
        /// Draw the RGB Image
        /// </summary>
        /// <param name="framePreProcessor">Frame preprocessor</param>
        private void DrawRGBImage(FramePreProcessor framePreProcessor)
        {
            if (null == framePreProcessor.RawFrames.RawColorFrameData)
            {
                return;
            }

            BitmapSource bitmapSource = BitmapSource.Create(
                framePreProcessor.RawFrames.RawColorFrameInfo.Width,
                framePreProcessor.RawFrames.RawColorFrameInfo.Height,
                96,
                96,
                PixelFormats.Bgr32,
                null,
                framePreProcessor.RawFrames.RawColorFrameData,
                framePreProcessor.RawFrames.RawColorFrameInfo.Width *
                    framePreProcessor.RawFrames.RawColorFrameInfo.BytesPerPixel);

            this.RgbImage.Source = bitmapSource;

            if (this.kinectUIService.IncludeVideoProcessed)
            {
                this.RgbImageProcessed.Visibility = System.Windows.Visibility.Visible;
                this.RgbImageProcessed.Source = FramePreProcessor.ToBitmapSource(framePreProcessor.BitmapProcessed);
            }
            else
            {
                this.RgbImageProcessed.Visibility = System.Windows.Visibility.Hidden;
            }
        }
        /// <summary>
        /// Overlay depth image
        /// </summary>
        /// <param name="framePreProcessor">Pre processed frame</param>
        private void DrawDepthImage(FramePreProcessor framePreProcessor)
        {
            byte[] depthImageBytes = framePreProcessor.GetDepthBytes();

            this.DepthImage.Source = BitmapSource.Create(
                framePreProcessor.RawFrames.RawDepthFrameInfo.Width,
                framePreProcessor.RawFrames.RawDepthFrameInfo.Height,
                96,
                96,
                PixelFormats.Bgr32,
                null,
                depthImageBytes,
                framePreProcessor.RawFrames.RawDepthFrameInfo.Width * PixelFormats.Bgr32.BitsPerPixel / 8);
        }
        /// <summary>
        /// Draw the frame
        /// </summary>
        /// <param name="framePreProcessor">Frame preprocessor</param>
        public void DrawFrame(FramePreProcessor framePreProcessor)
        {
            this.RegisterFrameRead();       // frame rate calculation

            if (cycleCounter % 2 == 0)      // only draw every N-th frame
            {
                bool doRgb = (bool)this.VideoCB.IsChecked;
                bool doDepth = (bool)this.DepthCB.IsChecked;
                bool doSkel = (bool)this.SkeletalCB.IsChecked;

                if (doRgb)
                {
                    this.DrawRGBImage(framePreProcessor);
                }

                if (doDepth)
                {
                    this.DrawDepthImage(framePreProcessor);
                }

                this.SkeletonCanvas.Children.Clear();

                if (doSkel)
                {
                    this.DrawSkeletons(framePreProcessor);
                }

                // infrequently adjust opacity
                if (cycleCounter % 20 == 0)
                {
                    this.RgbImage.Opacity = doRgb ? 1.0d : 0.0d;
                    this.DepthImage.Opacity = doDepth ? (doRgb ? 0.6d : 1.0d) : 0.0d;
                }
            }

            cycleCounter++;
        }
 private void UpdateUI(FramePreProcessor framePreProcessor)
 {
     this.wpfServicePort.Invoke(() => this.userInterface.DrawFrame(framePreProcessor));
 }
        /// <summary>
        /// Initialize Kinect UI service
        /// </summary>
        /// <returns>Iterator</returns>
        private IEnumerator<ITask> InitializeKinectUI()
        {
            this.frameProcessor = new FramePreProcessor(this.kinectPort, this._state);

            var runWindow = this.wpfServicePort.RunWindow(() => new KinectUI(this));
            yield return (Choice)runWindow;

            var exception = (Exception)runWindow;
            if (exception != null)
            {
                LogError(exception);
                StartFailed();
                yield break;
            }

            // need double cast because WPF adapter doesn't know about derived window types
            this.userInterface = (Window)runWindow as KinectUI;

            yield return this.kinectPort.Get().Choice(
                kinectState =>
                {
                    this.UpdateState(kinectState);
                },
                failure =>
                {
                    LogError(failure);
                });

            yield return this.kinectPort.GetDepthProperties().Choice(
                GetDepthProperties =>
                {
                    KinectUI.MaxValidDepth = GetDepthProperties.MaxDepthValue;
                },
                failure =>
                {
                    LogError(failure);
                });

            SpawnIterator(this.ReadKinectLoop);
        }
Beispiel #12
0
 private void UpdateUI(FramePreProcessor framePreProcessor)
 {
     this.wpfServicePort.Invoke(() => this.userInterface.DrawFrame(framePreProcessor));
 }