void _sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e) { //throw new NotImplementedException(); using (ColorImageFrame colorFrame = e.OpenColorImageFrame()) { if (colorFrame == null) { return; } byte[] pixels = new byte[colorFrame.PixelDataLength]; //copy data out into our byte array colorFrame.CopyPixelDataTo(pixels); int stride = colorFrame.Width * 4; image2.Source = BitmapSource.Create(colorFrame.Width, colorFrame.Height, 96, 96, PixelFormats.Bgr32, null, pixels, stride); if (playerDepth > 500) { ScaleTransform scaly = new ScaleTransform(.5, .5); image3.RenderTransform = scaly; } } using (DepthImageFrame depthFrame = e.OpenDepthImageFrame()) { if (depthFrame == null) { return; } } }
void kinect_AllFramesReady( object sender, AllFramesReadyEventArgs e ) { using ( var colorFrame = e.OpenColorImageFrame() ) { if ( colorFrame != null ) { var pixel = new byte[colorFrame.PixelDataLength]; colorFrame.CopyPixelDataTo( pixel ); ImageRgb.Source = BitmapSource.Create( colorFrame.Width, colorFrame.Height, 96, 96, PixelFormats.Bgr32, null, pixel, colorFrame.Width * 4 ); } } using ( var depthFrame = e.OpenDepthImageFrame() ) { if ( depthFrame != null ) { // Depth情報を入れる // GetRawPixelData()はインタラクションライブラリ内で実装された拡張メソッド stream.ProcessDepth( depthFrame.GetRawPixelData(), depthFrame.Timestamp ); } } using ( var skeletonFrame = e.OpenSkeletonFrame() ) { if ( skeletonFrame != null ) { var skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength]; skeletonFrame.CopySkeletonDataTo( skeletons ); // スケルトン情報を入れる stream.ProcessSkeleton( skeletons, kinect.AccelerometerGetCurrentReading(), skeletonFrame.Timestamp ); } } }
void GetCameraPoint(Skeleton first, AllFramesReadyEventArgs e) { using (DepthImageFrame depth = e.OpenDepthImageFrame()) { if (depth == null || kinectSensorChooser1.Kinect == null) { return; } //Map a joint location to a point on the depth map //left hand DepthImagePoint leftDepthPoint = depth.MapFromSkeletonPoint(first.Joints[JointType.HandLeft].Position); //Map a depth point to a point on the color image //left hand ColorImagePoint leftColorPoint = depth.MapToColorImagePoint(leftDepthPoint.X, leftDepthPoint.Y, ColorImageFormat.RgbResolution640x480Fps30); CameraPosition(arrow, leftColorPoint); SwipeCheck(leftColorPoint.X); } }
void GetCameraPoint(Skeleton first, AllFramesReadyEventArgs e) { using (DepthImageFrame depth = e.OpenDepthImageFrame()) { if (depth == null || _sensor == null) { return; } DepthImagePoint headDepthPoint = this._sensor.CoordinateMapper.MapSkeletonPointToDepthPoint( first.Joints[JointType.Head].Position, DepthImageFormat.Resolution640x480Fps30); DepthImagePoint leftDepthPoint = this._sensor.CoordinateMapper.MapSkeletonPointToDepthPoint( first.Joints[JointType.HandLeft].Position, DepthImageFormat.Resolution640x480Fps30); DepthImagePoint rightDepthPoint = this._sensor.CoordinateMapper.MapSkeletonPointToDepthPoint( first.Joints[JointType.HandRight].Position, DepthImageFormat.Resolution640x480Fps30); ColorImagePoint headColorPoint = this._sensor.CoordinateMapper.MapDepthPointToColorPoint( DepthImageFormat.Resolution640x480Fps30, headDepthPoint, ColorImageFormat.RgbResolution640x480Fps30); ColorImagePoint leftColorPoint = this._sensor.CoordinateMapper.MapDepthPointToColorPoint( DepthImageFormat.Resolution640x480Fps30, leftDepthPoint, ColorImageFormat.RgbResolution640x480Fps30); ColorImagePoint rightColorPoint = this._sensor.CoordinateMapper.MapDepthPointToColorPoint( DepthImageFormat.Resolution640x480Fps30, rightDepthPoint, ColorImageFormat.RgbResolution640x480Fps30); CameraPosition(ellipseHead, headColorPoint); CameraPosition(ellipseLeft, leftColorPoint); CameraPosition(ellipseRight, rightColorPoint); } }
void RuntimeDepthFrameReady(AllFramesReadyEventArgs e) { using (DepthImageFrame depthFrame = e.OpenDepthImageFrame()) { if (depthFrame == null) { return; } //turn raw data into array of distances var depthArray = depthFrame.ToDepthArray(); //get image DepthImage.Image = depthFrame.ToBitmap(); //get midpoint MidPointDistanceViaGetDistanceText.Text = depthFrame.GetDistance(depthFrame.Width/2, depthFrame.Height/2).ToString(); //image DepthImageWithMinDistance.Image = depthArray.ToBitmap(depthFrame.Width, depthFrame.Height, _minDistance, Color.FromArgb(255, 255, 0, 0)); if (_saveDepthFrame) { _saveDepthFrame = false; depthFrame.ToBitmap().Save(DateTime.Now.ToString("yyyyMMddHHmmss") + "_depth.jpg", ImageFormat.Jpeg); } } }
void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e) { //throw new NotImplementedException(); using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { // check for frame drop. if (skeletonFrame == null) { return; } // copy the frame data in to the collection skeletonFrame.CopySkeletonDataTo(totalSkeleton); // get the first Tracked skeleton Skeleton firstSkeleton = (from trackskeleton in totalSkeleton where trackskeleton.TrackingState == SkeletonTrackingState.Tracked select trackskeleton).FirstOrDefault(); // if the first skeleton returns null if (firstSkeleton == null) { return; } this.myCanvas.Children.Clear(); this.DrawSkeleton(firstSkeleton); recognitionEngine.Skeleton = firstSkeleton; recognitionEngine.StartRecognize(); } }
private void AllFramesReady(object sender,AllFramesReadyEventArgs e) { using(ColorImageFrame colorImage=e.OpenColorImageFrame()) using(SkeletonFrame skeletonFrame=e.OpenSkeletonFrame()) if(colorImage!=null&&skeletonFrame!=null){ colorImage.CopyPixelDataTo(bitmappixels); skeletonFrame.CopySkeletonDataTo(skeletons); bitmap.WritePixels(updateRect,bitmappixels,bitmap.PixelWidth*sizeof(int),0); using(DrawingContext drawingContext=drawingGroup.Open()){ drawingContext.DrawImage(bitmap,drawingRect); //drawingContext.DrawGeometry(button1.IsHitting?Brushes.White:null,new Pen(Brushes.Blue,2.0),button1.Geometry); //drawingContext.DrawGeometry(button2.IsHitting?Brushes.White:null,new Pen(Brushes.Blue,2.0),button2.Geometry); foreach(Skeleton skel in skeletons){ if(skel.TrackingState==SkeletonTrackingState.Tracked){ foreach(Joint joint in skel.Joints){ if(joint.TrackingState==JointTrackingState.Tracked){ var depthPoint=sensor.MapSkeletonPointToDepth(joint.Position,DepthImageFormat.Resolution640x480Fps30); drawingContext.DrawEllipse(Brushes.Green,null,new Point(depthPoint.X,depthPoint.Y),15,15); } } drawingContext.DrawRectangle(Brushes.Red,null,new Rect(0.0,0.0,distance1.Distance,50.0)); drawingContext.DrawLine(new Pen(Brushes.Blue,10),volume1.MiddlePoint,volume1.RightHandLocation); var mat=Matrix.Identity; mat.RotateAt(volume1.Angle,volume1.MiddlePoint.X,volume1.MiddlePoint.Y); drawingContext.DrawLine(new Pen(Brushes.Blue,10),volume1.MiddlePoint,mat.Transform(volume1.RightHandLocation)); drawingContext.DrawText(new FormattedText(volume1.Angle.ToString(),CultureInfo.CurrentCulture,FlowDirection.LeftToRight,new Typeface("MS Gothic"),150,Brushes.Blue),new Point()); break; } } } } return; }
void Kinect_AllFramesReady(object sender, AllFramesReadyEventArgs e) { _skeletonData.ToList().ForEach(s => { if (s.TrackingState == SkeletonTrackingState.Tracked) { var rightHand = s.Joints.First(x => x.JointType == JointType.HandRight); var leftHand = s.Joints.First(x => x.JointType == JointType.HandLeft); var r = rightHand.ScaleTo(571, 500); var l = leftHand.ScaleTo(571, 500); _hub.Invoke("MoveShape", new { hand = "right", x = r.Position.X, y = r.Position.Y}, new { hand = "left", x = l.Position.X, y = l.Position.Y } ); Log(string.Format("Right X: {0} Right Y: {1}, Left X: {2}, Left Y: {3}", r.Position.X, r.Position.Y, l.Position.X, l.Position.Y)); } }); Array.Clear(_skeletonData, 0, _skeletonData.Length); }
void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e) { using (ColorImageFrame frame = e.OpenColorImageFrame()) { if (frame == null) { return; } byte[] pixels = new byte[frame.PixelDataLength]; int stride = frame.Width * 4; frame.CopyPixelDataTo(pixels); imagecolor.Source = BitmapSource.Create(frame.Width, frame.Height, 96, 96, PixelFormats.Bgr32, null, pixels, stride); Skeleton first = GetFirstSkeleton(e); if (first == null) { return; } //set scaled position //ScalePosition(lShoulderEllipse, first.Joints[JointType.ShoulderLeft]); //ScalePosition(rShoulderEllipse, first.Joints[JointType.ShoulderRight]); //ScalePosition(lKneeEllipse, first.Joints[JointType.KneeLeft]); //ScalePosition(rKneeEllipse, first.Joints[JointType.KneeRight]); //ScalePosition(rHandEllipse, first.Joints[JointType.HandRight]); GetCameraPoint(first, e); } }
private Skeleton GetTrackedSkeleton(AllFramesReadyEventArgs e) { using (SkeletonFrame skeletonFrameData = e.OpenSkeletonFrame()) { SkeletonDetected = false; if (skeletonFrameData == null) { return null; } // Kinect SDK always returns 6 skeleton const int skeletonCount = 6; Skeleton[] allSkeletons = new Skeleton[skeletonCount]; skeletonFrameData.CopySkeletonDataTo(allSkeletons); //Get the first tracked skeleton out of the 6 Skeleton trackedSkeleton = null; foreach (Skeleton skeleton in allSkeletons) { // if no skeleton is tracked, null will be returned. if (skeleton.TrackingState == SkeletonTrackingState.Tracked) { trackedSkeleton = skeleton; SkeletonDetected = true; break; } } return trackedSkeleton; } }
void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e) { using (ColorImageFrame colorFrame = e.OpenColorImageFrame()) { if (colorFrame != null) { // Create byte array with pixel data byte[] pixels = new byte[colorFrame.PixelDataLength]; colorFrame.CopyPixelDataTo(pixels); // Bytes/row = 4 * with (for bgr32) int stride = colorFrame.Width * 4; // Display image img_colorimage.Source = BitmapSource.Create(colorFrame.Width, colorFrame.Height, 96, 96, PixelFormats.Bgr32, null, pixels, stride); } } // Auto dispose using (DepthImageFrame depthFrame = e.OpenDepthImageFrame()) { if (depthFrame != null) { // Set colors based on depth byte[] pixels = GenerateColoredBytes(depthFrame); // Bytes/row = 4 * with (for bgr32) int stride = depthFrame.Width * 4; // Display image img_depthimage.Source = BitmapSource.Create(depthFrame.Width, depthFrame.Height, 96, 96, PixelFormats.Bgr32, null, pixels, stride); } } // Auto dispose }
public void KinectAllFramesReady(object sender,AllFramesReadyEventArgs e) { using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { if (skeletonFrame != null && screenManager != null) { // take skeleton data and update avatar state skeletonFrame.CopySkeletonDataTo(skeletonData); float headX = skeletonData[0].Joints[JointType.Head].Position.X; //floats between -1 and 1 float headY = skeletonData[0].Joints[JointType.Head].Position.Y; midViewPort.X = screenManager.GraphicsDevice.Viewport.Width / 2; midViewPort.Y = screenManager.GraphicsDevice.Viewport.Height / 2; //set the posistion of the head's rectangle to be in the center of the screen and move by the joint amount //TODO: figure out if skeleton data stream has lower left origin, because XNA has upper left origin and we adjust for that. head.SetRectPos((int)((headX * 100) + midViewPort.X), (int)((headY * 100) + midViewPort.Y)); //head.SetRectPos((int)((headX * 100)), (int)((headY * 100) )); // Console.WriteLine( "head: " + head.Rectangle.X + ", " + head.Rectangle.Y ); Console.WriteLine("joint: " + headX + ", " + headY); } else { // skeletonFrame is null because the request did not arrive in time } } }
void _sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e) { using (ColorImageFrame colorFrame = e.OpenColorImageFrame()) { if (colorFrame == null) { return; } byte[] pixels = new byte[colorFrame.PixelDataLength]; colorFrame.CopyPixelDataTo(pixels); int stride = colorFrame.Width * 4; imageRGB.Source = BitmapSource.Create(colorFrame.Width, colorFrame.Height, 96, 96, PixelFormats.Bgr32, null, pixels, stride); } }
void mySensor_AllFramesReady(object sender, AllFramesReadyEventArgs e) { ColorImageFrame c = e.OpenColorImageFrame(); DepthImageFrame d = e.OpenDepthImageFrame(); bool myRenderFlag = (bool)ChkRender.IsChecked; if (c == null || d == null) return; c.CopyPixelDataTo(myColorArray); d.CopyPixelDataTo(myArray); for(int x = 0; x < 640; x++) { for (int y = 0; y < 480; y++) { short depthVal = myArray[y * 640 + x]; depthVal = (short)(depthVal >> DepthImageFrame.PlayerIndexBitmaskWidth); depthVal = (short)(depthVal << DepthImageFrame.PlayerIndexBitmaskWidth); depthVal /= 255; if(myRenderFlag==true) myColorArray[(y * 640 + x) * 4 + 1] = (byte)depthVal;// (byte)(myColorArray[(y * 640 + x) * 4 + 1] / 2 + (byte)depthVal / 2); myColorArray[(y * 640 + x) * 4 + 3] = 255; } } myBitmap.WritePixels( new Int32Rect(0, 0, myBitmap.PixelWidth, myBitmap.PixelHeight), myColorArray, myBitmap.PixelWidth * 4, 0); c.Dispose(); d.Dispose(); }
private void KinectSensorOnAllFramesReady(object sender, AllFramesReadyEventArgs allFramesReadyEventArgs) { using (var colorImageFrame = allFramesReadyEventArgs.OpenColorImageFrame()) { if (colorImageFrame == null) { return; } // Make a copy of the color frame for displaying. var haveNewFormat = this.currentColorImageFormat != colorImageFrame.Format; if (haveNewFormat) { this.currentColorImageFormat = colorImageFrame.Format; this.colorImageData = new byte[colorImageFrame.PixelDataLength]; this.colorImageWritableBitmap = new WriteableBitmap( colorImageFrame.Width, colorImageFrame.Height, 96, 96, PixelFormats.Bgr32, null); ColorImage.Source = this.colorImageWritableBitmap; } colorImageFrame.CopyPixelDataTo(this.colorImageData); this.colorImageWritableBitmap.WritePixels( new Int32Rect(0, 0, colorImageFrame.Width, colorImageFrame.Height), this.colorImageData, colorImageFrame.Width * Bgr32BytesPerPixel, 0); } }
void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e) { if (closing) { return; } //Get a skeleton Skeleton first = GetFirstSkeleton(e); if (first == null) { return; } //set scaled position //ScalePosition(head, first.Joints[JointType.Head]); //ScalePosition(leftHand, first.Joints[JointType.HandLeft]); //ScalePosition(rightHand, first.Joints[JointType.HandRight]); //ScalePosition(rightShoulder, first.Joints[JointType.ShoulderRight]); //ScalePosition(leftShoulder, first.Joints[JointType.ShoulderLeft]); GetCameraPoint(first, e); }
void kinect_AllFramesReady( object sender, AllFramesReadyEventArgs e ) { // 赤外線画像を表示する using ( ColorImageFrame colorFrame = e.OpenColorImageFrame() ) { if ( colorFrame != null ) { // 赤外線画像データを取得する byte[] color = new byte[colorFrame.PixelDataLength]; colorFrame.CopyPixelDataTo( color ); // 赤外線画像を表示する(16bitのグレースケール) imageInfrared.Source = BitmapSource.Create( colorFrame.Width, colorFrame.Height, 96, 96, PixelFormats.Gray16, null, color, colorFrame.Width * colorFrame.BytesPerPixel ); } } // 距離データを表示する using ( DepthImageFrame depthFrame = e.OpenDepthImageFrame() ) { if ( depthFrame != null ) { // 可視画像に変換する short[] depth = new short[depthFrame.PixelDataLength]; depthFrame.CopyPixelDataTo( depth ); for ( int i = 0; i < depth.Length; i++ ) { depth[i] = (short)~depth[i]; } imageDepth.Source = BitmapSource.Create( depthFrame.Width, depthFrame.Height, 96, 96, PixelFormats.Gray16, null, depth, depthFrame.Width * depthFrame.BytesPerPixel ); } } }
void kinect_AllFramesReady( object sender, AllFramesReadyEventArgs e ) { image1.Source = e.OpenColorImageFrame().ToBitmapSource(); // スケルトンフレームを取得する SkeletonFrame skeletonFrame = e.OpenSkeletonFrame(); if ( skeletonFrame != null ) { // スケルトンデータを取得する Skeleton[] skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength]; skeletonFrame.CopySkeletonDataTo( skeletonData ); // プレーヤーごとのスケルトンを描画する foreach ( var skeleton in skeletonData ) { var head = skeleton.Joints[JointType.Head]; if ( head.TrackingState == JointTrackingState.Tracked ) { ColorImagePoint point = kinect.MapSkeletonPointToColor( head.Position, kinect.ColorStream.Format ); var x = image2.Width / 2; var y = image2.Height / 2; image2.Margin = new Thickness( point.X - x, point.Y - y, 0, 0 ); image2.Visibility = System.Windows.Visibility.Visible; } } } }
bool working = false; // Skip frames if we're still processing stuff. public void CalibrationAllFramesReady(object sender, AllFramesReadyEventArgs e) { if (working) return; working = true; using (ColorImageFrame colorFrame = e.OpenColorImageFrame()) { if (colorFrame == null) { working = false; return; } using (DepthImageFrame depthFrame = e.OpenDepthImageFrame()) { if (depthFrame == null) { working = false; return; } //byte[] pixels = new byte[colorFrame.PixelDataLength]; //colorFrame.CopyPixelDataTo(pixels); //int stride = colorFrame.Width * 4; //debugImage.Source = BitmapSource.Create(colorFrame.Width, colorFrame.Height, 96, 96, PixelFormats.Bgr32, null, pixels, stride); //debugImage.Visibility = Visibility.Visible; //int code_num = find_code(colorFrame, depthFrame); int code_num = find_touch(colorFrame, depthFrame); if (code_num >= 0) { // Make the next code visible. if (code_num < 4) { codes[code_num].Visibility = Visibility.Hidden; codes[code_num + 1].Visibility = Visibility.Visible; next_code_num++; Thread.Sleep(3000); } else { Thread.Sleep(3000); // We are done. Calculate the coefficients. sensor.AllFramesReady -= this.CalibrationAllFramesReady; codes[4].Visibility = Visibility.Hidden; kinectController.calibration_coefficients = get_calibration_coeffs(); Point center_top_left = code_points[0]; Point center_bot_right = code_points[4]; kinectController.Calibrate((int)(center_top_left.X + 1.25*code_size.X), (int)(center_top_left.Y + 0.7*code_size.Y), (int)(center_bot_right.X - 1.25*code_size.X), (int)(center_bot_right.Y - 0.8*code_size.Y)); sensor.AllFramesReady += kinectController.SensorAllFramesReady; CalibrationDidComplete(); } } } } working = false; }
void Kinect_AllFramesReady(object sender, AllFramesReadyEventArgs e) { using (var Frame = e.OpenColorImageFrame()) { if (Frame != null) { Frame.CopyPixelDataTo(Pixels); Bitmap.WritePixels( new Int32Rect(0, 0, Bitmap.PixelWidth, Bitmap.PixelHeight), Pixels, Bitmap.PixelWidth * sizeof(int), 0); } } using (var Frame = e.OpenSkeletonFrame()) { if (Frame != null) { var skeletons = new Skeleton[Frame.SkeletonArrayLength]; Frame.CopySkeletonDataTo(skeletons); var skel = (from s in skeletons where s.TrackingState == SkeletonTrackingState.Tracked select s).FirstOrDefault(); if (skel != null) { var left_hand = skel.Joints[JointType.HandLeft]; var rite_hand = skel.Joints[JointType.HandRight]; var shoulderRight = skel.Joints[JointType.ShoulderRight]; var fleft = skel.Joints[JointType.FootLeft]; var frite = skel.Joints[JointType.FootRight]; Joint head = skel.Joints[JointType.Head]; Point mousePos = new Point((rite_hand.Position.X * 1300 + 683), (rite_hand.Position.Y * -1300 + 768)); //двойное нажатие левой кнопкой мыши if (distance(head.Position, left_hand.Position) < 0.06f) { NatiteMethods.sendMouseDoubleClick(mousePos); // правая кнопка мыши } else if(distance(left_hand.Position, rite_hand.Position) < 0.03f) { NatiteMethods.mouseLeftButtonDown(mousePos); // перетаскивание } else if(distance(shoulderRight.Position, left_hand.Position) < 0.03f) { NatiteMethods.sendMouseRightclick(mousePos); } if (fleft.Position.Y <= fleft.Position.Y + 0.5f) { // Get the virtual key code for the character we want to press //int key = 87; //uint vkKey = NatiteMethods.VkKeyScan((char) key); //NatiteMethods.keybd_event(vkKey, 0, 0, 0); //NatiteMethods.keybd_event(vkKey, 0, 2, 0); } NatiteMethods.SetCursorPos((int) mousePos.X, (int) mousePos.Y); } } } }
private void AllFramesReady(object sender,AllFramesReadyEventArgs e) { if(secondBuffer!=null){ using(ColorImageFrame colorImage=e.OpenColorImageFrame()) using(SkeletonFrame skeletonFrame=e.OpenSkeletonFrame()) if(colorImage!=null&&skeletonFrame!=null){ skeletonFrame.CopySkeletonDataTo(skeletons); //colorImage.CopyPixelDataTo(bitmappixels); //bitmap.WritePixels(updateRect,bitmappixels,bitmap.PixelWidth*sizeof(int),0); using(DrawingContext drawingContext=drawingGroup.Open()){ //drawingContext.DrawImage(bitmap,drawingRect); drawingContext.DrawRectangle(Brushes.Black,null,drawingRect); var redPen=new Pen(Brushes.Red,5.0); drawingContext.DrawGeometry(button.IsHitting?Brushes.White:null,redPen,button.Geometry); drawingContext.DrawGeometry(muteButton.IsHitting?Brushes.White:null,redPen,muteButton.Geometry); //drawingContext.DrawGeometry(boostButton.IsHitting?Brushes.White:null,redPen,boostButton.Geometry); drawingContext.DrawGeometry(gateButton.IsHitting?Brushes.White:null,redPen,gateButton.Geometry); drawingContext.DrawText(new FormattedText(secondBuffer.Status.Playing?"■":"▶",CultureInfo.CurrentCulture,FlowDirection.LeftToRight,new Typeface("メイリオ"),44,Brushes.Red),new Point(0,0)); foreach(Skeleton skel in skeletons){ if(skel.TrackingState==SkeletonTrackingState.Tracked){ foreach(Joint joint in skel.Joints){ if(joint.TrackingState==JointTrackingState.Tracked){ var depthPoint=sensor.CoordinateMapper.MapSkeletonPointToDepthPoint(joint.Position,DepthImageFormat.Resolution640x480Fps30); drawingContext.DrawEllipse(Brushes.Green,null,new Point(depthPoint.X,depthPoint.Y),10,10); } } if(mode==1){ drawingContext.DrawLine(new Pen(Brushes.DarkBlue,20),distance.Joint1Location,distance.Joint2Location); var volume=-10000+(distance.Distance<=250?distance.Distance:250)*35; if(timer.IsEnabled) prevvolume=volume; else secondBuffer.Volume=volume; }else if(mode==2){ var pen=new Pen(new SolidColorBrush(Color.FromArgb(0x7F,0,0,0x8B)),12.5); drawingContext.DrawLine(pen,volume.MiddlePoint,volume.RightHandLocation); var mat=Matrix.Identity; mat.RotateAt(volume.Angle,volume.MiddlePoint.X,volume.MiddlePoint.Y); drawingContext.DrawLine(pen,volume.MiddlePoint,mat.Transform(volume.RightHandLocation)); settings[0].Gain=15/180*(-volume.Angle); settings[1].Gain=10/180*(-volume.Angle); settings[2].Gain=15/180*(volume.Angle); settings[3].Gain=15/180*(volume.Angle); settings[4].Gain=15/180*(volume.Angle); for(int i=0;i<settings.Length;i++){ var effectInst=(ParamEqEffect)secondBuffer.GetEffects(i); effectInst.AllParameters=settings[i]; } } drawingContext.DrawText(new FormattedText("ControlMode:"+(mode==0?"None":mode==1?"Volume":"Filter"),CultureInfo.CurrentCulture,FlowDirection.LeftToRight,new Typeface("メイリオ"),40,Brushes.White),new Point(0,400)); if(muteButton.IsHitting){ secondBuffer.Volume=-10000; } break; } } } } } return; }
private void kinect_AllFramesReady(object sender, AllFramesReadyEventArgs e) { byte[] imagem = ObterImagemSensorRGB(e.OpenColorImageFrame()); if (chkEscalaCinza.IsChecked.HasValue && chkEscalaCinza.IsChecked.Value) ReconhecerDistancia(e.OpenDepthImageFrame(), imagem, 2000); if (imagem != null) imagemCamera.Source = BitmapSource.Create(kinect.ColorStream.FrameWidth, kinect.ColorStream.FrameHeight, 96, 96, PixelFormats.Bgr32, null, imagem, kinect.ColorStream.FrameBytesPerPixel * kinect.ColorStream.FrameWidth); }
/// <summary> /// Manage frames of kinect sensor according to the services activated /// </summary> /// <param name="e"></param> private void ManageAllFrame(AllFramesReadyEventArgs e) { if (!IsRunning) { return; } // SkeletonTracking Frame Manager using (SkeletonFrame SFrame = e.OpenSkeletonFrame()) { try { ManageSkeletonFrame(SFrame); } catch (Exception ex) { // Just log the error Console.Error.WriteLine("Error with skeleton frame : " + ex.Message + " _ " + ex.StackTrace); } } // Color Frame Manager if (PropertiesPluginKinect.Instance.EnableColorFrameService) { using (ColorImageFrame CFrame = e.OpenColorImageFrame()) { try { ManageColorFrame(CFrame); } catch (Exception ex) { // Just log the error Console.Error.WriteLine("Error with color frame : " + ex.Message + " _ " + ex.StackTrace); } } } // Depth Frame Manager if (PropertiesPluginKinect.Instance.EnableDepthFrameService || PropertiesPluginKinect.Instance.KinectPointingModeEnabled || PropertiesPluginKinect.Instance.EnableGestureGrip) { using (DepthImageFrame DFrame = e.OpenDepthImageFrame()) { try { ManageDepthFrame(DFrame); } catch (Exception ex) { // Just log the error Console.Error.WriteLine("Error with depth frame : " + ex.Message + " _ " + ex.StackTrace); } } } }
private void KinectSensorOnAllFramesReady(object sender, AllFramesReadyEventArgs allFramesReadyEventArgs) { using (var colorImageFrame = allFramesReadyEventArgs.OpenColorImageFrame()) { if (colorImageFrame == null) { return; } // Make a copy of the color frame for displaying. var haveNewFormat = this.currentColorImageFormat != colorImageFrame.Format; if (haveNewFormat) { this.currentColorImageFormat = colorImageFrame.Format; this.colorImageData = new byte[colorImageFrame.PixelDataLength]; this.colorImageWritableBitmap = new WriteableBitmap( colorImageFrame.Width, colorImageFrame.Height, 96, 96, PixelFormats.Bgr32, null); ColorImage.Source = this.colorImageWritableBitmap; } colorImageFrame.CopyPixelDataTo(this.colorImageData); this.colorImageWritableBitmap.WritePixels( new Int32Rect(0, 0, colorImageFrame.Width, colorImageFrame.Height), this.colorImageData, colorImageFrame.Width * Bgr32BytesPerPixel, 0); /* double length = Point.Subtract(faceTrackingViewer.ppLeft, faceTrackingViewer.ppRight).Length; tB.Text = length.ToString(); if (length > 19) { elp.Fill = Brushes.Red; } else { elp.Fill = Brushes.Green; } */ double mouthWidth = faceTrackingViewer.mouthWidth; double noseWidth = faceTrackingViewer.noseWidth; double threshold = noseWidth * modifyValue; tBMouthDistance.Text = mouthWidth.ToString(); tbThreshold.Text = threshold.ToString(); if (mouthWidth > threshold) { elp.Fill = Brushes.Red; } else { elp.Fill = Brushes.Green; } } }
void GetCameraPoint(Skeleton first, AllFramesReadyEventArgs e) { using (DepthImageFrame depth = e.OpenDepthImageFrame()) { if (depth == null || _sensor == null) { return; } //Map a joint location to a point on the depth map //head DepthImagePoint headDepthPoint = depth.MapFromSkeletonPoint(first.Joints[JointType.Head].Position); //left hand DepthImagePoint leftHandDepthPoint = depth.MapFromSkeletonPoint(first.Joints[JointType.HandLeft].Position); //right hand DepthImagePoint rightHandDepthPoint = depth.MapFromSkeletonPoint(first.Joints[JointType.HandRight].Position); //left foot DepthImagePoint leftFootDepthPoint = depth.MapFromSkeletonPoint(first.Joints[JointType.HandRight].Position); //right foot DepthImagePoint rightFootDepthPoint = depth.MapFromSkeletonPoint(first.Joints[JointType.HandRight].Position); //hip DepthImagePoint hipDepthPoint = depth.MapFromSkeletonPoint(first.Joints[JointType.HipCenter].Position); //Map a depth point to a point on the color image //head ColorImagePoint headColorPoint = depth.MapToColorImagePoint(headDepthPoint.X, headDepthPoint.Y, ColorImageFormat.RgbResolution640x480Fps30); //left hand ColorImagePoint leftHandColorPoint = depth.MapToColorImagePoint(leftHandDepthPoint.X, leftHandDepthPoint.Y, ColorImageFormat.RgbResolution640x480Fps30); //right hand ColorImagePoint rightHandColorPoint = depth.MapToColorImagePoint(rightHandDepthPoint.X, rightHandDepthPoint.Y, ColorImageFormat.RgbResolution640x480Fps30); //left foot ColorImagePoint leftFootColorPoint = depth.MapToColorImagePoint(leftFootDepthPoint.X, leftFootDepthPoint.Y, ColorImageFormat.RgbResolution640x480Fps30); //right foot ColorImagePoint rightFootColorPoint = depth.MapToColorImagePoint(rightFootDepthPoint.X, rightFootDepthPoint.Y, ColorImageFormat.RgbResolution640x480Fps30); //hip ColorImagePoint hipColorPoint = depth.MapToColorImagePoint(hipDepthPoint.X, hipDepthPoint.Y, ColorImageFormat.RgbResolution640x480Fps30); } }
// すべてのデータの更新通知を受け取る void kinect_AllFramesReady(object sender, AllFramesReadyEventArgs e) { using (ColorImageFrame colorFrame = e.OpenColorImageFrame()) { using (DepthImageFrame depthFrame = e.OpenDepthImageFrame()) { RenderScreen(colorFrame, depthFrame); } } }
/// <summary> /// 表示データを更新する /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void kinect_AllFramesReady( object sender, AllFramesReadyEventArgs e ) { Vector4 accelerometer = kinect.AccelerometerGetCurrentReading(); textAccelerometerX.Text = accelerometer.X.ToString(); textAccelerometerY.Text = accelerometer.Y.ToString(); textAccelerometerZ.Text = accelerometer.Z.ToString(); textAngle.Text = GetAccelerometerAngle().ToString(); textTiltAngle.Text = kinect.ElevationAngle.ToString(); }
void NewSensor_AllFramesReady(object sender, AllFramesReadyEventArgs e) { using (var colorFrame = e.OpenColorImageFrame()) { if (colorFrame == null) { return; } Coding4Fun.Kinect.Wpf.WriteableBitmapHelper.WritePixelsForColorImageFrame(colorFrame, _colorBitmap); } }
private void Kinect_AllFramesReady(object sender, AllFramesReadyEventArgs e) { if (cnt++ < 3) return; cnt = 0; using (var f = e.OpenDepthImageFrame()) { var pd = f.GetRawPixelData(); int mx = 1000, my = 1000, Mx = 0, My = 0; for (int i = 0; i < 320; i++) { for (int j = 0; j < 240; j++) { if (get(pd, i, j).PlayerIndex > 0) { if (i < mx) mx = i; if (i > Mx) Mx = i; if (j < my) my = j; if (j > My) My = j; } } } if (mx<1000) { float wc = (Mx - mx) / 16; float hc = (My - my) / 16; if (keep_proportions) { if (hc < wc) hc = wc; else wc = hc; } Console.WriteLine("mx={0},Mx={1},my={2},My={3}", mx, Mx, my, My); for (int j=0;j<16;j++) { int b1 = 0; for (int i = 0; i<8; i++) { b1 = b1 * 2 + ((get(pd, mx + (int)(wc * i), my + (int)(hc * j)).PlayerIndex > 0) ? 1 : 0); } int b2 = 0; for (int i = 8; i < 16; i++) { b2 = b2 * 2 + ((get(pd, mx + (int)(wc * i), my + (int)(hc * j)).PlayerIndex > 0) ? 1 : 0); } byte[] x = new byte[2]; x[0] = (byte)b1; x[1] = (byte)b2; COM.Write(x, 0, 2); Console.WriteLine("Sending {0},{1}", b1, b2); } } // Console.Write("{0}\r", pd.Length); } }
private void GetCameraPoint(Skeleton first, AllFramesReadyEventArgs e) { using (DepthImageFrame depthFrame = e.OpenDepthImageFrame()) { if (depthFrame == null || _sensor == null) return; // DepthImagePoint headDepthPoint = depthFrame.MapFromSkeletonPoint(first.Joints[JointType.Head].Position); //left hand point information DepthImagePoint LeftHandDepthPoint = depthFrame.MapFromSkeletonPoint(first.Joints[JointType.HandLeft].Position); LeftHandPoint newLeftHandPoint = new LeftHandPoint() { X = LeftHandDepthPoint.X, Y = LeftHandDepthPoint.Y, Z = LeftHandDepthPoint.Depth, T = DateTime.Now }; DepthImagePoint HeadDepthPoint = depthFrame.MapFromSkeletonPoint(first.Joints[JointType.Head].Position); HeadPoint newHeadPoint = new HeadPoint() { X = HeadDepthPoint.X, Y = HeadDepthPoint.Y, Z = HeadDepthPoint.Depth, T = DateTime.Now }; //user should stand in the right place before eveything start // the two if condition requires the user to stand in front of Kinect in a box area if (newHeadPoint.Z < 1700 || newHeadPoint.Z > 2000) { StatusLabel.Visibility = System.Windows.Visibility.Hidden; StatusLabel.Content = ""; return; } StatusLabel.Visibility = System.Windows.Visibility.Visible; StatusLabel.Content = "Control Mode(1.7m~2m): " + newHeadPoint.Z / 1000 + "m"; // left hand wave to quit system if (newLeftHandPoint.Y < newHeadPoint.Y) { // MessageBox.Show("Left wave"); LeftHandWave(newLeftHandPoint, newHeadPoint); } else { IsLeftHandWave = false; } }// end of using statement }
void sensor_ColorFrameReady(AllFramesReadyEventArgs e) { using (ColorImageFrame colorFrame = e.OpenColorImageFrame()) { if (colorFrame == null) { return; } //set image ColorImage.Source = colorFrame.ToBitmapSource(); if (_saveColorFrame) { //save image colorFrame.ToBitmapSource().Save(DateTime.Now.ToString("yyyyMMddHHmmss") + "_color.jpg", ImageFormat.Jpeg); } } }
Skeleton GetFirstSkeleton(AllFramesReadyEventArgs e) { using (SkeletonFrame skeletonFrameData = e.OpenSkeletonFrame()) { if (skeletonFrameData == null) { return(null); } skeletonFrameData.CopySkeletonDataTo(allSkeletons); //Linq语法,查找第一个被跟踪的骨骼 Skeleton first = (from s in allSkeletons where s.TrackingState == SkeletonTrackingState.Tracked select s).FirstOrDefault(); return(first); } }
void newSensor_AllFramesReady(object sender, AllFramesReadyEventArgs e) { using (DepthImageFrame depthFrame = e.OpenDepthImageFrame()) { if (depthFrame == null) { return; } byte[] pixels = GenerateColoredBytes(depthFrame); //number of bytes per row width * 4 (B,G,R,Empty) int stride = depthFrame.Width * 4; //create image image1.Source = BitmapSource.Create(depthFrame.Width, depthFrame.Height, 96, 96, PixelFormats.Bgr32, null, pixels, stride); } }
private void kinect_AllFramesReady(object sender, AllFramesReadyEventArgs e) { byte[] imagem = ObterImagemSensorRGB(e.OpenColorImageFrame()); if (chkEscalaCinza.IsChecked.HasValue && chkEscalaCinza.IsChecked.Value) { ReconhecerDistancia(e.OpenDepthImageFrame(), imagem, 2000); } if (imagem != null) { canvasKinect.Background = new ImageBrush(BitmapSource.Create(kinect.ColorStream.FrameWidth, kinect.ColorStream.FrameHeight, 96, 96, PixelFormats.Bgr32, null, imagem, kinect.ColorStream.FrameWidth * kinect.ColorStream.FrameBytesPerPixel)); } canvasKinect.Children.Clear(); FuncoesEsqueletoUsuario(e.OpenSkeletonFrame()); }
private void GetCameraPoint(Skeleton skel, AllFramesReadyEventArgs e) { using (DepthImageFrame depth = e.OpenDepthImageFrame()) { if (depth == null || _kinect.Kinect == null) { return; } DepthImagePoint headDepthPoint = _kinect.Kinect.CoordinateMapper.MapSkeletonPointToDepthPoint(GetSkeletonPoint(skel, JointType.Head), DepthImageFormat.Resolution320x240Fps30); DepthImagePoint leftDepthPoint = _kinect.Kinect.CoordinateMapper.MapSkeletonPointToDepthPoint(GetSkeletonPoint(skel, JointType.HandLeft), DepthImageFormat.Resolution320x240Fps30); DepthImagePoint rightDepthPoint = _kinect.Kinect.CoordinateMapper.MapSkeletonPointToDepthPoint(GetSkeletonPoint(skel, JointType.HandRight), DepthImageFormat.Resolution320x240Fps30); ColorImagePoint headColorPoint = _kinect.Kinect.CoordinateMapper.MapDepthPointToColorPoint(DepthImageFormat.Resolution320x240Fps30, headDepthPoint, ColorImageFormat.RgbResolution640x480Fps30); ColorImagePoint leftColorPoint = _kinect.Kinect.CoordinateMapper.MapDepthPointToColorPoint(DepthImageFormat.Resolution320x240Fps30, leftDepthPoint, ColorImageFormat.RgbResolution640x480Fps30); ColorImagePoint rightColorPoint = _kinect.Kinect.CoordinateMapper.MapDepthPointToColorPoint(DepthImageFormat.Resolution320x240Fps30, rightDepthPoint, ColorImageFormat.RgbResolution640x480Fps30); CameraPosition(Head, headColorPoint); CameraPosition(Left, leftColorPoint); CameraPosition(Right, rightColorPoint); } }
void _kinect_AllFramesReady(object sender, AllFramesReadyEventArgs e) { var skeleton = GetFirstSkeleton(e); if (skeleton == null) { return; } var point = skeleton.Joints[JointType.Head].Position; RawPosition = new Vector3D(point.X, -point.Y, point.Z); //Raising right hand for calibration.. if (skeleton.Joints[JointType.HandRight].Position.Y > point.Y) { Dispatcher.Invoke((Action)(Calibrate)); } Dispatcher.Invoke((Action)(UpdatePositionAndRotation)); }
void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e) { if (closing) { return; } //Get a skeleton Skeleton first = GetFirstSkeleton(e); if (first == null) { return; } //set scaled position ScalePosition(leftEllipse, first.Joints[JointType.HandLeft]); ScalePosition(rightEllipse, first.Joints[JointType.HandRight]); GetCameraPoint(first, e); }
void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e) { if (closing) { return; } //Get a skeleton Skeleton first = GetFirstSkeleton(e); if (first == null) { return; } ExerciseVariant exercisevariant = ExerciseVariant.HandRight; ExerciseHandler(first); // UpdatePosition(first, exercisevariant); }
private void NewSensor_AllFramesReady(object sender, AllFramesReadyEventArgs e) { using (DepthImageFrame depthFrame = e.OpenDepthImageFrame()) { if (depthFrame == null) { return; } byte[] pixels = GenerateColoredBytes(depthFrame); // Every second send an image to handler if (i % 30 == 0) { //Encode pixels string pix_str = Convert.ToBase64String(pixels); string answer; using (var wb = new WebClient()) { var data = new NameValueCollection(); data["pixels"] = pix_str; var response = wb.UploadValues("http://localhost:8000", "POST", data); string responseInString = Encoding.UTF8.GetString(response); answer = responseInString; } // Print decoded comand text_box1.Text = answer; } i++; int stride = depthFrame.Width * 4; image1.Source = BitmapSource.Create(depthFrame.Width, depthFrame.Height, 96, 96, PixelFormats.Bgr32, null, pixels, stride); } }
void kinect_AllFramesReady(object sender, AllFramesReadyEventArgs args) { using (ColorImageFrame colorFrame = args.OpenColorImageFrame()) using (DepthImageFrame depthFrame = args.OpenDepthImageFrame()) using (SkeletonFrame skeletonFrame = args.OpenSkeletonFrame()) { byte[] pixelData; //いずれのフレームもnullでなければ処理をすすめる if (colorFrame != null && depthFrame != null && skeletonFrame != null) { //スケルトンの情報をSkeleton配列に格納する Skeleton[] skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength]; skeletonFrame.CopySkeletonDataTo(skeletonData); //カラーフレームの情報をByte配列に格納する pixelData = new byte[colorFrame.PixelDataLength]; colorFrame.CopyPixelDataTo(pixelData); //表示処理 colorBitmap.WritePixels(this.colorImageBitmapRect, pixelData, this.colorImageStride, 0); ////InteractionStreamを利用する場合の処理 //iStream.ProcessDepth(depthFrame.GetRawPixelData(), depthFrame.Timestamp); //iStream.ProcessSkeleton(skeletonData, kinect.AccelerometerGetCurrentReading(), // skeletonFrame.Timestamp); //DepthFrame表示用処理 depthFrame.CopyPixelDataTo(this.depthBitmapPixelData); this.depthBitmap.WritePixels(this.depthImageBitmapRect, this.depthBitmapPixelData, this.depthImageStride, 0); //深度情報取得用 depthFrame.CopyDepthImagePixelDataTo(this.depthPixelData); //ある関節の情報をとってくる //Joint target= getJointPosition(skeletonFrame, JointType.Head); //string str = string.Format("x={0},y={1},z={2}", target.Position.X, target.Position.Y, target.Position.Z); //textBlock1.Text = str; } //System.Diagnostics.Debug.WriteLine(joint.Position.Y); } }
private void KinectSensor_AllFramesReady(object sender, AllFramesReadyEventArgs e) { DepthFrameStream360.DepthFrame depthFrame360 = null; BodyFrameStream360.BodyFrame bodyFrame360 = null; ColorFrameStream360.ColorFrame colorFrame360 = null; if (FrameTypes.HasFlag(MultiFrameTypes.Color)) { var colorFrame = e.OpenColorImageFrame(); if (colorFrame == null) { return; } colorFrame360 = new ColorFrameStream360.ColorFrame(colorFrame); } if (FrameTypes.HasFlag(MultiFrameTypes.Body)) { var skeletonFrame = e.OpenSkeletonFrame(); if (skeletonFrame == null) { return; } bodyFrame360 = new BodyFrameStream360.BodyFrame(skeletonFrame); } if (FrameTypes.HasFlag(MultiFrameTypes.Depth)) { var depthFrame = e.OpenDepthImageFrame(); if (depthFrame == null) { return; } depthFrame360 = new DepthFrameStream360.DepthFrame(depthFrame); } MultiFrameArrived?.Invoke(this, new MultiFrameReadyEventArgs(new MultiFrame(colorFrame360, bodyFrame360, depthFrame360))); }
private void _sensor_TakeDepthshot(object sender, AllFramesReadyEventArgs e) { using (DepthImageFrame depthFrame = e.OpenDepthImageFrame()) { if (depthFrame == null) { return; } if (!depthShot) { return; } depthShot = false; byte[] pixels = GenerateColoredBytes(depthFrame); label_max.Content = depthFrame.Width; label_min.Content = depthFrame.Height; int stride = depthFrame.Width * 4; image4.Source = BitmapSource.Create(depthFrame.Width, depthFrame.Height, 96, 96, PixelFormats.Bgr32, null, pixels, stride); //Writing depth to a file short[] rawDepthData = new short[depthFrame.PixelDataLength]; depthFrame.CopyPixelDataTo(rawDepthData); Console.WriteLine(string.Format("{0:HH:mm:ss tt}", DateTime.Now)); System.IO.StreamWriter file = new System.IO.StreamWriter("testDepth.txt", true); file.Write(depthFrame.Width.ToString() + "#" + depthFrame.Height.ToString() + "#"); for (int i = 0; i < rawDepthData.Length; i++) { int depth = rawDepthData[i] >> DepthImageFrame.PlayerIndexBitmaskWidth; string s = depth.ToString(); file.Write(s + '$'); } file.Close(); } }
/// <summary> /// Event handler for Kinect sensor's SkeletonFrameReady event /// </summary> /// <param name="sender">object sending the event</param> /// <param name="e">event arguments</param> private void SensorAllFramesReady(object sender, AllFramesReadyEventArgs e) { if (shuttingDown) { return; } KinectSensor sensor = (KinectSensor)sender; ColorImageFrame colorFrame = e.OpenColorImageFrame(); if (colorFrame == null) { return; } if (colorPixelData[sensor] == null) { colorPixelData[sensor] = new byte[colorFrame.PixelDataLength]; } colorFrame.CopyPixelDataTo(colorPixelData[sensor]); colorFrame = null; DepthImageFrame depthFrame = e.OpenDepthImageFrame(); if (depthFrame == null) { return; } if (depthPixelData[sensor] == null) { depthPixelData[sensor] = new short[depthFrame.PixelDataLength]; } depthFrame.CopyPixelDataTo(depthPixelData[sensor]); depthFrame = null; SkeletonFrame skeletonFrame = e.OpenSkeletonFrame(); if (skeletonFrame == null) { return; } skeletonFrame.CopySkeletonDataTo(skeletons[sensor]); skeletonFrame = null; SensorFrameHelper(sensor, true); }
void SensorSkeletonFrameReady(AllFramesReadyEventArgs e) { using (SkeletonFrame skeletonFrameData = e.OpenSkeletonFrame()) { if (skeletonFrameData == null) { return; } var allSkeletons = new Skeleton[skeletonFrameData.SkeletonArrayLength]; skeletonFrameData.CopySkeletonDataTo(allSkeletons); foreach (Skeleton sd in allSkeletons) { // the first found/tracked skeleton moves the mouse cursor if (sd.TrackingState == SkeletonTrackingState.Tracked) { // make sure both hands are tracked if (sd.Joints[JointType.HandRight].TrackingState == JointTrackingState.Tracked) { var wristRight = sd.Joints[JointType.WristRight]; var leftShoulder = sd.Joints[JointType.ShoulderLeft]; var rightShoulder = sd.Joints[JointType.ShoulderRight]; var rightHand = sd.Joints[JointType.HandRight]; var head = sd.Joints[JointType.Head]; var rightHip = sd.Joints[JointType.HipRight]; double xScaled = (wristRight.Position.X - leftShoulder.Position.X) / ((rightShoulder.Position.X - leftShoulder.Position.X) * 2) * SystemParameters.PrimaryScreenWidth; double yScaled = (rightHand.Position.Y - head.Position.Y) / (rightHip.Position.Y - head.Position.Y) * SystemParameters.PrimaryScreenHeight; var cursorX = (int)xScaled + 1.5; var cursorY = (int)yScaled + 1.5; var leftClick = CheckForClickHold(xScaled, yScaled); NativeMethods.SendMouseInput(Convert.ToInt32(cursorX), Convert.ToInt32(cursorY), (int)SystemParameters.PrimaryScreenWidth, (int)SystemParameters.PrimaryScreenHeight, leftClick); } } } } }
/// <summary> /// Returns the first skeleton (the kinect recognizes up to two) /// </summary> /// <param name="e"></param> /// <returns></returns> private Skeleton getFirstSkeleton(AllFramesReadyEventArgs e) { using (SkeletonFrame skeletonFrameData = e.OpenSkeletonFrame()) { if (skeletonFrameData == null) { return(null); } Skeleton[] mainSkeletonData = new Skeleton[mainKinectSensor.SkeletonStream.FrameSkeletonArrayLength]; skeletonFrameData.CopySkeletonDataTo(mainSkeletonData); //get the first tracked skeleton Skeleton first = (from s in mainSkeletonData where s.TrackingState == SkeletonTrackingState.Tracked select s).FirstOrDefault(); return(first); } }
//this event fires when Color/Depth/Skeleton are synchronized void newSensor_AllFramesReady(object sender, AllFramesReadyEventArgs e) { //using (ColorImageFrame colorFrame = e.OpenColorImageFrame()) //{ // if (colorFrame == null) // { // return; // } // byte[] pixels = new byte[colorFrame.PixelDataLength]; // colorFrame.CopyPixelDataTo(pixels); // int stride = colorFrame.Width * 4; // image1.Source = // BitmapSource.Create(colorFrame.Width, colorFrame.Height, // 96, 96, PixelFormats.Bgr32, null, pixels, stride); //} }
/// <summary> /// Gets the first skeleton available. /// </summary> /// <param name="e">The <see cref="AllFramesReadyEventArgs" /> instance containing the event data.</param> /// <returns></returns> private Skeleton GetFirstSkeleton(AllFramesReadyEventArgs e) { ///The kinect will give us each stream of data as a seperate entity. ///This allows us to do things like just get the data for the skeletons. ///We could also do this for depth and colour. using (SkeletonFrame skeletonFrameData = e.OpenSkeletonFrame()) { if (skeletonFrameData == null) { return(null); } ///Add out skeleton to the all skeletons array. skeletonFrameData.CopySkeletonDataTo(allSkeletons); ///Some qick searching to find the skeleton currently being tracked. Skeleton firstSkele = (from skeles in allSkeletons where skeles.TrackingState == SkeletonTrackingState.Tracked select skeles).FirstOrDefault(); ///Return the correct and currently tracked skeleton. return(firstSkele); } }
Skeleton GetClosetSkeleton(AllFramesReadyEventArgs e) { using (SkeletonFrame skeletonFrameData = e.OpenSkeletonFrame()) { if (skeletonFrameData == null) { return(null); } skeletonFrameData.CopySkeletonDataTo(allSkeletons); //Linq语法,查找离Kinect最近的、被跟踪的骨骼 Skeleton closestSkeleton = (from s in allSkeletons where s.TrackingState == SkeletonTrackingState.Tracked && s.Joints[JointType.Head].TrackingState == JointTrackingState.Tracked select s).OrderBy(s => s.Joints[JointType.Head].Position.Z) .FirstOrDefault(); return(closestSkeleton); } }
private Skeleton GetFirstSkeleton(AllFramesReadyEventArgs e) { var allSkeletons = new Skeleton[6]; using (var skeletonFrameData = e.OpenSkeletonFrame()) { if (skeletonFrameData == null) { return(null); } skeletonFrameData.CopySkeletonDataTo(allSkeletons); //get the first tracked skeleton var first = (from s in allSkeletons where s.TrackingState == SkeletonTrackingState.Tracked select s).FirstOrDefault(); return(first); } }
/// <summary> /// Event handler called on every frame. /// Updates the hands on the GUI, does some computation depending on the current mode, /// and updates coordinate text boxes /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e) { // grab the skeleton and set the positions of the left and right hands Skeleton first = GetFirstSkeleton(e); if (first != null) { ScaleAndSetPosition(kinectHand, first.Joints[JointType.HandRight]); if (currentMode != Mode.MENU) { ScaleAndSetPosition(kinectHandL, first.Joints[JointType.HandLeft]); } // update the GUI and compute data to send to the Arduino, depending on the current mode compute(); // update the coordinates in the text boxes UpdateBoxesWithCoords(first.Joints[JointType.HandLeft], JointType.HandLeft); UpdateBoxesWithCoords(first.Joints[JointType.HandRight], JointType.HandRight); } }
void nui_AllFramesReady(object sender, AllFramesReadyEventArgs e) { SkeletonFrame sf = e.OpenSkeletonFrame(); if (sf == null) { return; } Skeleton[] skeletonData = new Skeleton[sf.SkeletonArrayLength]; sf.CopySkeletonDataTo(skeletonData); using (DepthImageFrame depthImageFrame = e.OpenDepthImageFrame()) { if (depthImageFrame != null) { foreach (Skeleton sd in skeletonData) { if (sd.TrackingState == SkeletonTrackingState.Tracked) { Joint joint = sd.Joints[JointType.Head]; DepthImagePoint depthPoint; depthPoint = depthImageFrame.MapFromSkeletonPoint(joint.Position); Point point = new Point((int)(Image1.Width * depthPoint.X / depthImageFrame.Width), (int)(Image1.Height * depthPoint.Y / depthImageFrame.Height)); textBlock1.Text = string.Format("X:{0:0.00} Y:{1:0.00}", point.X, point.Y); Canvas.SetLeft(ellipse1, point.X); Canvas.SetTop(ellipse1, point.Y); } } } } }
private void _sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e) { using (ColorImageFrame colorFrame = e.OpenColorImageFrame()) { if (colorFrame == null) { return; } if (!irCam) //RGB { byte[] pixels1 = new byte[colorFrame.PixelDataLength]; colorFrame.CopyPixelDataTo(pixels1); int stride = colorFrame.Width * 4; image1.Source = BitmapSource.Create(colorFrame.Width, colorFrame.Height, 96, 96, PixelFormats.Bgr32, null, pixels1, stride); } else //IR { byte[] pixels = new byte[colorFrame.PixelDataLength]; colorFrame.CopyPixelDataTo(pixels); int stride = colorFrame.Width * 2; image1.Source = BitmapSource.Create(colorFrame.Width, colorFrame.Height, 96, 96, PixelFormats.Gray16, null, pixels, stride); } } using (DepthImageFrame depthFrame = e.OpenDepthImageFrame()) { if (depthFrame == null) { return; } byte[] pixels = GenerateColoredBytes(depthFrame); int stride = depthFrame.Width * 4; image3.Source = BitmapSource.Create(depthFrame.Width, depthFrame.Height, 96, 96, PixelFormats.Bgr32, null, pixels, stride); } }
/// <summary> /// Checks the gesture. /// </summary> /// <param name="skeleton">The skeleton.</param> /// <returns>GesturePartResult based on if the gesture part has been completed</returns> public GesturePartResult CheckGesture(Skeleton skeleton, AllFramesReadyEventArgs e, GestureStatus gestureStatus) { // Don't check if user is not making a fast if (!gestureStatus.isMakingAFast) { return(GesturePartResult.Fail); } // Right in front of Shoulders if (skeleton.Joints[JointType.HandRight].Position.Z < skeleton.Joints[JointType.ElbowRight].Position.Z) { // Hands are higher then start point if (skeleton.Joints[JointType.HandRight].Position.Y < gestureStatus.startPoint.Y - 0.1) { return(GesturePartResult.Suceed); } return(GesturePartResult.Fail); } return(GesturePartResult.Fail); }
private static void Sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e) { //throw new NotImplementedException(); if (kinectMonitor.WindowState != FormWindowState.Minimized) { using (var colorFrame = e.OpenColorImageFrame()) using (var depthFrame = e.OpenDepthImageFrame()) using (var skeletonFrame = e.OpenSkeletonFrame()) { if (colorFrame == null) { return; } var colorBitmap = Helpers.ImageToBitmap(colorFrame); //draw to form if (colorBitmap != null) { kinectMonitor.DrawBitmapToForm(colorBitmap, new Point(0, 0)); } if (skeletonFrame != null) { var skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength]; skeletonFrame.CopySkeletonDataTo(skeletons); foreach (var skeleton in skeletons) { if (skeleton.TrackingState == SkeletonTrackingState.Tracked) { kinectMonitor.DrawTrackedSkeletonJoints(skeleton.Joints); } } } } } }
void _sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e) { using (ColorImageFrame colorFrame = e.OpenColorImageFrame()) { using (DepthImageFrame depthFrame = e.OpenDepthImageFrame()) { using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { if (colorFrame == null || depthFrame == null || skeletonFrame == null) { return; } // ****************Color Frame*************** ColorFrameToBitmap(colorFrame); //img_color.Source = colorBitmap; //************Skeleton Frame******************* Skeleton user_skeleton = getSkeleton(skeletonFrame); if (user_skeleton == null) { return; } //********From here --->>> Get the hand pixels // void get hand coordinates GetROI(user_skeleton, depthFrame, colorFrame); //img_color.Source = aligned_colorBitmap; img_color.Source = colorBitmap; img_cropped.Source = cb; } } } }
private void AllFrameReady(object sender, AllFramesReadyEventArgs e) { DepthImageFrame frame = e.OpenDepthImageFrame(); if (frame != null) { if (frame.FrameNumber != this.frameindex) { this.FInvalidate = true; this.RebuildBuffer(frame.Format, false); this.frameindex = frame.FrameNumber; frame.CopyDepthImagePixelDataTo(this.depthpixels); lock (m_lock) { this.runtime.Runtime.CoordinateMapper.MapDepthFrameToColorFrame(frame.Format, this.depthpixels, ColorImageFormat.RgbResolution640x480Fps30, this.colpoints); } frame.Dispose(); } } }
//DEPTH_END void GetCameraPoint(Skeleton first, AllFramesReadyEventArgs e) { using (DepthImageFrame depth = e.OpenDepthImageFrame()) { if (depth == null || kinectSensorChooser1.Kinect == null) { return; } CoordinateMapper cm = new CoordinateMapper(kinectSensorChooser1.Kinect); DepthImagePoint headDepthPoint = cm.MapSkeletonPointToDepthPoint(first.Joints[JointType.Head].Position, DepthImageFormat.Resolution640x480Fps30); DepthImagePoint leftDepthPoint = cm.MapSkeletonPointToDepthPoint(first.Joints[JointType.HandLeft].Position, DepthImageFormat.Resolution640x480Fps30); DepthImagePoint rightDepthPoint = cm.MapSkeletonPointToDepthPoint(first.Joints[JointType.HandRight].Position, DepthImageFormat.Resolution640x480Fps30); ColorImagePoint headColorPoint = cm.MapDepthPointToColorPoint(DepthImageFormat.Resolution640x480Fps30, headDepthPoint, ColorImageFormat.RgbResolution640x480Fps30); ColorImagePoint leftColorPoint = cm.MapDepthPointToColorPoint(DepthImageFormat.Resolution640x480Fps30, leftDepthPoint, ColorImageFormat.RgbResolution640x480Fps30); ColorImagePoint rightColorPoint = cm.MapDepthPointToColorPoint(DepthImageFormat.Resolution640x480Fps30, rightDepthPoint, ColorImageFormat.RgbResolution640x480Fps30); //=> CameraPosition(headImage, headColorPoint); //=> CameraPosition(leftEllipse, leftColorPoint); //=> CameraPosition(rightEllipse, rightColorPoint); } }
void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e) { if (closing) { return; } //Get a skeleton first = GetFirstSkeleton(e); if (first == null) { return; } GetCameraPoint(first, e); //set scaled position ScalePosition(leftHand, first.Joints[JointType.HandLeft]); ScalePosition(rightHand, first.Joints[JointType.HandRight]); leftHandPos.Location = new Point(Canvas.GetLeft(leftHand), Canvas.GetTop(leftHand)); rightHandPos.Location = new Point(Canvas.GetLeft(rightHand), Canvas.GetTop(rightHand)); }
void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e) { depthImagePixels = new DepthImagePixel[sensor.DepthStream.FramePixelDataLength]; using (var frame = e.OpenDepthImageFrame()) { if (frame == null) { return; } frame.CopyDepthImagePixelDataTo(depthImagePixels); } using (var frame = e.OpenColorImageFrame()) { if (frame == null) { return; } var bitmap = CreateBitmapFromFrame(frame); imageCanvas.Background = new ImageBrush(bitmap); } }
//Method to get the skeleton data from the kinect camera private void getSkeles(AllFramesReadyEventArgs e, ref Skeleton me, int person) { //retrieves skeletal data from kinect using (SkeletonFrame skeletonFrameData = e.OpenSkeletonFrame()) { if (skeletonFrameData == null) { return; } //Inputs skeleton data into the allSKELETONS array, initialised at the top of the class skeletonFrameData.CopySkeletonDataTo(allSkeles); //query to retrive list from skeleton frame data List <Skeleton> tmpSkel = (from s in allSkeles where s.TrackingState == SkeletonTrackingState.Tracked select s).Distinct().ToList(); if (tmpSkel.Count < person + 1) { return; } //Sets me (the current person) as the current skeleton with the index of the current person //This ensures that only the initial people are referenced when drawing the skeletons me = tmpSkel[person]; } }