void sensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { //frameNumber = frameNumber + 1; timepassed++; seconds = timepassed / 30; e.OpenSkeletonFrame().CopySkeletonDataTo(skeletons); int counter = 0; foreach(Skeleton skeleton in skeletons) { if (skeleton.TrackingState == SkeletonTrackingState.Tracked) counter++; } //Console.WriteLine("Frame: {0}, Number of Skeletons: {1}", frameNumber, counter); if (timepassed == seconds * 30) Console.WriteLine("Seconds passed: {0}, Number of Skeletons: {1}", seconds, counter); if (counter > 0) { if (timepassed == seconds * 30) { Console.WriteLine("Location of head: " + skeletons[counter].Joints[JointType.Head].Position.X + ", " + skeletons[counter].Joints[JointType.Head].Position.Y + ", " + skeletons[counter].Joints[JointType.Head].Position.Z + "; Found at: " + DateTime.Now); } } }
//---------------------METHODS------------- #region Methods private void KinectDevice_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { SkeletonsPanel.Children.Clear(); JointInfoPanel.Children.Clear(); if (this.IsEnabled) { using (SkeletonFrame frame = e.OpenSkeletonFrame()) { if (frame != null) { if (this.IsEnabled) { Brush brush; Skeleton skeleton; frame.CopySkeletonDataTo(this._FrameSkeletons); for (int i = 0; i < this._FrameSkeletons.Length; i++) { skeleton = this._FrameSkeletons[i]; brush = this._SkeletonBrushes[i]; DrawSkeleton(skeleton, brush); TrackJoint(skeleton.Joints[JointType.HandLeft], brush); TrackJoint(skeleton.Joints[JointType.HandRight], brush); //You can track all the joints if you want } } } } } }
void Sensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { using (var frame = e.OpenSkeletonFrame()) { if (frame != null) { canvas.ClearSkeletons(); var skeletons = frame.Skeletons().Where(s => s.TrackingState == SkeletonTrackingState.Tracked); foreach (var skeleton in skeletons) { if (skeleton != null) { // Update skeleton gestures. _gestureController.Update(skeleton); // Draw skeleton. canvas.DrawSkeleton(skeleton); } } } } }
private void kinectSensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { using (SkeletonFrame frame = e.OpenSkeletonFrame()) { if (frame == null) return; frame.GetSkeletons(ref skeletons); if (skeletons.All(s => s.TrackingState == SkeletonTrackingState.NotTracked)) return; foreach (var skeleton in skeletons) { if (skeleton.TrackingState != SkeletonTrackingState.Tracked) continue; foreach (Joint joint in skeleton.Joints) { if (joint.TrackingState != JointTrackingState.Tracked) continue; if (joint.JointType == JointType.HandRight) { MouseController.Current.SetHandPosition(kinectSensor, joint, skeleton); } } } } }
void sensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { Skeleton[] skeletons = new Skeleton[0]; using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { if (skeletonFrame != null) { skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength]; skeletonFrame.CopySkeletonDataTo(skeletons); } } var index = 0; foreach (Skeleton skeleton in skeletons) { if (skeleton.TrackingState != SkeletonTrackingState.NotTracked) { SetMarkerPosition(skeleton, index); } index++; } RemoveUnusedMarkers(skeletons); }
//Eventhanterare för andra skeletet public void Kinect_SkeletonFrameReadyTwo(object sender, SkeletonFrameReadyEventArgs e) { SkeletonsPanelTwo.Children.Clear(); if (this.IsEnabled) { using (SkeletonFrame frame = e.OpenSkeletonFrame()) { if (frame != null) { if (this.IsEnabled) { frame.CopySkeletonDataTo(this._FrameSkeletons); for (int i = 0; i < this._FrameSkeletons.Length; i++) { DrawSkeleton(this._FrameSkeletons[i], this._SkeletonBrushes[i]); TrackJoint(this._FrameSkeletons[i].Joints[JointType.HandLeft], this._SkeletonBrushes[i]); TrackJoint(this._FrameSkeletons[i].Joints[JointType.HandRight], this._SkeletonBrushes[i]); TrackJoint(this._FrameSkeletons[i].Joints[JointType.HipLeft], this._SkeletonBrushes[i]); TrackJoint(this._FrameSkeletons[i].Joints[JointType.HipRight], this._SkeletonBrushes[i]); TrackJoint(this._FrameSkeletons[i].Joints[JointType.KneeLeft], this._SkeletonBrushes[i]); TrackJoint(this._FrameSkeletons[i].Joints[JointType.KneeRight], this._SkeletonBrushes[i]); } } } } } }
static void Nui_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { if (!_initialized) return; List<Skeleton> users = new List<Skeleton>(); SkeletonFrame skeletonFrame = e.OpenSkeletonFrame(); Skeleton[] skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength]; skeletonFrame.CopySkeletonDataTo(skeletons); foreach (var user in skeletons) { if (user.TrackingState == SkeletonTrackingState.Tracked) { users.Add(user); } } if (users.Count > 0) { string json = users.Serialize(); foreach (var socket in _sockets) { socket.Send(json); } } }
private static void KinectOnSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs skeletonFrameReadyEventArgs) { using (var frame = skeletonFrameReadyEventArgs.OpenSkeletonFrame()) { if (frame == null) return; //フレームに含まれる骨格情報を取得する var skeletonData = new Skeleton[frame.SkeletonArrayLength]; frame.CopySkeletonDataTo(skeletonData); foreach (var skeleton in skeletonData) { if (skeleton == null) continue; //トラッキングできている骨格だけ取得 if (skeleton.TrackingState != SkeletonTrackingState.Tracked) continue; foreach (Joint joint in skeleton.Joints) { //トラッキングできている関節だけ取得 if (joint.TrackingState != JointTrackingState.Tracked) continue; Console.WriteLine("JointType: {0}\t X: {1} \t Y: {2} \t Z: {3}", joint.JointType, joint.Position.X, joint.Position.Y, joint.Position.Z); //座標系の変換 var cp = (sender as KinectSensor).CoordinateMapper.MapSkeletonPointToColorPoint(joint.Position, ColorImageFormat.RawBayerResolution640x480Fps30); Console.WriteLine("RGB X: {0} \t RGB Y: {1}", cp.X, cp.Y); } } } }
private void SensorSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs skeletonFrameReadyEventArgs) { using (SkeletonFrame skeletonFrame = skeletonFrameReadyEventArgs.OpenSkeletonFrame()) { if (skeletonFrame == null) return; try { skeletonFrame.CopySkeletonDataTo(skeletons); var accelerometerReading = sensor.AccelerometerGetCurrentReading(); interactionStream.ProcessSkeleton(skeletons, accelerometerReading, skeletonFrame.Timestamp); } catch (InvalidOperationException) { // SkeletonFrame functions may throw when the sensor gets // into a bad state. Ignore the frame in that case. } } }
void NewSensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs args) { var colors = new Dictionary<int, Color>(); Skeleton[] skeletons; using (var frame = args.OpenSkeletonFrame()) { if (frame == null) return; skeletons = new Skeleton[frame.SkeletonArrayLength]; frame.CopySkeletonDataTo(skeletons); } foreach (var skeleton in skeletons.Where(s => SkeletonTrackingState.Tracked.Equals(s.TrackingState))) { Random _rnd = new Random(); var userId = skeleton.TrackingId; var crazyColors = Color.FromRgb((byte)_rnd.Next(255), (byte)_rnd.Next(255), (byte)_rnd.Next(255)); colors.Add(userId, KinectRegion.PrimaryUserTrackingId == userId ? crazyColors : Colors.Blue); } this.KinectUserViewer.UserColors = colors; }
void Sensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { using (var frame = e.OpenSkeletonFrame()) { if (frame != null) { canvas.Children.Clear(); Skeleton[] skeletons = new Skeleton[frame.SkeletonArrayLength]; frame.CopySkeletonDataTo(skeletons); var skeleton = skeletons.Where(s => s.TrackingState == SkeletonTrackingState.Tracked).FirstOrDefault(); if (skeleton != null) { // Calculate height. double height = Math.Round(skeleton.Height(), 2); // Draw skeleton joints. foreach (JointType joint in Enum.GetValues(typeof(JointType))) { //DrawJoint(skeleton.Joints[joint].ScaleTo(640, 480)); Point p = posionScale(skeleton.Joints[joint].Position); DrawJoint(p); } // Display height. tblHeight.Text = "Height: " + height.ToString() + "m"; } } } }
void sensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { Thread.Sleep(200); // 意図的な負荷。 using (var frame = e.OpenSkeletonFrame()) { if (frame == null) { PositionText = ""; return; } var skeletons = new Skeleton[frame.SkeletonArrayLength]; frame.CopySkeletonDataTo(skeletons); var skeleton = skeletons.FirstOrDefault(s => s.TrackingState == SkeletonTrackingState.Tracked); if (skeleton == null) { PositionText = ""; return; } var p = skeleton.Position; PositionText = string.Format("({0:N3}, {1:N3}, {2:N3})", p.X, p.Y, p.Z); } }
void sensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { using (SkeletonFrame frame = e.OpenSkeletonFrame()) { if (frame == null) return; Skeleton[] skeletonArray = new Skeleton[frame.SkeletonArrayLength]; frame.CopySkeletonDataTo(skeletonArray); int i = 0; foreach (Skeleton s in skeletonArray) { if (s.TrackingState == SkeletonTrackingState.Tracked && i < 2) { playerSkeleton[i] = s; i++; } } if (i == 2 && playerSkeleton[0].Joints[JointType.Head].Position.X > playerSkeleton[1].Joints[JointType.Head].Position.X) { Skeleton temp = playerSkeleton[0]; playerSkeleton[0] = playerSkeleton[1]; playerSkeleton[1] = temp; } } }
void Sensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { using (var frame = e.OpenSkeletonFrame()) { if (frame != null) { canvas.ClearSkeletons(); tblHeights.Text = string.Empty; var skeletons = frame.Skeletons().Where(s => s.TrackingState == SkeletonTrackingState.Tracked); foreach (var skeleton in skeletons) { if (skeleton != null) { // Update skeleton gestures. _gestureController.Update(skeleton); // Draw skeleton. canvas.DrawSkeleton(skeleton); // Display user height. tblHeights.Text += string.Format("\nUser {0}: {1}cm", skeleton.TrackingId, skeleton.Height()); } } } } }
/// <summary> /// スケルトンの更新通知 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void kinect_SkeletonFrameReady( object sender, SkeletonFrameReadyEventArgs e ) { try { // Kinectのインスタンスを取得する KinectSensor kinect = sender as KinectSensor; if ( kinect == null ) { return; } // スケルトンのフレームを取得する using ( SkeletonFrame skeletonFrame = e.OpenSkeletonFrame() ) { if ( skeletonFrame != null ) { Skeleton skeleton = skeletonFrame.GetFirstTrackedSkeleton(); if ( skeleton != null ) { // ポーズの検出用に、スケルトンデータを追加する postureDetector.TrackPostures( skeleton ); // 右手がトラッキングされていた場合、ジェスチャーの検出用にジョイントを追加する Joint hand = skeleton.Joints[JointType.HandRight]; if ( hand.TrackingState == JointTrackingState.Tracked ) { swipeDetector.Add( hand.Position, kinect ); } } } } } catch ( Exception ex ) { MessageBox.Show( ex.Message ); } }
void Sensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { skeletonFrame.CopySkeletonDataTo(this.FSkeletons); } }
private void miKinect_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { canvasesqueleto.Children.Clear(); Skeleton[] esqueletos = null; using (SkeletonFrame frameEsqueleto = e.OpenSkeletonFrame()) { if (frameEsqueleto != null) { esqueletos = new Skeleton[frameEsqueleto.SkeletonArrayLength]; frameEsqueleto.CopySkeletonDataTo(esqueletos); } } if (esqueletos == null) return; foreach (Skeleton esqueleto in esqueletos) { if (esqueleto.TrackingState == SkeletonTrackingState.Tracked) { Joint handJoint = esqueleto.Joints[JointType.HandRight]; Joint elbowJoint = esqueleto.Joints[JointType.ElbowRight]; Line huesoBrazoDer = new Line(); huesoBrazoDer.Stroke = new SolidColorBrush(Colors.Red); huesoBrazoDer.StrokeThickness = 5; ColorImagePoint puntoMano = miKinect.CoordinateMapper.MapSkeletonPointToColorPoint(handJoint.Position, ColorImageFormat.RgbResolution640x480Fps30); huesoBrazoDer.X1 = puntoMano.X; huesoBrazoDer.Y1 = puntoMano.Y; ColorImagePoint puntoCodo = miKinect.CoordinateMapper.MapSkeletonPointToColorPoint(elbowJoint.Position, ColorImageFormat.RgbResolution640x480Fps30); huesoBrazoDer.X2 = puntoCodo.X; huesoBrazoDer.Y2 = puntoCodo.Y; canvasesqueleto.Children.Add(huesoBrazoDer); } } }
private void SensorSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { Skeleton[] skeletons = null; using (var frame = e.OpenSkeletonFrame()) { if (frame != null) { skeletons = new Skeleton[frame.SkeletonArrayLength]; frame.CopySkeletonDataTo(skeletons); } } if (skeletons == null) return; foreach (var kinectRocketGestures in ( from skeleton in skeletons where skeleton.TrackingState == SkeletonTrackingState.Tracked let headJoint = skeleton.Joints[JointType.Head] where headJoint.TrackingState != JointTrackingState.NotTracked select skeleton).Select(skeleton => new KinectRocketGestures(skeleton, _rocket))) { var gesture = kinectRocketGestures.ValidateGestures(); textBlockInformation.Text = gesture; } }
private void myKinect_AllFramesReady(Object sender,SkeletonFrameReadyEventArgs e) { using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { if (skeletonFrame != null) { if (this.skeletonData == null || (this.skeletonData.Length != skeletonFrame.SkeletonArrayLength)) { this.skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength]; } skeletonFrame.CopySkeletonDataTo(skeletonData); foreach(Skeleton skeleton in skeletonData) { if(skeleton.TrackingState == SkeletonTrackingState.Tracked) { double x = 0, y = 0, z = 0; Joint joint = skeleton.Joints[JointType.HandRight]; x = joint.Position.X; y = joint.Position.Y; z = joint.Position.Z; tRightHand.Content = "X: " + x + " \nY: " + y + " \nZ: " + z; if (x > 0.5) { tRightHand.Foreground = Brushes.Red; } else { tRightHand.Foreground = Brushes.Black; } } } } } }
void sensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { if (skeletonFrame == null) { return; } Skeleton[] totalSkeleton = new Skeleton[skeletonFrame.SkeletonArrayLength]; skeletonFrame.CopySkeletonDataTo(totalSkeleton); // 如果不用 LINQ表达式应该是怎么写? Skeleton firstSkeleton = (from trackskeleton in totalSkeleton where trackskeleton.TrackingState == SkeletonTrackingState. Tracked select trackskeleton).FirstOrDefault(); if (firstSkeleton == null) { return; } if (firstSkeleton.Joints[JointType.HandRight].TrackingState == JointTrackingState.Tracked) { this.MapJointsWithUIElement(firstSkeleton); } } }
void Sensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { using (var frame = e.OpenSkeletonFrame()) { if (frame != null) { Skeleton[] bodies = new Skeleton[frame.SkeletonArrayLength]; frame.CopySkeletonDataTo(bodies); var body = bodies.Where(b => b.TrackingState == SkeletonTrackingState.Tracked).FirstOrDefault(); if (body != null) { Joint handLeft = body.Joints[JointType.HandLeft]; Joint handRight = body.Joints[JointType.HandRight]; if (handLeft.TrackingState != JointTrackingState.NotTracked && handRight.TrackingState != JointTrackingState.NotTracked) { // Select the hand that is closer to the sensor. var activeHand = handRight.Position.Z <= handLeft.Position.Z ? handRight : handLeft; var position = _sensor.CoordinateMapper.MapSkeletonPointToColorPoint(activeHand.Position, ColorImageFormat.RgbResolution640x480Fps30); cursor.Flip(activeHand); cursor.Update(position); } } } } }
private void SensorSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { // Access the skeleton frame using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { if (skeletonFrame != null) { if (this.skeletons == null) { // Allocate array of skeletons this.skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength]; } // Copy skeletons from this frame skeletonFrame.CopySkeletonDataTo(this.skeletons); // Find first tracked skeleton, if any Skeleton skeleton = this.skeletons.Where(s => s.TrackingState == SkeletonTrackingState.Tracked).FirstOrDefault(); FloorClipPlane = skeletonFrame.FloorClipPlane; //Debug.WriteLine(skeletonFrame.FloorClipPlane); if (skeleton != null) { // Obtain the left knee joint; if tracked, print its position Calibration.mainSkeleton = skeleton; Debug.WriteLine(skeleton.Joints[JointType.FootLeft].Position.X + " " + skeleton.Joints[JointType.FootLeft].Position.Y + " " + skeleton.Joints[JointType.FootLeft].Position.Z); } } } }
protected void MeasureAngle(object sender,SkeletonFrameReadyEventArgs e) { if(IsEnabled) using(SkeletonFrame skeletonFrame=e.OpenSkeletonFrame()) if(skeletonFrame!=null){ Skeleton[] skeletons=new Skeleton[skeletonFrame.SkeletonArrayLength]; skeletonFrame.CopySkeletonDataTo(skeletons); Skeleton firstTrackedSkeleton=null; foreach(Skeleton skel in skeletons) if(skel.TrackingState==SkeletonTrackingState.Tracked){ firstTrackedSkeleton=skel; break; } if(firstTrackedSkeleton==null){ IsTracking=false; return; } IsTracking=true; var point1=sensor.CoordinateMapper.MapSkeletonPointToDepthPoint(firstTrackedSkeleton.Joints[JointType.HandRight].Position,DepthImageFormat.Resolution640x480Fps30); var point2=sensor.CoordinateMapper.MapSkeletonPointToDepthPoint(firstTrackedSkeleton.Joints[JointType.HandLeft].Position,DepthImageFormat.Resolution640x480Fps30); RightHandLocation=new Point(point1.X,point1.Y); LeftHandLocation=new Point(point2.X,point2.Y); MiddlePoint=new Point((point1.X+point2.X)/2.0,(point1.Y+point2.Y)/2.0); var angle=(int)(Math.Atan(-(((double)point2.Y-point1.Y)/(point2.X-point1.X)))*(180.0/Math.PI)); Angle=point1.X<point2.X?point1.Y<point2.Y?angle+180:angle-180:angle; } return; }
private void kinect_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { //Debug.WriteLine("In kinect skeleton event handler"); using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) // Open the Skeleton frame { if (skeletonFrame != null && this.skeletonData != null) // check that a frame is available { skeletonFrame.CopySkeletonDataTo(this.skeletonData); // get the skeletal information in this frame } } // Debug.WriteLine(this.skeletonData.Length); foreach (Skeleton skel in this.skeletonData) { if (skel.TrackingState == SkeletonTrackingState.Tracked) { count++; if (count > 50) { Console.WriteLine("id: " + skel.TrackingId + "shoulder L X:" + skel.Joints[JointType.ShoulderLeft].Position.X + " Y: " + skel.Joints[JointType.ShoulderLeft].Position.Y + " Z: " + skel.Joints[JointType.ShoulderLeft].Position.Z); Console.WriteLine("id: " + skel.TrackingId + "shoulder C X:" + skel.Joints[JointType.ShoulderCenter].Position.X + " Y: " + skel.Joints[JointType.ShoulderCenter].Position.Y + " Z: " + skel.Joints[JointType.ShoulderCenter].Position.Z); Console.WriteLine("id: " + skel.TrackingId + "shoulder R X:" + skel.Joints[JointType.ShoulderRight].Position.X + " Y: " + skel.Joints[JointType.ShoulderRight].Position.Y + " Z: " + skel.Joints[JointType.ShoulderRight].Position.Z); //Console.WriteLine("id: " + skel.TrackingId + " X: " + skel.Position.X + " Y: " + skel.Position.Y + " Z: " + skel.Position.Z); count = 0; } } } }
protected void MeasureDistance(object sender,SkeletonFrameReadyEventArgs e) { using(SkeletonFrame skeletonFrame=e.OpenSkeletonFrame()) if(skeletonFrame!=null){ Skeleton[] skeletons=new Skeleton[skeletonFrame.SkeletonArrayLength]; skeletonFrame.CopySkeletonDataTo(skeletons); Skeleton firstTrackedSkeleton=null; foreach(Skeleton skel in skeletons) if(skel.TrackingState==SkeletonTrackingState.Tracked){ firstTrackedSkeleton=skel; break; } if(firstTrackedSkeleton==null){ IsTracking=false; return; } IsTracking=true; var point1=sensor.MapSkeletonPointToDepth(firstTrackedSkeleton.Joints[Joint1].Position,DepthImageFormat.Resolution640x480Fps30); var point2=sensor.MapSkeletonPointToDepth(firstTrackedSkeleton.Joints[Joint2].Position,DepthImageFormat.Resolution640x480Fps30); Joint1Location=new Point(point1.X,point1.Y); Joint2Location=new Point(point2.X,point2.Y); Distance=(int)Math.Sqrt((point2.X-point1.X)*(point2.X-point1.X)+(point2.Y-point1.Y)*(point2.Y-point1.Y)); } return; }
static void Sensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { if (!_serverInitialized) return; List<Skeleton> users = new List<Skeleton>(); using (var frame = e.OpenSkeletonFrame()) { if (frame != null) { frame.CopySkeletonDataTo(_skeletons); foreach (var skeleton in _skeletons) { if (skeleton.TrackingState == SkeletonTrackingState.Tracked) { users.Add(skeleton); } } if (users.Count > 0) { string json = users.Serialize(); foreach (var socket in _clients) { socket.Send(json); } } } } }
private void nui_SkeletonFrameReady5(object sender, SkeletonFrameReadyEventArgs e) { //get the first tracked skeleton Skeleton[] skeletons = new Skeleton[0]; using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { if (skeletonFrame != null) { skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength]; skeletonFrame.CopySkeletonDataTo(skeletons); } } if (skeletons != null && skeletons.Length != 0) { if (skeletons[0].TrackingState == SkeletonTrackingState.Tracked) { SetEllipsePosition(leftEllipse, skeletons[0].Joints[JointType.HandLeft]); SetEllipsePosition(rightEllipse, skeletons[0].Joints[JointType.HandRight]); currentController.processSkeletonFramePage8(skeletons[0], this.controls, this); } } }
static void Nui_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { //Skeleton[] skeletons; List<Skeleton> skeletons = new List<Skeleton>(); bool receivedData = false; using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { if (skeletonFrame != null) { if (skeletons == null) { //skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength]; var addskels = new Skeleton(); skeletons.Add(addskels); } receivedData = true; } else { // apps processing of skeleton data took too long; it got more than 2 frames behind. // thedata is no longer avabilable. } if (receivedData) { string json = skeletons.Serialize(); //string json = skeletonFrame.CopySkeletonDataTo( foreach (var socket in _sockets) { SkeletonFrame allSkeletons = e.OpenSkeletonFrame(); Skeleton playerSkeleton = (from s in skeletons where s.TrackingState == SkeletonTrackingState.Tracked select s).FirstOrDefault(); Joint rightHandJoint = playerSkeleton.Joints[JointType.HandRight]; Console.WriteLine("working"); socket.Send(json); } } } }
void Kinect_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { if(ClientList.Count > 0) { using(SkeletonFrame frame = e.OpenSkeletonFrame()) { this.SkeletonFrame = frame; if(frame != null) { _memoryStream.Seek(0, SeekOrigin.Begin); if(_skeletons == null || _skeletons.Length != frame.SkeletonArrayLength) _skeletons = new Skeleton[frame.SkeletonArrayLength]; frame.CopySkeletonDataTo(_skeletons); _binaryWriter.Write(frame.FloorClipPlane.Item1); _binaryWriter.Write(frame.FloorClipPlane.Item2); _binaryWriter.Write(frame.FloorClipPlane.Item3); _binaryWriter.Write(frame.FloorClipPlane.Item4); _binaryWriter.Write(frame.FrameNumber); _binaryWriter.Write(frame.SkeletonArrayLength); _binaryWriter.Write(frame.Timestamp); foreach(Skeleton s in _skeletons) { _binaryWriter.Write((int)s.ClippedEdges); _binaryWriter.Write(s.Joints.Count); foreach(Joint j in s.Joints) { _binaryWriter.Write((int)j.JointType); _binaryWriter.Write(j.Position.X); _binaryWriter.Write(j.Position.Y); _binaryWriter.Write(j.Position.Z); _binaryWriter.Write((int)j.TrackingState); } _binaryWriter.Write(s.Position.X); _binaryWriter.Write(s.Position.Y); _binaryWriter.Write(s.Position.Z); _binaryWriter.Write(s.TrackingId); _binaryWriter.Write((int)s.TrackingState); } Parallel.For(0, ClientList.Count, index => { SocketClient sc = ClientList[index]; sc.Send(BitConverter.GetBytes((int)_memoryStream.Length)); sc.Send(_memoryStream.ToArray()); }); RemoveClients(); } } } }
void SkeletonReady(object sender, SkeletonFrameReadyEventArgs e) { if (!((KinectSensor)sender).SkeletonStream.IsEnabled) { return; } SkeletonFrame sf = e.OpenSkeletonFrame(); if (sf == null) return; Skeleton[] data = new Skeleton[sf.SkeletonArrayLength]; Action<string> gs = GestureAction; sf.CopySkeletonDataTo(data); foreach (Skeleton s in data) { if (s.TrackingState == SkeletonTrackingState.Tracked) { if (s.Joints[JointType.HandRight].TrackingState == JointTrackingState.Tracked) { var wristRight = s.Joints[JointType.WristRight]; var leftShoulder = s.Joints[JointType.ShoulderLeft]; var rightShoulder = s.Joints[JointType.ShoulderRight]; var rightHand = s.Joints[JointType.HandRight]; var head = s.Joints[JointType.Head]; var rightHip = s.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); } foreach (Joint joint in s.Joints) { if (joint.JointType == JointType.HandLeft) { KinectController.LeftHandSwipeGesture.Add(joint.Position, KinectController.KS); if (KinectController.KinectMouseEnabled == true) { MouseController.Current.SetHandPosition(KinectController.KS, joint, s); } } else if (joint.JointType == JointType.HandRight) { KinectController.RightHandSwipeGesture.Add(joint.Position, KinectController.KS); } } } } }
private void skeletonTracking(object sender, Microsoft.Kinect.SkeletonFrameReadyEventArgs e) { using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { if (skeletonFrame != null) { if ((null == skels) || (skels.Length != skeletonFrame.SkeletonArrayLength)) { this.skels = new Skeleton[skeletonFrame.SkeletonArrayLength]; } skeletonFrame.CopySkeletonDataTo(skels); } } foreach (Skeleton skel in skels) { if (SkeletonTrackingState.Tracked != skel.TrackingState) { txtEstado.Text = "No hay skeleton"; } else { txtEstado.Text = "Skeleton detectado"; DateTime now = DateTime.Now; // Si no se había inicializado el LastFrameSent if (this.lastFrameSent == DateTime.MinValue) { this.lastFrameSent = now; } // Si el tiempo transcurrido es menor al 95% del thick double ms = now.Subtract(this.lastFrameSent).Milliseconds; //double ms = this.lastFrameSent.Subtract(now).Milliseconds; if (ms < (TICK_FRAMES * 0.95)) { return; } //txtMensajes.Text = cabeza.Position.X + " " + cabeza.Position.Y + " " + cabeza.Position.Z; //string posiciones = // skel.Joints[JointType.HandRight].Position.X + " " + // skel.Joints[JointType.HandRight].Position.Y + " " + // skel.Joints[JointType.HandRight].Position.Z; // SE ESTÁ PROBANDO EL MÉTODO QUE GENERA TODAS LAS POSICIONES EN UNA SOLA CADENA this.conexServer.EnviarMensajeAlAvatar(this.GenerarStringSkeletonData(skel.Joints)); this.lastFrameSent = now; break; } } }
/// <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 SensorSkeletonFrameReady(object sender, kinect.SkeletonFrameReadyEventArgs e) { kinect.Skeleton[] skeletons = new kinect.Skeleton[0]; using (kinect.SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { if (skeletonFrame != null) { skeletons = new kinect.Skeleton[skeletonFrame.SkeletonArrayLength]; skeletonFrame.CopySkeletonDataTo(skeletons); } } processSkeletons(skeletons); }
void runtime_SkeletonFrameReady(object sender, Microsoft.Kinect.SkeletonFrameReadyEventArgs e) { Skeleton[] skels = null; long ts = 0; using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { if (skeletonFrame != null) { skels = new Skeleton[skeletonFrame.SkeletonArrayLength]; skeletonFrame.CopySkeletonDataTo(skels); ts = skeletonFrame.Timestamp; } } if (skels != null) { Vector4 accel = this.runtime.Runtime.AccelerometerGetCurrentReading(); stream.ProcessSkeleton(skels, accel, ts); } }
void Kinect_SkeletonFrameReady(object sender, Microsoft.Kinect.SkeletonFrameReadyEventArgs e) { ServerMessage info = new ServerMessage(); info.X = KinectCursorVisualizer.CurrentXPosition; info.Y = KinectCursorVisualizer.CurrentYPosition; info.PressLevel = KinectCursorVisualizer.CurrentPressLevel; Console.WriteLine("{0} {1}", info.X, info.Y); if (info.X > 0 && info.Y > 0) { Webserver.SendToClients(info.ToJSON()); } Skeleton[] skeletons = new Skeleton[0]; using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { if (skeletonFrame != null) { skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength]; skeletonFrame.CopySkeletonDataTo(skeletons); } } foreach (Skeleton skeleton in skeletons) { if (skeleton.TrackingState == SkeletonTrackingState.Tracked) { foreach (CustomGesture gesture in CustomGesturesHandler.Instance().Gestures) { if (gesture.Check(skeleton)) { ServerMessage gestureInfo = new ServerMessage(); gestureInfo.Gesture = gesture.Name; Webserver.SendToClients(gestureInfo.ToJSON()); } } } } }