예제 #1
0
        private void InitializeKinectSensor(KinectSensor kinectSensor)
        {
            if (kinectSensor != null)
            {
                ColorImageStream colorStream = kinectSensor.ColorStream;
                colorStream.Enable();
                this._ColorImageBitmap = new WriteableBitmap(colorStream.FrameWidth, colorStream.FrameHeight,
                                                             96, 96, PixelFormats.Bgr32, null);
                this._ColorImageBitmapRect = new Int32Rect(0, 0, colorStream.FrameWidth, colorStream.FrameHeight);
                this._ColorImageStride     = colorStream.FrameWidth * colorStream.FrameBytesPerPixel;
                videoStream.Source         = this._ColorImageBitmap;

                kinectSensor.SkeletonStream.Enable(new TransformSmoothParameters()
                {
                    Correction         = 0.5f,
                    JitterRadius       = 0.05f,
                    MaxDeviationRadius = 0.04f,
                    Smoothing          = 0.5f
                });

                kinectSensor.SkeletonFrameReady += Kinect_SkeletonFrameReady;
                kinectSensor.ColorFrameReady    += Kinect_ColorFrameReady;
                kinectSensor.Start();
                this.FrameSkeletons = new Skeleton[this.Kinect.SkeletonStream.FrameSkeletonArrayLength];
            }
        }
예제 #2
0
        void ColorWindow_Loaded(object sender, RoutedEventArgs e)
        {
            if (kinect != null)
            {
                #region 彩色影像相關物件初始化
                ColorImageStream colorStream = kinect.ColorStream;

                colorStream.Enable();
                kinect.ColorFrameReady += myKinect_ColorFrameReady;

                _ColorImageBitmap = new WriteableBitmap(colorStream.FrameWidth, colorStream.FrameHeight, 96, 96,
                                                        PixelFormats.Bgr32, null);
                _ColorImageBitmapRect = new Int32Rect(0, 0, colorStream.FrameWidth, colorStream.FrameHeight);
                _ColorImageStride     = colorStream.FrameWidth * colorStream.FrameBytesPerPixel;
                ColorData.Source      = _ColorImageBitmap;
                #endregion
                kinect.Start();

                speechRecognizer = CreateSpeechRecognizer();
                if (speechRecognizer != null)
                {
                    ready4sTimer          = new DispatcherTimer();
                    ready4sTimer.Tick    += ReadyTimerTick;
                    ready4sTimer.Interval = new TimeSpan(0, 0, 4);
                    ready4sTimer.Start();
                }
            }
        }
예제 #3
0
        // Habilita ColorStream de KinectSensor recién detectado y establece la imagen de salida
        private void InitializeKinectSensor(KinectSensor sensor)
        {
            if (sensor != null)
            {
                ColorImageStream colorStream = sensor.ColorStream;
                colorStream.Enable();

                KinectCameraImage = new WriteableBitmap(colorStream.FrameWidth, colorStream.FrameHeight
                                                        , 96, 96, PixelFormats.Bgr32, null);

                _cameraSourceBounds     = new Int32Rect(0, 0, colorStream.FrameWidth, colorStream.FrameHeight);
                _colorStride            = colorStream.FrameWidth * colorStream.FrameBytesPerPixel;
                sensor.ColorFrameReady += KinectSensor_ColorFrameReady; ///METODOS DE KINECT

                sensor.SkeletonStream.AppChoosesSkeletons = false;
                sensor.SkeletonStream.Enable();
                _skeletons = new Skeleton[sensor.SkeletonStream.FrameSkeletonArrayLength];
                sensor.SkeletonFrameReady += KinectSensor_SkeletonFrameReady;
                try
                {
                    sensor.Start();
                }
                catch (Exception)
                {
                    UninitializeKinectSensor(sensor);
                    Kinect = null;
                    ErrorGridVisibility = Visibility.Visible;
                    ErrorGridMessage    = "Kinect está siendo utilizado por otro proceso. " + Environment.NewLine +
                                          "Trata de desconectar y volver a conectar el dispositivo al ordenador." + Environment.NewLine +
                                          "Asegúrese de que todos los programas que utilizan Kinect se han desactivado.";
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Enables ColorStream from newly detected KinectSensor and sets output image
        /// </summary>
        /// <param name="sensor">Detected KinectSensor</param>
        private void InitializeKinectSensor(KinectSensor sensor)
        {
            if (sensor != null)
            {
                ColorImageStream colorStream = sensor.ColorStream;
                colorStream.Enable();

                KinectCameraImage = new WriteableBitmap(colorStream.FrameWidth, colorStream.FrameHeight
                                                        , 96, 96, PixelFormats.Bgr32, null);

                _cameraSourceBounds     = new Int32Rect(0, 0, colorStream.FrameWidth, colorStream.FrameHeight);
                _colorStride            = colorStream.FrameWidth * colorStream.FrameBytesPerPixel;
                sensor.ColorFrameReady += KinectSensor_ColorFrameReady;

                sensor.SkeletonStream.AppChoosesSkeletons = false;
                sensor.SkeletonStream.Enable();
                _skeletons = new Skeleton[sensor.SkeletonStream.FrameSkeletonArrayLength];
                sensor.SkeletonFrameReady += KinectSensor_SkeletonFrameReady;
                try
                {
                    sensor.Start();
                }
                catch (Exception)
                {
                    UninitializeKinectSensor(sensor);
                    Kinect = null;
                    ErrorGridVisibility = Visibility.Visible;
                    ErrorGridMessage    = "Kinect jest używany przez inny proces." + Environment.NewLine +
                                          "Spróbuj odłączyć i ponownie podłączyć urządzenie do komputera." + Environment.NewLine +
                                          "Upewnij się, że wszystkie programy używajace Kinecta zostały wyłączone.";
                }
            }
        }
예제 #5
0
        private void WindowLoaded(object sender, RoutedEventArgs e)
        {
            KinectSensor kinect = KinectSensor.KinectSensors[0];

            ColorImageStream clrStream = kinect.ColorStream;

            clrStream.Enable(rgbFormat);
            DepthImageStream depStream = kinect.DepthStream;

            depStream.Enable(depthFormat);

            kinect.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);

            pixelBuffer     = new byte[kinect.ColorStream.FramePixelDataLength];
            depthBuffer     = new DepthImagePixel[depStream.FramePixelDataLength];
            clrPntBuffer    = new ColorImagePoint[depStream.FramePixelDataLength];
            depthMaskBuffer = new byte[clrStream.FramePixelDataLength];

            bmpBuffer = new RenderTargetBitmap(clrStream.FrameWidth, clrStream.FrameHeight,
                                               96, 96, PixelFormats.Default);
            rgbImage.Source = bmpBuffer;

            kinect.AllFramesReady += AllFramesReady;

            textBox1.Clear();

            kinect.Start();

            kinect.ElevationAngle = 0;
        }
예제 #6
0
 private void EnableColorImageStreamBasedOnIsChecked(
     CheckBox checkBox, ColorImageStream imageStream, ComboBox colorFormatsValue)
 {
     if (checkBox.IsChecked.HasValue && checkBox.IsChecked.Value)
     {
         imageStream.Enable((ColorImageFormat)colorFormatsValue.SelectedItem);
     }
     else
     {
         imageStream.Disable();
     }
 }
예제 #7
0
        // kinect センサーの初期化
        private void InitKinectSensor(KinectSensor kinect)
        {
            //カラーストリームの有効化
            ColorImageStream clrStream = kinect.ColorStream;

            clrStream.Enable(rgbFormat);
            // 深度ストリームの有効化
            DepthImageStream depStream = kinect.DepthStream;
            // depStream.Enable(depthFormat); // /*TEST_DEPTHFRAME*/

            //骨格ストリームの有効化
            SkeletonStream skelStream = kinect.SkeletonStream;

            skelStream.Enable();

            // バッファの初期化
            pixelBuffer = new byte[clrStream.FramePixelDataLength];
            if (TEST_DEPTHFLAG)
            {
                depthBuffer   = new short[depStream.FramePixelDataLength];
                clrPntBuffer  = new ColorImagePoint[depStream.FramePixelDataLength];
                depMaskBuffer = new byte[clrStream.FramePixelDataLength];
            }
            skeletonBuffer = new Skeleton[skelStream.FrameSkeletonArrayLength];

            bmpBuffer = new RenderTargetBitmap(clrStream.FrameWidth, clrStream.FrameHeight, 96, 96, PixelFormats.Default);

            rgbimage.Source = bmpBuffer;

            // 音声認識エンジンの初期化
            speechEngine = InitSpeechEngine();

            // イベントハンドラの登録
            kinect.AllFramesReady += AllFramesReady;
            kinect.AudioSource.SoundSourceAngleChanged += SoundSourceChanged;
            speechEngine.SpeechRecognized += SpeechRecognized;

            // 近接モードに変更
            kinect.DepthStream.Range = DepthRange.Near;

            // 着席モードに変更
            kinect.SkeletonStream.TrackingMode = SkeletonTrackingMode.Seated;

            // Kinect センサーからのストリーム取得を開始
            System.IO.Stream stream = kinect.AudioSource.Start();
            var speechAudioFormat   = new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null);

            speechEngine.SetInputToAudioStream(stream, speechAudioFormat);
            speechEngine.RecognizeAsync(RecognizeMode.Multiple);
        }
        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            if (kinects.Count > 0)
            {
                ColorImageStream colorStream = kinects[0].ColorStream;
                colorStream.Enable();
                //kinects[0].ColorStream.Enable(ColorImageFormat.InfraredResolution640x480Fps30);
                kinects[0].ColorFrameReady += Kinect_ColorFrameReady;

                _ColorImageBitmap = new WriteableBitmap(colorStream.FrameWidth, colorStream.FrameHeight, 96, 96,
                                                        PixelFormats.Bgr32, null);
                _ColorImageBitmapRect = new Int32Rect(0, 0, colorStream.FrameWidth, colorStream.FrameHeight);
                _ColorImageStride     = colorStream.FrameWidth * colorStream.FrameBytesPerPixel;
                ColorData.Source      = _ColorImageBitmap;
            }
        }
        void ColorWindow_Loaded(object sender, RoutedEventArgs e)
        {
            if (kinect != null)
            {
                ColorImageStream colorStream = kinect.ColorStream;

                colorStream.Enable();
                kinect.ColorFrameReady += myKinect_ColorFrameReady;

                _ColorImageBitmap = new WriteableBitmap(colorStream.FrameWidth, colorStream.FrameHeight, 96, 96,
                                                        PixelFormats.Bgr32, null);
                _ColorImageBitmapRect = new Int32Rect(0, 0, colorStream.FrameWidth, colorStream.FrameHeight);
                _ColorImageStride     = colorStream.FrameWidth * colorStream.FrameBytesPerPixel;
                ColorData.Source      = _ColorImageBitmap;

                kinect.Start();
            }
        }
        private void InitializeKinectSensor(KinectSensor sensor)
        {
            if (sensor != null)
            {
                ColorImageStream colorStream = sensor.ColorStream;

                colorStream.Enable();

                /* Added in Listing 2-5 */
                this._ColorImageBitmap        = new WriteableBitmap(colorStream.FrameWidth, colorStream.FrameHeight, 96, 96, PixelFormats.Bgr32, null);
                this._ColorImageBitmapRect    = new Int32Rect(0, 0, colorStream.FrameWidth, colorStream.FrameHeight);
                this._ColorImageStride        = colorStream.FrameWidth * colorStream.FrameBytesPerPixel;
                this.ColorImageElement.Source = this._ColorImageBitmap;
                this._ColorImagePixelData     = new byte[colorStream.FramePixelDataLength];
                /* Added in Listing 2-5 */

                sensor.ColorFrameReady += Kinect_ColorFrameReady;
                sensor.Start();
            }
        }
예제 #11
0
        /// <summary>
        /// Enables ColorStream from newly detected KinectSensor and sets output image
        /// </summary>
        /// <param name="sensor">Detected KinectSensor</param>
        private void InitializeKinectSensor(KinectSensor sensor)
        {
            if (sensor != null)
            {
                ColorImageStream colorStream = sensor.ColorStream;
                colorStream.Enable();

                _cameraSourceBitmap = new WriteableBitmap(colorStream.FrameWidth, colorStream.FrameHeight
                                                          , 96, 96, PixelFormats.Bgr32, null);
                _cameraSourceBounds      = new Int32Rect(0, 0, colorStream.FrameWidth, colorStream.FrameHeight);
                _colorStride             = colorStream.FrameWidth * colorStream.FrameBytesPerPixel;
                KinectCameraImage.Source = _cameraSourceBitmap;

                sensor.ColorFrameReady += KinectSensor_ColorFrameReady;

                sensor.SkeletonStream.Enable();
                _skeletons = new Skeleton[sensor.SkeletonStream.FrameSkeletonArrayLength];
                sensor.SkeletonFrameReady += KinectSensor_SkeletonFrameReady;
                sensor.Start();
            }
        }
예제 #12
0
        private void InitializeKinectSensor(KinectSensor sensor)
        {
            if (sensor != null)
            {
                ColorImageStream colorStream = sensor.ColorStream;
                colorStream.Enable();

                this.colorImageBitmap = new WriteableBitmap(colorStream.FrameWidth, colorStream.FrameHeight,
                                                            96, 96, PixelFormats.Bgr32, null);
                this.colorImageBitmapRect = new Int32Rect(0, 0, colorStream.FrameWidth, colorStream.FrameHeight);
                this.colorImageStride     = colorStream.FrameWidth * colorStream.FrameBytesPerPixel;
                ColorImageElement.Source  = this.colorImageBitmap;
                sensor.ColorFrameReady   += kinect_ColorFrameReady;

                //depth
                DepthImageStream depthStream = sensor.DepthStream;
                sensor.DepthStream.Enable();

                this.depthImageBitmap = new WriteableBitmap(depthStream.FrameWidth, depthStream.FrameHeight,
                                                            96, 96, PixelFormats.Gray16, null);
                this.depthImageBitmapRect = new Int32Rect(0, 0, depthStream.FrameWidth, depthStream.FrameHeight);
                this.depthImageStride     = depthStream.FrameWidth * depthStream.FrameBytesPerPixel;
                DepthImageElement.Source  = this.depthImageBitmap;

                this.enhancedDepthImageBitmap = new WriteableBitmap(colorStream.FrameWidth, colorStream.FrameHeight,
                                                                    96, 96, PixelFormats.Bgr32, null);
                this.enhancedDepthImageBitmapRect = new Int32Rect(0, 0, colorStream.FrameWidth, colorStream.FrameHeight);
                this.enhancedDepthImageStride     = colorImageStride;
                EnhancedDepthImageElement.Source  = this.enhancedDepthImageBitmap;

                sensor.DepthFrameReady += kinect_DepthFrameReady;


                //skeleton
                sensor.SkeletonStream.Enable();
                sensor.Start();
            }
        }
예제 #13
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                //Kinectセンサーの取得(エラー処理など省略版)
                kinect = KinectSensor.KinectSensors[0];

                //カラー・骨格ストリームの有効化
                ColorImageStream clrStream = kinect.ColorStream;
                clrStream.Enable(rgbFormat);
                SkeletonStream skelStream = kinect.SkeletonStream;
                skelStream.Enable();
                DepthImageStream depStream = kinect.DepthStream;
                depStream.Enable(depthFormat);

                //バッファの初期化
                pixelBuffer    = new byte[kinect.ColorStream.FramePixelDataLength];
                skeletonBuffer = new Skeleton[skelStream.FrameSkeletonArrayLength];
                bmpBuffer      = new WriteableBitmap(kinect.ColorStream.FrameWidth,
                                                     kinect.ColorStream.FrameHeight,
                                                     96, 96, PixelFormats.Bgr32, null);
                depthBuffer     = new short[depStream.FramePixelDataLength];
                clrPntBuffer    = new ColorImagePoint[depStream.FramePixelDataLength];
                rgbImage.Source = bmpBuffer;

                //イベントハンドラの登録
                kinect.ColorFrameReady += ColorImageReady;
                kinect.AllFramesReady  += AllFramesReady;

                //Kinectセンサーからのストリーム取得を開始
                kinect.Start();
            }
            catch
            {
                Console.WriteLine("kinectがありません。");
            }
        }
예제 #14
0
        private void InitializeKinectSensor(KinectSensor sensor)
        {
            if (kinect != null)
            {
                ColorImageStream colorStream = kinect.ColorStream;
                colorStream.Enable();

                this.colorImageBitmap = new WriteableBitmap(colorStream.FrameWidth, colorStream.FrameHeight,
                                                            96, 96, PixelFormats.Bgr32, null);
                this.colorImageBitmapRect = new Int32Rect(0, 0, colorStream.FrameWidth, colorStream.FrameHeight);
                this.colorImageStride     = colorStream.FrameWidth * colorStream.FrameBytesPerPixel;
                //initialize drawing
                this.drawingGroupColor = new DrawingGroup();
                this.imageSourceColor  = new DrawingImage(this.drawingGroupColor);
                SkeletonColorOverlappingImage.Source = this.imageSourceColor;

                DepthImageStream depthStream = kinect.DepthStream;
                depthStream.Enable();

                this.depthImageBitmap = new WriteableBitmap(depthStream.FrameWidth, depthStream.FrameHeight,
                                                            96, 96, PixelFormats.Gray16, null);
                this.depthImageBitmapRect = new Int32Rect(0, 0, depthStream.FrameWidth, depthStream.FrameHeight);
                this.depthImageStride     = depthStream.FrameWidth * depthStream.FrameBytesPerPixel;

                //initialize drawing
                this.drawingGroupDepth = new DrawingGroup();
                this.imageSourceDepth  = new DrawingImage(this.drawingGroupDepth);
                SkeletonDepthOverlappingImage.Source = this.imageSourceDepth;
                //  SkeletonDepthOverlappingImage.Source = depthImageBitmap;


                //\ parameters
                TransformSmoothParameters smoothingParameters = new TransformSmoothParameters();
                {
                    smoothingParameters.Smoothing          = 0.5f;
                    smoothingParameters.Correction         = 0.5f;
                    smoothingParameters.Prediction         = 0.5f;
                    smoothingParameters.JitterRadius       = 0.05f;
                    smoothingParameters.MaxDeviationRadius = 0.04f;
                }

                sensor.SkeletonStream.Enable(smoothingParameters);
                skeletonData = new Skeleton[sensor.SkeletonStream.FrameSkeletonArrayLength];

                this.kinect.AllFramesReady += kinect_AllFramesReady;
                sensor.Start();

                //timer start


                time  = TimeSpan.FromSeconds(0);
                timer = new System.Windows.Threading.DispatcherTimer(
                    new TimeSpan(0, 0, 1),
                    System.Windows.Threading.DispatcherPriority.Normal,
                    delegate {
                    timerLabel.Content = time.ToString();
                    if (time == TimeSpan.FromSeconds(10))
                    {
                        timer.Stop();
                    }
                    time = time.Add(TimeSpan.FromSeconds(1));
                },
                    Application.Current.Dispatcher
                    );


                timer.Start();

                //
                WrongPostureClassifier.setRef(this);
            }
        }
예제 #15
0
 private void EnableColorImageStreamBasedOnIsChecked(
     CheckBox checkBox, ColorImageStream imageStream, ComboBox colorFormatsValue)
 {
     if (checkBox.IsChecked.HasValue && checkBox.IsChecked.Value)
     {
         imageStream.Enable((ColorImageFormat)colorFormatsValue.SelectedItem);
     }
     else
     {
         imageStream.Disable();
     }
 }
 public void Enable(ColorImageFormat colorImageFormat)
 {
     _colorImageStream.Enable(colorImageFormat);
 }