public BodyTexture(Microsoft.Research.Kinect.Nui.Runtime nui,Microsoft.Research.Kinect.Nui.SkeletonData skeleton,byte[] latestVideoBytes) { this.skeleton = skeleton; this.latestVideoBytes = latestVideoBytes; this.nui = nui; byte[] thumbBitsLeft = new byte[imgWidth * imgHeight * 4]; byte[] thumbBitsRight = new byte[imgWidth * imgHeight * 4]; this.calcPositions(); for (int y = 0; y < imgHeight; y++) { for (int x = 0; x < imgWidth; x++) { float screenXLeft = 0; float screenYLeft = 0; float screenXRight = 0; float screenYRight = 0; getPosition2D((float)x * 0.5f, y, ref screenXLeft, ref screenYLeft); getPosition2D((float)(x + imgWidth) * 0.5f, y, ref screenXRight, ref screenYRight); if (screenXRight > 1 || screenXRight < 0) screenXRight = 0; if (screenYRight > 1 || screenYRight < 0) screenYRight = 0; if (screenXLeft > 1 || screenXLeft < 0) screenXLeft = 0; if (screenYLeft > 1 || screenYLeft < 0) screenYLeft = 0; int origIndexLeft = ((int)(screenXLeft * (float)origWidth) + (int)(screenYLeft * (float)origHeight) * origWidth) * 4; int origIndexRight = ((int)(screenXRight * (float)origWidth) + (int)(screenYRight * (float)origHeight) * origWidth) * 4; int newIndex = (x + y * imgWidth) * 4; byte[] leftBytesOrig = { latestVideoBytes[origIndexLeft + 0], latestVideoBytes[origIndexLeft + 1], latestVideoBytes[origIndexLeft + 2], latestVideoBytes[origIndexLeft + 3], }; byte[] rightBytesOrig = { latestVideoBytes[origIndexRight + 0], latestVideoBytes[origIndexRight + 1], latestVideoBytes[origIndexRight + 2], latestVideoBytes[origIndexRight + 3], }; byte[] leftBytes = getColorAdjustedRGBA(leftBytesOrig, (double)y / (double)imgHeight); byte[] rightBytes = getColorAdjustedRGBA(rightBytesOrig, (double)y / (double)imgHeight); thumbBitsLeft[newIndex + 0] = leftBytes[0]; thumbBitsLeft[newIndex + 1] = leftBytes[1]; thumbBitsLeft[newIndex + 2] = leftBytes[2]; thumbBitsLeft[newIndex + 3] = leftBytes[3]; thumbBitsRight[newIndex + 0] = rightBytes[0]; thumbBitsRight[newIndex + 1] = rightBytes[1]; thumbBitsRight[newIndex + 2] = rightBytes[2]; thumbBitsRight[newIndex + 3] = rightBytes[3]; } } ImageSourceLeft = BitmapSource.Create(imgWidth, imgHeight, 96, 96, PixelFormats.Bgr32, null, thumbBitsLeft, imgWidth * 4); ImageSourceRight = BitmapSource.Create(imgWidth, imgHeight, 96, 96, PixelFormats.Bgr32, null, thumbBitsRight, imgWidth * 4); }
void OnLoad(object sender, RoutedEventArgs e) { _kinect = KinectNui.Runtime.Kinects[0]; _kinect.Initialize(KinectNui.RuntimeOptions.UseColor | RuntimeOptions.UseSkeletalTracking); _kinect.VideoStream.Open(KinectNui.ImageStreamType.Video, 2, KinectNui.ImageResolution.Resolution640x480, KinectNui.ImageType.Color); _kinect.VideoFrameReady += new EventHandler <KinectNui.ImageFrameReadyEventArgs>(OnKinectVideoReady); _kinect.SkeletonFrameReady += new EventHandler <SkeletonFrameReadyEventArgs>(nui_SkeletonFrameReady); _timer = new Timer(); _timer.Interval = 3000; _timer.Elapsed += new ElapsedEventHandler(OnTimerElapsed); //_bus = ServiceBus.Setup(ServiceBusUtilities.GetServiceBusCredentials()); }
private void Window_Loaded(object sender, EventArgs e) { nui = new Microsoft.Research.Kinect.Nui.Runtime(); drawCore = new SkeletalCore.Draw(); player = new VirtualKinect.Player(); try { nui.Initialize(RuntimeOptions.UseDepthAndPlayerIndex | RuntimeOptions.UseSkeletalTracking | RuntimeOptions.UseColor); } catch (InvalidOperationException) { } player.DepthFrameReady += new EventHandler<VirtualKinect.ImageFrameReadyEventArgs>(nui_DepthFrameReady); player.SkeletonFrameReady += new EventHandler<VirtualKinect.SkeletonFrameReadyEventArgs>(nui_SkeletonFrameReady); player.VideoFrameReady += new EventHandler<VirtualKinect.ImageFrameReadyEventArgs>(nui_ColorFrameReady); }
private void Window_Loaded(object sender, RoutedEventArgs e) { hoverWatch = new Stopwatch(); if (Runtime.Kinects.Count == 0) { Console.Write("missing kinect"); } else { nui = Runtime.Kinects[0]; nui.Initialize(RuntimeOptions.UseColor | RuntimeOptions.UseDepth | RuntimeOptions.UseDepthAndPlayerIndex | RuntimeOptions.UseSkeletalTracking); nui.VideoFrameReady += new EventHandler<ImageFrameReadyEventArgs>(nui_VideoFrameReady); nui.DepthFrameReady += new EventHandler<ImageFrameReadyEventArgs>(nui_DepthFrameReady); nui.VideoStream.Open(ImageStreamType.Video, 2, ImageResolution.Resolution640x480, ImageType.Color); //PoolSize = 2 buffers. One for queuing and one for displaying nui.DepthStream.Open(ImageStreamType.Depth, 2, ImageResolution.Resolution320x240, ImageType.Depth); #region TransformSmooth //Must set to true and set after call to Initialize nui.SkeletonEngine.TransformSmooth = true; //Use to transform and reduce jitter var parameters = new TransformSmoothParameters { Smoothing = 0.75f, Correction = 0.0f, Prediction = 0.0f, JitterRadius = 0.05f, MaxDeviationRadius = 0.04f }; nui.SkeletonEngine.SmoothParameters = parameters; #endregion //add event to receive skeleton data nui.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(nui_SkeletonFrameReady); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { try { /* NuiRuntime = Microsoft.Research.Kinect.Nui.Runtime.Kinects[0]; NuiRuntime.Initialize(RuntimeOptions.UseSkeletalTracking | RuntimeOptions.UseColor); NuiRuntime.VideoStream.Open(ImageStreamType.Video, 2, ImageResolution.Resolution640x480, ImageType.Color); */ // Set up the Kinects NuiRuntime = Microsoft.Research.Kinect.Nui.Runtime.Kinects[0]; NuiRuntime.Initialize(RuntimeOptions.UseDepth | RuntimeOptions.UseDepthAndPlayerIndex | RuntimeOptions.UseColor | RuntimeOptions.UseSkeletalTracking); NuiRuntime.VideoFrameReady += new EventHandler<ImageFrameReadyEventArgs>(nui_VideoFrameReady); NuiRuntime.DepthFrameReady += new EventHandler<ImageFrameReadyEventArgs>(nui_DepthFrameReady); NuiRuntime.SkeletonEngine.TransformSmooth = true; var parameters = new TransformSmoothParameters { Smoothing = 0.3f, Correction = 0.0f, Prediction = 0.0f, JitterRadius = 1.0f, MaxDeviationRadius = 0.5f }; NuiRuntime.SkeletonEngine.SmoothParameters = parameters; try { NuiRuntime.VideoStream.Open(ImageStreamType.Video, 2, ImageResolution.Resolution640x480, ImageType.Color); //PoolSize = 2 buffers. One for queuing and one for displaying } catch (InvalidOperationException) { System.Windows.MessageBox.Show("Failed to open stream. Please make sure to specify a supported image type and resolution."); return; } try { NuiRuntime.DepthStream.Open(ImageStreamType.Depth, 2, ImageResolution.Resolution320x240, ImageType.Depth); } catch (InvalidOperationException) { System.Windows.MessageBox.Show("Failed to open depth stream. Please make sure to specify a supported image type and resolution."); return; } } catch (Exception) { // Failed to set up the Kinect. Show the error onscreen (app will switch to using mouse movement) NuiRuntime = null; PART_ErrorText.Visibility = Visibility.Visible; } }
void OnLoad(object sender, RoutedEventArgs e) { _kinect = KinectNui.Runtime.Kinects[0]; _kinect.Initialize(KinectNui.RuntimeOptions.UseColor | RuntimeOptions.UseSkeletalTracking); _kinect.VideoStream.Open(KinectNui.ImageStreamType.Video, 2, KinectNui.ImageResolution.Resolution640x480, KinectNui.ImageType.Color); _kinect.VideoFrameReady += new EventHandler<KinectNui.ImageFrameReadyEventArgs>(OnKinectVideoReady); _kinect.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(nui_SkeletonFrameReady); _timer = new Timer(); _timer.Interval = 3000; _timer.Elapsed += new ElapsedEventHandler(OnTimerElapsed); //_bus = ServiceBus.Setup(ServiceBusUtilities.GetServiceBusCredentials()); }
private void Window_Loaded(object sender, EventArgs e) { nui = new Runtime(); drawCore = new SkeletalCore.Draw(); try { nui.Initialize(RuntimeOptions.UseDepthAndPlayerIndex | RuntimeOptions.UseSkeletalTracking | RuntimeOptions.UseColor); } catch (InvalidOperationException) { System.Windows.MessageBox.Show("Runtime initialization failed. Please make sure Kinect device is plugged in."); return; } try { nui.VideoStream.Open(ImageStreamType.Video, 2, ImageResolution.Resolution640x480, ImageType.Color); nui.DepthStream.Open(ImageStreamType.Depth, 2, ImageResolution.Resolution320x240, ImageType.DepthAndPlayerIndex); } catch (InvalidOperationException) { System.Windows.MessageBox.Show("Failed to open stream. Please make sure to specify a supported image type and resolution."); return; } nui.DepthFrameReady += new EventHandler<ImageFrameReadyEventArgs>(nui_DepthFrameReady); nui.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(nui_SkeletonFrameReady); nui.VideoFrameReady += new EventHandler<ImageFrameReadyEventArgs>(nui_ColorFrameReady); }