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; }
private void InitializeKinectSensor(KinectSensor kinectSensor) { if (kinectSensor != null) { DepthImageStream depthStream = kinectSensor.DepthStream; depthStream.Enable(); depthImageBitMap = new WriteableBitmap(depthStream.FrameWidth, depthStream.FrameHeight, 96, 96, PixelFormats.Gray16, null); depthImageBitmapRect = new Int32Rect(0, 0, depthStream.FrameWidth, depthStream.FrameHeight); depthImageStride = depthStream.FrameWidth * depthStream.FrameBytesPerPixel; DepthImage.Source = depthImageBitMap; kinectSensor.DepthFrameReady += new EventHandler <DepthImageFrameReadyEventArgs>(kinectSensor_DepthFrameReady); kinectSensor.Start(); } }
private void EnableDepthStreamBasedOnDepthOrSkeletonEnabled( DepthImageStream depthImageStream, ComboBox depthFormatsValue) { if (depthFormatsValue.SelectedItem != null) { // SkeletonViewer needs depth. So if DepthViewer or SkeletonViewer is enabled, enabled depthStream. if ((DepthStreamEnable.IsChecked.HasValue && DepthStreamEnable.IsChecked.Value) || (SkeletonStreamEnable.IsChecked.HasValue && SkeletonStreamEnable.IsChecked.Value)) { depthImageStream.Enable((DepthImageFormat)depthFormatsValue.SelectedItem); } else { depthImageStream.Disable(); } } }
private void InitializeKinectSensor(KinectSensor sensor) { if (kinect != null) { DepthImageStream depthStream = kinect.DepthStream; depthStream.Enable(); this.depthImageBitmap = new WriteableBitmap(depthStream.FrameWidth, depthStream.FrameHeight, 96, 96, PixelFormats.Bgr32, null); this.depthImageBitmapRect = new Int32Rect(0, 0, depthStream.FrameWidth, depthStream.FrameHeight); this.depthImageStride = depthStream.FrameWidth * 4; DepthLevelsImage.Source = this.depthImageBitmap; SkeletonStream skeletonStream = kinect.SkeletonStream; skeletonStream.Enable(); sensor.DepthFrameReady += kinect_DepthFrameReady; sensor.Start(); } }
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がありません。"); } }
private void InitializeKinectSensor(KinectSensor kinectSensor) { if (kinectSensor != null) { ColorImageStream colorStream = kinectSensor.ColorStream; kinectSensor.ColorStream.Enable(ColorImageFormat.RgbResolution1280x960Fps12); 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; kinectSensor.ColorFrameReady += kinectSensor_ColorFrameReady; //kinectSensor.ColorFrameReady += new EventHandler<ColorImageFrameReadyEventArgs>(kinectSensor_ColorFrameReady); this.kinectDevice.SkeletonStream.Enable(); this.frameSkeletons = new Skeleton[this.kinectDevice.SkeletonStream.FrameSkeletonArrayLength]; this.kinectDevice.SkeletonFrameReady += KinectDevice_SkeletonFrameReady; DepthImageStream depthStream = this.kinectDevice.DepthStream; depthStream.Enable(); this.depthImageBitMap = new WriteableBitmap(depthStream.FrameWidth, depthStream.FrameHeight, 96, 96, PixelFormats.Gray16, null); 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; SkeletonStream skeletonStream = this.kinectDevice.SkeletonStream; skeletonStream.Enable(); //suggest choice the last //DepthImage.Source = this.depthImageBitMap; //DepthImage.Source = this._depthImageBitMap; this.kinectDevice.DepthFrameReady += kinectSensor_DepthFrameReady; //kinectSensor.DepthFrameReady += new EventHandler<DepthImageFrameReadyEventArgs>(kinectSensor_DepthFrameReady); this.kinectDevice.Start(); } }
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); } }