public void Record(SkeletonFrame frame) { if (writer == null) throw new Exception("You must call Start before calling Record"); TimeSpan timeSpan = DateTime.Now.Subtract(referenceTime); referenceTime = DateTime.Now; writer.Write((long)timeSpan.TotalMilliseconds); writer.Write(frame.FloorClipPlane); writer.Write((int)frame.Quality); writer.Write(frame.NormalToGravity); writer.Write(frame.Skeletons.Length); foreach (SkeletonData skeleton in frame.Skeletons) { writer.Write((int)skeleton.TrackingState); writer.Write(skeleton.Position); writer.Write(skeleton.TrackingID); writer.Write(skeleton.UserIndex); writer.Write((int)skeleton.Quality); writer.Write(skeleton.Joints.Count); foreach (Joint joint in skeleton.Joints) { writer.Write((int)joint.ID); writer.Write((int)joint.TrackingState); writer.Write(joint.Position); } } }
public void EnqueueSkeletonFrame(SkeletonFrame frame) { lock (skeletonFrameQueue) { skeletonFrameQueue.Enqueue(new SkeletonFrameAlternative(frame)); } }
public SkeletonFrameAlternative(SkeletonFrame frame) { FrameNumber = frame.FrameNumber; Skeletons = new SkeletonDataAlternative[frame.Skeletons.Length]; int i = 0; foreach (SkeletonData data in frame.Skeletons) { Skeletons[i++] = new SkeletonDataAlternative(data); } }
public ReplaySkeletonFrame(SkeletonFrame frame) { FloorClipPlane = frame.FloorClipPlane; FrameNumber = frame.FrameNumber; NormalToGravity = frame.NormalToGravity; Quality = frame.Quality; TimeStamp = frame.TimeStamp; Skeletons = new ReplaySkeletonData[frame.Skeletons.Length]; for (int index = 0; index < Skeletons.Length; index++) { Skeletons[index] = frame.Skeletons[index]; } }
private void ProcessFrame(SkeletonFrame frame) { foreach (var skeleton in frame.Skeletons) { if (skeleton.TrackingState != SkeletonTrackingState.Tracked) continue; foreach (Joint joint in skeleton.Joints) { if (joint.Position.W < 0.8f || joint.TrackingState != JointTrackingState.Tracked) continue; if (joint.ID == JointID.HandRight) { gestureRecognizer.Add(joint.Position, kinectRuntime.SkeletonEngine); } } skeletonDisplayManager.Draw(frame); } }
// Process a frame which can contain 0 or more skeletons (maximum of 2 full skeletons) void ProcessFrame(SkeletonFrame frame) { // Calculate stats to be printed once a second lastPacket = DateTime.Now.Ticks; statFrames++; if (DateTime.Now.Ticks - statLast > 10000000) { Console.WriteLine("{0} frames in {1} s", statFrames, ((double) (DateTime.Now.Ticks - statLast)/10000000f)); statFrames = 0; statLast = DateTime.Now.Ticks; } // Send out all the skeletons foreach (var s in frame.Skeletons) { if (s.TrackingID != 0) { SendSkeleton(s); } } }
public void processSkeletonFrame(SkeletonFrame frame) { SkeletonFrame allSkeletons = frame; //get the first tracked skeleton SkeletonData skeleton = (from s in allSkeletons.Skeletons where s.TrackingState == SkeletonTrackingState.Tracked select s).FirstOrDefault(); if (skeleton != null) { //set positions on our joints of interest (already defined as Ellipse objects in the xaml) // SetEllipsePosition(headEllipse, skeleton.Joints[JointID.Head]); SetEllipsePosition(leftEllipse, skeleton.Joints[JointID.HandLeft]); SetEllipsePosition(rightEllipse, skeleton.Joints[JointID.HandRight]); /*SetEllipsePosition(shoulderCenter, skeleton.Joints[JointID.ShoulderCenter]); SetEllipsePosition(shoulderRight, skeleton.Joints[JointID.ShoulderRight]); SetEllipsePosition(shoulderLeft, skeleton.Joints[JointID.ShoulderLeft]); SetEllipsePosition(ankleRight, skeleton.Joints[JointID.AnkleRight]); SetEllipsePosition(ankleLeft, skeleton.Joints[JointID.AnkleLeft]); SetEllipsePosition(footLeft, skeleton.Joints[JointID.FootLeft]); SetEllipsePosition(footRight, skeleton.Joints[JointID.FootRight]); SetEllipsePosition(wristLeft, skeleton.Joints[JointID.WristLeft]); SetEllipsePosition(wristRight, skeleton.Joints[JointID.WristRight]); SetEllipsePosition(elbowLeft, skeleton.Joints[JointID.ElbowLeft]); SetEllipsePosition(elbowRight, skeleton.Joints[JointID.ElbowRight]); SetEllipsePosition(ankleLeft, skeleton.Joints[JointID.AnkleLeft]); SetEllipsePosition(footLeft, skeleton.Joints[JointID.FootLeft]); SetEllipsePosition(footRight, skeleton.Joints[JointID.FootRight]); SetEllipsePosition(wristLeft, skeleton.Joints[JointID.WristLeft]); SetEllipsePosition(wristRight, skeleton.Joints[JointID.WristRight]); SetEllipsePosition(kneeLeft, skeleton.Joints[JointID.KneeLeft]); SetEllipsePosition(kneeRight, skeleton.Joints[JointID.KneeRight]); SetEllipsePosition(hipCenter, skeleton.Joints[JointID.HipCenter]);*/ currentController.processSkeletonFrame(skeleton, targets); } }
/// <summary> /// Returns the skeletons found in the current frame. /// </summary> /// <param name="frame">The SkeletonFrame generated by the Kinect sensor.</param> /// <returns>An array of skeletons or an empty array if no skeletons were found.</returns> public static Skeleton[] Skeletons(this SkeletonFrame frame) { frame.CopySkeletonDataTo(_skeletons); return(_skeletons); }
void OnUpdate(object sender, AllFramesReadyEventArgs e) { // KINECT Add code to get joint data and smooth it if (Application.Current.MainWindow == null || Container.Instance == null) { return; } Nui.Skeleton skeleton = null; PreviousCursorPosition = CursorPosition; if (e == null) { CursorPosition = Mouse.GetPosition(Application.Current.MainWindow); } else { using (SkeletonFrame skeletonFrameData = e.OpenSkeletonFrame()) { if (skeletonFrameData != null) { Skeleton[] allSkeletons = new Skeleton[skeletonFrameData.SkeletonArrayLength]; skeletonFrameData.CopySkeletonDataTo(allSkeletons); foreach (Skeleton sd in allSkeletons) { if (sd.TrackingState == Nui.SkeletonTrackingState.Tracked) { skeleton = sd; break; } } if (skeleton == null) { return; } var nuiv = skeleton.Joints[JointType.HandRight].ScaleTo((int)ActualWidth, (int)ActualHeight, 0.50f, 0.30f).Position; CursorPosition = new Point(nuiv.X, nuiv.Y); } } } // Update which graphical element the cursor is currently over if (!Passive) { UpdateElementOver(); } if (Container.Instance.sensor == null) { // For mouse, see if the right mouse button is down. if (_isPainting) { if (Mouse.LeftButton == MouseButtonState.Released) { MainWindow.Instance.StopPainting(); } } else { if (Mouse.LeftButton == MouseButtonState.Pressed) { MainWindow.Instance.StartPainting(); } } _isPainting = Mouse.LeftButton == MouseButtonState.Pressed; } else { if (skeleton == null) { return; } // To begin painting w/ Kinect, raise your left hand above your shoulder. // To stop painting, lower it. Nui.Joint lh = skeleton.Joints[Nui.JointType.HandLeft]; Nui.Joint ls = skeleton.Joints[Nui.JointType.ShoulderLeft]; bool isup = lh.Position.Y > ls.Position.Y; if (isup != _isPainting) { _isPainting = isup; if (_isPainting) { MainWindow.Instance.StartPainting(); } else { MainWindow.Instance.StopPainting(); } } } }
public void SetSkeletalFrame(SkeletonFrame frame) { this.skeletalFrame = frame; }
private MasterDetails FrameToMasterDetail(SkeletonFrame frame) { if (this.initialTimestamp == 0) { this.initialTimestamp = frame.Timestamp; } return new MasterDetails() { Master = new FrameContainer () { FrameString = FrameSpecifier, Index = ++this.totalFrames, UserCount = 1, TimeStamp = frame.Timestamp - this.initialTimestamp }, Details = new SkeletonContainer[]{ this.ToContainer(frame) } }; }
void gNUI_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { gSkeletonFrame = e.SkeletonFrame; gUP.gGD.getSFPS(); }
public abstract void AddFrame(SkeletonFrame frame);
private void OnAllFramesReady(object sender, Microsoft.Kinect.AllFramesReadyEventArgs allFramesReadyEventArgs) { ColorImageFrame colorImageFrame = null; DepthImageFrame depthImageFrame = null; SkeletonFrame skeletonFrame = null; try { colorImageFrame = allFramesReadyEventArgs.OpenColorImageFrame(); depthImageFrame = allFramesReadyEventArgs.OpenDepthImageFrame(); skeletonFrame = allFramesReadyEventArgs.OpenSkeletonFrame(); if (colorImageFrame == null || depthImageFrame == null || skeletonFrame == null) { return; } // Check for image format changes. The FaceTracker doesn't // deal with that so we need to reset. if (this.depthImageFormat != depthImageFrame.Format) { this.depthImage = null; this.depthImageFormat = depthImageFrame.Format; } if (this.colorImageFormat != colorImageFrame.Format) { this.colorImage = null; this.colorImageFormat = colorImageFrame.Format; } // Create any buffers to store copies of the data we work with if (this.depthImage == null) { this.depthImage = new short[depthImageFrame.PixelDataLength]; } if (this.colorImage == null) { this.colorImage = new byte[colorImageFrame.PixelDataLength]; } // Get the skeleton information if (this.SkeletonData == null || this.SkeletonData.Length != skeletonFrame.SkeletonArrayLength) { this.SkeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength]; } colorImageFrame.CopyPixelDataTo(this.colorImage); depthImageFrame.CopyPixelDataTo(this.depthImage); skeletonFrame.CopySkeletonDataTo(this.SkeletonData); Skeleton activeSkeleton = null; activeSkeleton = (from skel in this.SkeletonData where skel.TrackingState == SkeletonTrackingState.Tracked select skel).FirstOrDefault(); //Idea: Separate Eye-Parts of Color Image //Use learning Algorithm for right and left eye //Detect blink on separated parts of color Image //colorImage is one dimensional array with 640 x 480 x 4 (RGBA) values if (activeSkeleton != null) { FaceTrackFrame currentFaceFrame = faceTracker.Track(ColorImageFormat.RgbResolution640x480Fps30, colorImage, depthImageFormat, depthImage, activeSkeleton); float browRaiserValue = currentFaceFrame.GetAnimationUnitCoefficients()[AnimationUnit.BrowRaiser]; float browLowererValue = currentFaceFrame.GetAnimationUnitCoefficients()[AnimationUnit.BrowLower]; tbBrowLowerer.Text = browLowererValue.ToString(); tbBrowRaiser.Text = browRaiserValue.ToString(); //Get relevant Points for blink detection //Left eye int minX = (int)Math.Round(currentFaceFrame.GetProjected3DShape()[FeaturePoint.AboveOneFourthLeftEyelid].X); int minY = (int)Math.Round(currentFaceFrame.GetProjected3DShape()[FeaturePoint.AboveOneFourthLeftEyelid].Y); int maxX = (int)Math.Round(currentFaceFrame.GetProjected3DShape()[FeaturePoint.BelowThreeFourthLeftEyelid].X); int maxY = (int)Math.Round(currentFaceFrame.GetProjected3DShape()[FeaturePoint.BelowThreeFourthLeftEyelid].Y); Bitmap leftEye = EyeExtract(colorImageFrame, currentFaceFrame, minX, minY, maxX, maxY, false); pbLeftEye.Image = leftEye; //Right eye minX = (int)Math.Round(currentFaceFrame.GetProjected3DShape()[FeaturePoint.AboveThreeFourthRightEyelid].X); minY = (int)Math.Round(currentFaceFrame.GetProjected3DShape()[FeaturePoint.AboveThreeFourthRightEyelid].Y); maxX = (int)Math.Round(currentFaceFrame.GetProjected3DShape()[FeaturePoint.OneFourthBottomRightEyelid].X); maxY = (int)Math.Round(currentFaceFrame.GetProjected3DShape()[FeaturePoint.OneFourthBottomRightEyelid].Y); Bitmap rightEye = EyeExtract(colorImageFrame, currentFaceFrame, minX, minY, maxX, maxY, true); pbRightEye.Image = rightEye; //Wende Kantenfilter auf die beiden Augen an. double dxRight; double dyRight; double dxLeft; double dyLeft; if (rightEye != null && leftEye != null) { Bitmap edgePicRight = Convolution(ConvertGrey(rightEye), true, out dxRight, out dyRight); Bitmap edgePicLeft = Convolution(ConvertGrey(leftEye), false, out dxLeft, out dyLeft); //If Face is rotated, move Mouse if (headRotationHistory.Count > filterLength && currentFaceFrame.TrackSuccessful) { int x = 0; int y = 0; //Method 1: Ohne Glättung //ScaleXY(currentFaceFrame.Rotation, out x, out y); //MouseControl.Move(x, y); ////Method 2: Glättung über die letzten x Bilder: //int i = 0; //Vector3DF rotationMedium = new Vector3DF(); //while (i < 10 && headRotationHistory.Count - 1 > i) //{ // i++; // rotationMedium.X += headRotationHistory[headRotationHistory.Count - 1 - i].X; // rotationMedium.Y += headRotationHistory[headRotationHistory.Count - 1 - i].Y; //} //rotationMedium.X = rotationMedium.X / i; //rotationMedium.Y = rotationMedium.Y / i; //ScaleXY(rotationMedium, out x, out y); //MouseControl.Move(x, y); //Method 3: Gauß-Filter: Gewichte die letzten Bilder stärker. Vector3DF rotationMedium = new Vector3DF(); rotationMedium.X = currentFaceFrame.Rotation.X * gaussFilter[0]; rotationMedium.Y = currentFaceFrame.Rotation.Y * gaussFilter[0]; int i = 0; while (i < filterLength - 1) { i++; rotationMedium.X += (headRotationHistory[headRotationHistory.Count - 1 - i].X * gaussFilter[i]); rotationMedium.Y += (headRotationHistory[headRotationHistory.Count - 1 - i].Y * gaussFilter[i]); } rotationMedium.X = (float)(rotationMedium.X / gaussFactor); rotationMedium.Y = (float)(rotationMedium.Y / gaussFactor); ScaleXY(rotationMedium, out x, out y); MouseControl.Move(x, y); //Method 4: Quadratische Glättung //double deltaX = ((-currentFaceFrame.Rotation.Y) - (-headRotationHistory.Last().Y)); //double deltaY = ((-currentFaceFrame.Rotation.X) - (-headRotationHistory.Last().X)); //if (deltaX < 0) // deltaX = -Math.Pow(deltaX, 2) * 4; //else // deltaX = Math.Pow(deltaX, 2) * 4; //if (deltaY < 0) // deltaY = -Math.Pow(deltaY, 2) * 5; //else // deltaY = Math.Pow(deltaY, 2) * 5; //MouseControl.DeltaMove((int)Math.Round(deltaX, 0), (int)Math.Round(deltaY)); } headRotationHistory.Add(currentFaceFrame.Rotation); if (headRotationHistory.Count >= 100) { headRotationHistory.RemoveAt(0); } } } } catch (Exception e) { } finally { if (colorImageFrame != null) { colorImageFrame.Dispose(); } if (depthImageFrame != null) { depthImageFrame.Dispose(); } if (skeletonFrame != null) { skeletonFrame.Dispose(); } } }
//--------------------------SKELETON------------------------------------ void nui_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { // Change on Pose if (mShow.type == Utils.POSE_CHANGE) { SkeletonFrame skeletonFrame = e.SkeletonFrame; if (skeletonFrame == null) { return; } foreach (SkeletonData skeleton in skeletonFrame.Skeletons) { // Unschöne Methode - Sollte man irgendwie anders lösen Pose Y = new Pose(0, "Y", Pose.getArrayFromID(0, skeleton)); if (SkeletonTrackingState.Tracked == skeleton.TrackingState) { if (skeleton.Joints.Count > 0) { if (Y.fits() && poseLock == false) { lastPoseTime = DateTime.Now.Minute * 60 + DateTime.Now.Second; nextEffect(); poseLock = true; } else if (poseLock && lastPoseTime + Utils.POSE_TIME_OFFSET < DateTime.Now.Minute * 60 + DateTime.Now.Second) { poseLock = false; } } } } } // Flashes else if (mShow.flashes != null && mShow.type == Utils.TIME_CHANGE) { SkeletonFrame skeletonFrame = e.SkeletonFrame; if (skeletonFrame == null) { return; } foreach (SkeletonData skeleton in skeletonFrame.Skeletons) { if (SkeletonTrackingState.Tracked == skeleton.TrackingState) { if (skeleton.Joints.Count > 0) { for (int i = 0; i < mShow.flashes.Count; i++) { int Z = mShow.flashes.ElementAt(i).pose_id; Pose Y = new Pose(Z, i + "" + Z, Pose.getArrayFromID(Z, skeleton)); if (Y.fits()) { mShow.flashes.ElementAt(i).active = true; } else { mShow.flashes.ElementAt(i).active = false; } } } } } } //Screenshot on pose if no flashes are selected else if (mShow.flashes == null && mShow.type == Utils.TIME_CHANGE) { SkeletonFrame skeletonFrame = e.SkeletonFrame; if (skeletonFrame == null) { return; } foreach (SkeletonData skeleton in skeletonFrame.Skeletons) { Pose Y = new Pose(0, "Y", Pose.getArrayFromID(0, skeleton)); if (SkeletonTrackingState.Tracked == skeleton.TrackingState) { if (skeleton.Joints.Count > 0) { if (Y.fits() && poseLock == false) { lastPoseTime = DateTime.Now.Minute * 60 + DateTime.Now.Second; makeScreenshot(currentGameTime); poseLock = true; } else if (poseLock && lastPoseTime + Utils.POSE_TIME_OFFSET < DateTime.Now.Minute * 60 + DateTime.Now.Second) { poseLock = false; } } } } } }
void KinectFaceNode_AllFrameReady(object sender, AllFramesReadyEventArgs e) { ColorImageFrame colorImageFrame = null; DepthImageFrame depthImageFrame = null; SkeletonFrame skeletonFrame = null; colorImageFrame = e.OpenColorImageFrame(); depthImageFrame = e.OpenDepthImageFrame(); skeletonFrame = e.OpenSkeletonFrame(); if (colorImageFrame == null || depthImageFrame == null || skeletonFrame == null) { return; } if (first) { first = false; this.olddepth = depthImageFrame.Format; } else { if (this.olddepth != depthImageFrame.Format) { //Need a reset if (this.depthImage != null) { this.depthImage = null; } if (this.face != null) { this.face.Dispose(); this.face = null; } this.trackedSkeletons.Clear(); this.olddepth = depthImageFrame.Format; } } if (this.depthImage == null) { this.depthImage = new short[depthImageFrame.PixelDataLength]; } if (this.colorImage == null) { this.colorImage = new byte[colorImageFrame.PixelDataLength]; } if (this.skeletonData == null || this.skeletonData.Length != skeletonFrame.SkeletonArrayLength) { this.skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength]; } if (face == null) { face = new FaceTracker(this.runtime.Runtime); } colorImageFrame.CopyPixelDataTo(this.colorImage); depthImageFrame.CopyPixelDataTo(this.depthImage); skeletonFrame.CopySkeletonDataTo(this.skeletonData); foreach (Skeleton skeleton in this.skeletonData) { if (skeleton.TrackingState == SkeletonTrackingState.Tracked || skeleton.TrackingState == SkeletonTrackingState.PositionOnly) { // We want keep a record of any skeleton, tracked or untracked. if (!this.trackedSkeletons.ContainsKey(skeleton.TrackingId)) { this.trackedSkeletons.Add(skeleton.TrackingId, new SkeletonFaceTracker()); } // Give each tracker the upated frame. SkeletonFaceTracker skeletonFaceTracker; if (this.trackedSkeletons.TryGetValue(skeleton.TrackingId, out skeletonFaceTracker)) { skeletonFaceTracker.OnFrameReady(this.runtime.Runtime, colorImageFrame.Format, colorImage, depthImageFrame.Format, depthImage, skeleton); skeletonFaceTracker.LastTrackedFrame = skeletonFrame.FrameNumber; } } } this.RemoveOldTrackers(skeletonFrame.FrameNumber); colorImageFrame.Dispose(); depthImageFrame.Dispose(); skeletonFrame.Dispose(); this.FInvalidate = true; }
/// <summary> /// Handles the SkeletonFrameReady event of the newKinect control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="Microsoft.Kinect.SkeletonFrameReadyEventArgs"/> instance containing the event data.</param> void Kinect_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { // use flag not to track movements, on timer flag will change to true. if (bFlag == false) { return; } // Opens the received SkeletonFrame using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { // Skeleton frame might be null if we are too late or if the Kinect has been stopped if (skeletonFrame == null) { return; } // Copies the data in a Skeleton array (6 items) skeletonFrame.CopySkeletonDataTo(skeletonData); // Retrieves Skeleton objects with Tracked state var trackedSkeletons = skeletonData.Where(s => s.TrackingState == SkeletonTrackingState.Tracked); // By default, assume all the drawn skeletons are inactive foreach (SkeletonDrawing skeleton in drawnSkeletons.Values) { skeleton.Status = ActivityState.Inactive; } foreach (Skeleton trackedSkeleton in trackedSkeletons) { SkeletonDrawing skeletonDrawing; // Checks if the tracked skeleton is already drawn. if (!drawnSkeletons.ContainsKey(trackedSkeleton.TrackingId)) { // If not, create a new drawing on our canvas skeletonDrawing = new SkeletonDrawing(this.SkeletonCanvas); drawnSkeletons.Add(trackedSkeleton.TrackingId, skeletonDrawing); } else { skeletonDrawing = drawnSkeletons[trackedSkeleton.TrackingId]; } // Update the drawing foreach (Joint joint in trackedSkeleton.Joints) { // Transforms a SkeletonPoint to a ColorImagePoint //var colorPoint = Kinect.MapSkeletonPointToColor(joint.Position, Kinect.ColorStream.Format); var colorPoint = Kinect.CoordinateMapper.MapSkeletonPointToColorPoint(joint.Position, Kinect.ColorStream.Format); // Scale the ColorImagePoint position to the current window size var point = new Point((int)colorPoint.X / 640.0 * this.ActualWidth, (int)colorPoint.Y / 480.0 * this.ActualHeight); // update the position of that joint skeletonDrawing.Update(joint.JointType, point, joint.Position.Z); JointData data = new JointData(sw.Elapsed, joint.JointType, joint.TrackingState, joint.Position.X, joint.Position.Y, joint.Position.Z); //CurrentExamData.Data.Add(new JointData(sw.Elapsed, joint)); if (joint.JointType == JointType.ElbowLeft || joint.JointType == JointType.ElbowRight) { CurrentExamData.Data.Add(data); } } skeletonDrawing.Status = ActivityState.Active; } foreach (SkeletonDrawing skeleton in drawnSkeletons.Values) { // Erase all the still inactive drawing. It means they are not tracked anymore. if (skeleton.Status == ActivityState.Inactive) { skeleton.Erase(); } } this.InvalidateVisual(); } }
private static void Nui_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) // Open the Skeleton frame { if (skeletonFrame != null) // check that a frame is available { Skeleton[] skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength]; int TotalSkeletons = skeletonFrame.SkeletonArrayLength; int counter = 0; skeletonFrame.CopySkeletonDataTo(skeletons); // get the skeletal information in this frame foreach (Skeleton S in skeletons) { if (S.ClippedEdges.HasFlag(FrameEdges.Left) || S.ClippedEdges.HasFlag(FrameEdges.Right)) { S.TrackingState = SkeletonTrackingState.NotTracked; closestdistance = 10000f; closestid = 0; skeletonFrame.Dispose(); } if (S.TrackingState != SkeletonTrackingState.NotTracked) { if (S.Position.Z < closestdistance) { closestid = S.TrackingId; closestdistance = S.Position.Z; } if (closestid > 0) { sensor.SkeletonStream.ChooseSkeletons(closestid); // track this skeleton if (S.TrackingId == closestid) { string json = S.Serialize(); foreach (var socket in _sockets) { socket.Send(json); // send JSON via websocket } } } } if (S.TrackingState == SkeletonTrackingState.NotTracked) { counter++; if (counter == TotalSkeletons) { closestdistance = 10000f; closestid = 0; } } } } else { // beware of using loops! } } }
private void nui_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { bool receivedData = false; using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { if (skeletonFrame != null) { if (skeletons == null) //allocate the first time { skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength]; } receivedData = true; } else { // apps processing of skeleton data took too long; it got more than 2 frames behind. // the data is no longer avabilable. Console.Error.WriteLine("Processing of skeleton data took too long; it got more than 2 frames behind. The data is no longer avabilable."); } if (receivedData) { XmlDocument doc = new XmlDocument(); XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, "", ""); doc.AppendChild(xmlnode); XmlNode root = doc.CreateElement("Skeleton"); doc.AppendChild(root); XmlNode frameNode = doc.CreateElement("frameNumber"); frameNode.InnerText = skeletonFrame.FrameNumber.ToString(); root.AppendChild(frameNode); XmlNode timeStampNode = doc.CreateElement("timeStamp"); timeStampNode.InnerText = skeletonFrame.Timestamp.ToString(); root.AppendChild(timeStampNode); skeletonFrame.CopySkeletonDataTo(skeletons); foreach (Skeleton skeleton in skeletons) { if (skeleton.TrackingState == SkeletonTrackingState.Tracked) { XmlNode skeletonData = doc.CreateElement("skeletonData"); root.AppendChild(skeletonData); XmlNode trackingId = doc.CreateElement("trackingId"); trackingId.InnerText = skeleton.TrackingId.ToString(); skeletonData.AppendChild(trackingId); //These lines remained from the beta sdk version of jenect. There seams to be no equivalence in API 1.0 anymore... /*XmlNode userIndex = doc.CreateElement("userIndex"); * userIndex.InnerText = skeleton.UserIndex.ToString(); * skeletonData.AppendChild(userIndex);*/ JointCollection joints = skeleton.Joints; foreach (Joint j in joints) { XmlNode joint = doc.CreateElement("joint"); XmlNode jPositionX = doc.CreateElement("positionX"); jPositionX.InnerText = j.Position.X.ToString(); joint.AppendChild(jPositionX); XmlNode jPositionY = doc.CreateElement("positionY"); jPositionY.InnerText = j.Position.Y.ToString(); joint.AppendChild(jPositionY); XmlNode jPositionZ = doc.CreateElement("positionZ"); jPositionZ.InnerText = j.Position.Z.ToString(); joint.AppendChild(jPositionZ); XmlNode jointID = doc.CreateElement("jointId"); jointID.InnerText = j.JointType.ToString(); joint.AppendChild(jointID); skeletonData.AppendChild(joint); } XmlNode positionX = doc.CreateElement("positionX"); positionX.InnerText = skeleton.Position.X.ToString(); skeletonData.AppendChild(positionX); XmlNode positionY = doc.CreateElement("positionY"); positionY.InnerText = skeleton.Position.Y.ToString(); skeletonData.AppendChild(positionY); XmlNode positionZ = doc.CreateElement("positionZ"); positionZ.InnerText = skeleton.Position.Z.ToString(); skeletonData.AppendChild(positionZ); } appendSkeletonToQueue(doc.OuterXml); //cch.sendSkeleton(doc.OuterXml); } } } }
private SkeletonContainer ToContainer(SkeletonFrame frame) { return new SkeletonContainer() { ID = (short)frame.TrackingInformation.TrackingID, Confidence = (int)frame.TrackingInformation.TrackingState * 0.5f, HipCenter = frame[SkeletonHelp.HipCenter].ToArray(), Spine = frame[SkeletonHelp.Spine].ToArray(), ShoulderCenter = frame [SkeletonHelp.ShoulderCenter].ToArray (), Head = frame[SkeletonHelp.Head].ToArray(), ShoulderLeft = frame [SkeletonHelp.ShoulderLeft].ToArray (), ElbowLeft = frame [SkeletonHelp.ElbowLeft].ToArray (), WristLeft = frame [SkeletonHelp.WristLeft].ToArray (), HandLeft = frame [SkeletonHelp.HandLeft].ToArray (), ShoulderRight = frame [SkeletonHelp.ShoulderRight].ToArray (), ElbowRight = frame [SkeletonHelp.ElbowRight].ToArray (), WristRight = frame [SkeletonHelp.WristRight].ToArray (), HandRight = frame [SkeletonHelp.HandRight].ToArray (), HipLeft = frame [SkeletonHelp.HipLeft].ToArray (), KneeLeft = frame [SkeletonHelp.KneeLeft].ToArray (), AnkleLeft = frame [SkeletonHelp.AnkleLeft].ToArray (), FootLeft = frame [SkeletonHelp.FootLeft].ToArray (), HipRight = frame [SkeletonHelp.HipRight].ToArray (), KneeRight = frame [SkeletonHelp.KneeRight].ToArray (), AnkleRight = frame [SkeletonHelp.AnkleRight].ToArray (), FootRight = frame [SkeletonHelp.FootRight].ToArray () }; }
private void OnAllFramesReady(object sender, AllFramesReadyEventArgs allFramesReadyEventArgs) { ColorImageFrame colorImageFrame = null; DepthImageFrame depthImageFrame = null; SkeletonFrame skeletonFrame = null; try { colorImageFrame = allFramesReadyEventArgs.OpenColorImageFrame(); depthImageFrame = allFramesReadyEventArgs.OpenDepthImageFrame(); skeletonFrame = allFramesReadyEventArgs.OpenSkeletonFrame(); if (colorImageFrame == null || depthImageFrame == null || skeletonFrame == null) { return; } // Check for image format changes. The FaceTracker doesn't // deal with that so we need to reset. if (this.depthImageFormat != depthImageFrame.Format) { this.ResetFaceTracking(); this.depthImage = null; this.depthImageFormat = depthImageFrame.Format; } if (this.colorImageFormat != colorImageFrame.Format) { this.ResetFaceTracking(); this.colorImage = null; this.colorImageFormat = colorImageFrame.Format; } // Create any buffers to store copies of the data we work with if (this.depthImage == null) { this.depthImage = new short[depthImageFrame.PixelDataLength]; } if (this.colorImage == null) { this.colorImage = new byte[colorImageFrame.PixelDataLength]; } // Get the skeleton information if (this.skeletonData == null || this.skeletonData.Length != skeletonFrame.SkeletonArrayLength) { this.skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength]; } colorImageFrame.CopyPixelDataTo(this.colorImage); depthImageFrame.CopyPixelDataTo(this.depthImage); skeletonFrame.CopySkeletonDataTo(this.skeletonData); // Update the list of trackers and the trackers with the current frame information foreach (Skeleton skeleton in this.skeletonData) { if (skeleton.TrackingState == SkeletonTrackingState.Tracked || skeleton.TrackingState == SkeletonTrackingState.PositionOnly) { // We want keep a record of any skeleton, tracked or untracked. if (!this.trackedSkeletons.ContainsKey(skeleton.TrackingId)) { this.trackedSkeletons.Add(skeleton.TrackingId, new SkeletonFaceTracker()); } // Give each tracker the upated frame. SkeletonFaceTracker skeletonFaceTracker; if (this.trackedSkeletons.TryGetValue(skeleton.TrackingId, out skeletonFaceTracker)) { skeletonFaceTracker.OnFrameReady(this.Kinect, colorImageFormat, colorImage, depthImageFormat, depthImage, skeleton); skeletonFaceTracker.LastTrackedFrame = skeletonFrame.FrameNumber; } } } this.RemoveOldTrackers(skeletonFrame.FrameNumber); this.InvalidateVisual(); } finally { if (colorImageFrame != null) { colorImageFrame.Dispose(); } if (depthImageFrame != null) { depthImageFrame.Dispose(); } if (skeletonFrame != null) { skeletonFrame.Dispose(); } } }
private void Kinect_AllFramesReady(object sender, AllFramesReadyEventArgs allFramesReadyEventArgs) { ColorImageFrame colorImageFrame = null; DepthImageFrame depthImageFrame = null; SkeletonFrame skeletonFrame = null; try { colorImageFrame = allFramesReadyEventArgs.OpenColorImageFrame(); depthImageFrame = allFramesReadyEventArgs.OpenDepthImageFrame(); skeletonFrame = allFramesReadyEventArgs.OpenSkeletonFrame(); if (colorImageFrame == null || depthImageFrame == null || skeletonFrame == null) { return; } // Check for image format changes. The FaceTracker doesn't // deal with that so we need to reset. if (this.depthImageFormat != depthImageFrame.Format) { this.depthImage = null; this.depthImageFormat = depthImageFrame.Format; } if (this.colorImageFormat != colorImageFrame.Format) { this.colorImage = null; this.colorImageFormat = colorImageFrame.Format; } // Create any buffers to store copies of the data we work with if (this.depthImage == null) { this.depthImage = new short[depthImageFrame.PixelDataLength]; } if (this.colorImage == null) { this.colorImage = new byte[colorImageFrame.PixelDataLength]; } // Get the skeleton information if (this.skeletonData == null || this.skeletonData.Length != skeletonFrame.SkeletonArrayLength) { this.skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength]; } // TODO look into using the Timestamp on each frame var time = pipeline.GetCurrentTime(); var sharedColorImage = ImagePool.GetOrCreate(colorImageFrame.Width, colorImageFrame.Height, Imaging.PixelFormat.BGRX_32bpp); var sharedDepthImage = ImagePool.GetOrCreate(depthImageFrame.Width, depthImageFrame.Height, Imaging.PixelFormat.Gray_16bpp); colorImageFrame.CopyPixelDataTo(sharedColorImage.Resource.ImageData, (colorImageFrame.Width * colorImageFrame.Height * 4)); this.ColorImage.Post(sharedColorImage, time); //depthImageFrame.CopyPixelDataTo(sharedDepthImage.Resource.ImageData, (depthImageFrame.Width * depthImageFrame.Height * 2)); depthImageFrame.CopyPixelDataTo(sharedDepthImage.Resource.ImageData, depthImageFrame.PixelDataLength); this.DepthImage.Post(sharedDepthImage, time); skeletonFrame.CopySkeletonDataTo(this.skeletonData); this.Skeletons.Post(this.skeletonData.ToList(), time); } catch { // TODO catch a cold } }
public void UpdateKinectSkeleton(SkeletonFrame Sk) { try { gGD.UpdateSkeleton(Sk); } catch { } }
private 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); } } // Used to determine when skeletons move off the screen List <int> unseenTrackingIDs = this.trackingIDsToSequences.Keys.ToList(); foreach (Skeleton skel in skeletons) { if (skel.TrackingState == SkeletonTrackingState.Tracked) { if (!isSaving) { GhostSkeletonSequence sequence; if (!this.trackingIDsToSequences.ContainsKey(skel.TrackingId)) { Console.WriteLine("Adding tracking ID " + skel.TrackingId); sequence = new GhostSkeletonSequence(); this.trackingIDsToSequences.Add(skel.TrackingId, sequence); } else { sequence = this.trackingIDsToSequences[skel.TrackingId]; } unseenTrackingIDs.Remove(skel.TrackingId); sequence.AddSkeleton(skel); } } } if (!isSaving) { foreach (int trackingID in unseenTrackingIDs) { if (!this.trackingIDsToSequences.ContainsKey(trackingID)) { return; } Console.WriteLine("we have " + unseenTrackingIDs.Count + " unseen tracking IDs"); BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += (obj, args) => { GhostSkeletonSequence sequence = this.trackingIDsToSequences[trackingID]; this.trackingIDsToSequences.Remove(trackingID); sequence.FinalizeRecording(); isSaving = true; Console.WriteLine("beginning save"); this.dataContext.GhostSkeletonSequences.InsertOnSubmit(sequence); Console.WriteLine("saved!"); sequence.UpdateCache(GhostSkeletonSequence.DefaultInterpolationFactor); Console.WriteLine("Locking down. updating saved sequences"); lock (lockObj) { this.savedSequences.Add(sequence); } Console.WriteLine("Saved sequences updated. Unlocking."); isSaving = false; }; worker.RunWorkerAsync(); } // prevent drawing outside of our render area this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, RenderWidth, RenderHeight)); } }
void Nui_SkeletonFrameReady(object sender, Microsoft.Research.Kinect.Nui.SkeletonFrameReadyEventArgs e) { skeletonFrame_ = e.SkeletonFrame; pictureSkeleton.Refresh(); if (kinect_._capturing) { labelLastGesture.Text = "Recording gesture" + textGesture.Text + ": " + (int)((kinect_.nof_ / 32f)*100f) + " %"; } }
public static void DebugSkeleton(SkeletonFrame skeleton, Matrix transform) { if (skeleton != null) { //transform *= SwitchAxesZwithY; var positions = skeleton.JointPositions.Select((position) => transform * position).ToArray(); Logger.DrawLine(positions [Head], positions [ShoulderCenter]); Logger.DrawLine(positions [ShoulderCenter], positions [ShoulderLeft]); Logger.DrawLine(positions [ShoulderCenter], positions [ShoulderRight]); Logger.DrawLine(positions [ShoulderLeft], positions [ElbowLeft]); Logger.DrawLine(positions [ElbowLeft], positions [WristLeft]); //Logger.DrawLine (positions [WristLeft], positions [HandLeft]); Logger.DrawLine(positions [ShoulderRight], positions [ElbowRight]); Logger.DrawLine(positions [ElbowRight], positions [WristRight]); //Logger.DrawLine (positions [WristRight], positions [HandRight]); Logger.DrawLine(positions [ShoulderCenter], positions [Spine]); //Logger.DrawLine (positions [ShoulderLeft], positions [Spine]); //Logger.DrawLine (positions [ShoulderRight], positions [Spine]); Logger.DrawLine(positions [Spine], positions [HipCenter]); Logger.DrawLine(positions [HipCenter], positions [HipLeft]); Logger.DrawLine(positions [HipCenter], positions [HipRight]); Logger.DrawLine(positions [HipLeft], positions [KneeLeft]); Logger.DrawLine(positions [KneeLeft], positions [AnkleLeft]); //Logger.DrawLine (positions [AnkleLeft], positions [FootLeft]); Logger.DrawLine(positions [HipRight], positions [KneeRight]); Logger.DrawLine(positions [KneeRight], positions [AnkleRight]); //Logger.DrawLine (positions [AnkleRight], positions [FootRight]); } }
void RecieveAndSetSkeletons(SkeletonFrame AllSkeletons) { TrackedSkeleton = (from s in AllSkeletons.Skeletons where s.TrackingState == SkeletonTrackingState.Tracked select s).FirstOrDefault(); RunWordSearch(); }
private void SensorSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { floorPlane = skeletonFrame.FloorClipPlane; if (skeletonFrame != null) { if (this.skeletons == null) { this.skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength]; } skeletonFrame.CopySkeletonDataTo(this.skeletons); Skeleton skeleton = this.skeletons.Where(s => s.TrackingState == SkeletonTrackingState.Tracked).FirstOrDefault(); floorPlane = skeletonFrame.FloorClipPlane; if (skeleton != null) { Joint kneeLeft = skeleton.Joints[JointType.KneeLeft]; Joint kneeRight = skeleton.Joints[JointType.KneeRight]; Joint ankleLeft = skeleton.Joints[JointType.AnkleLeft]; Joint ankleRight = skeleton.Joints[JointType.AnkleRight]; Joint footLeft = skeleton.Joints[JointType.FootLeft]; Joint footRight = skeleton.Joints[JointType.FootRight]; if ((ankleLeft.TrackingState == JointTrackingState.Tracked && ankleLeft.TrackingState == JointTrackingState.Tracked) && (footLeft.TrackingState == JointTrackingState.Tracked && footLeft.TrackingState == JointTrackingState.Tracked) && (kneeLeft.TrackingState == JointTrackingState.Tracked && kneeLeft.TrackingState == JointTrackingState.Tracked)) { time = DateTime.Now; timeInSecond = time.Minute * 60 + time.Second; float leftFootFloorDistance = (float)Math.Round(Math.Abs((floorPlane.Item1 * footLeft.Position.X) + (floorPlane.Item2 * footLeft.Position.Y) + (floorPlane.Item3 * footLeft.Position.Z) + floorPlane.Item4) / Math.Sqrt(Math.Pow(footLeft.Position.X, 2) + Math.Pow(footLeft.Position.Y, 2) + Math.Pow(footLeft.Position.Z, 2)) * 1000, 2); float rightFootFloorDistance = (float)Math.Round(Math.Abs((floorPlane.Item1 * footRight.Position.X) + (floorPlane.Item2 * footRight.Position.Y) + (floorPlane.Item3 * footRight.Position.Z) + floorPlane.Item4) / Math.Sqrt(Math.Pow(footRight.Position.X, 2) + Math.Pow(footRight.Position.Y, 2) + Math.Pow(footRight.Position.Z, 2)) * 1000, 2); //Improve Accuracy Calibration (Disregard bad skeletons) if (leftFootFloorDistance < 17) { if (leftOnFloorFalse < 5) { leftOnFloorFalse = 0; } if (++leftOnFloorTrue == 7) { leftOnFloor = true; leftOnFloorTrue = 0; leftOnFloorFalse = 0; } } else { if (leftOnFloorTrue < 5) { leftOnFloorTrue = 0; } if (++leftOnFloorFalse == 7) { leftOnFloor = false; leftOnFloorTrue = 0; leftOnFloorFalse = 0; } } if (rightFootFloorDistance < 17) { if (rightOnFloorFalse < 5) { rightOnFloorFalse = 0; } if (++rightOnFloorTrue == 7) { rightOnFloor = true; rightOnFloorTrue = 0; rightOnFloorFalse = 0; } } else { if (rightOnFloorTrue < 5) { rightOnFloorTrue = 0; } if (++rightOnFloorFalse == 7) { rightOnFloor = false; rightOnFloorTrue = 0; rightOnFloorFalse = 0; } } stance = leftOnFloor && rightOnFloor; if (stance) { //Console.Clear(); Console.ForegroundColor = ConsoleColor.Red; //Console.BackgroundColor = ConsoleColor.Red; } else { //Console.Clear(); if (!leftOnFloor && !rightOnFloor) { Console.ForegroundColor = ConsoleColor.White; } else if (!leftOnFloor) { Console.ForegroundColor = ConsoleColor.Blue; } else if (!rightOnFloor) { Console.ForegroundColor = ConsoleColor.Green; } //Console.BackgroundColor = ConsoleColor.Green; } //Stride Velocity if (initialPoint[0] == 0 && initialPoint[1] == 0 && initialPoint[2] == 0) { initialPoint[0] = footLeft.Position.X; initialPoint[1] = footLeft.Position.Y; initialPoint[2] = footLeft.Position.Z; initialTime = timeInSecond; startTime = DateTime.Now; } else { currentPoint[0] = footLeft.Position.X; currentPoint[1] = footLeft.Position.Y; currentPoint[2] = footLeft.Position.Z; currentTime = timeInSecond; totalDistance = Math.Round(Math.Sqrt(Math.Pow(initialPoint[0] - currentPoint[0], 2) + Math.Pow(initialPoint[0] - currentPoint[0], 2) + Math.Pow(initialPoint[0] - currentPoint[0], 2)) * 100, 2); totalTime = currentTime - initialTime; strideVelocity = Math.Round(totalDistance / totalTime, 2); } //Step Length and Step Frequency (Right Foot) if (!rightOnFloor) { if (!stepProcessingRight) { stepProcessingRight = true; initialStepPoint[1, 0] = footRight.Position.X; initialStepPoint[1, 1] = footRight.Position.Y; initialStepPoint[1, 2] = footRight.Position.Z; initialStepTime = timeInSecond; } else { terminalStepPoint[1, 0] = footRight.Position.X; terminalStepPoint[1, 1] = footRight.Position.Y; terminalStepPoint[1, 2] = footRight.Position.Z; terminalStepTime = timeInSecond; } } else { if (stepProcessingRight) { stepProcessingRight = false; ++stepCounter; stepLengthTotal += Math.Round(Math.Sqrt(Math.Pow(initialStepPoint[1, 0] - terminalStepPoint[1, 0], 2) + Math.Pow(initialStepPoint[1, 1] - terminalStepPoint[1, 1], 2) + Math.Pow(initialStepPoint[1, 2] - terminalStepPoint[1, 2], 2)) * 100, 2); stepLength = Math.Round(stepLengthTotal / stepCounter, 2); stepTimeTotal += terminalStepTime - initialStepTime; stepTime = Math.Round(stepTimeTotal / stepCounter, 2); stepFrequency = Math.Round(stepCounter / (totalTime), 2); initialStepPoint[1, 0] = 0; initialStepPoint[1, 1] = 0; initialStepPoint[1, 2] = 0; initialStepTime = 0; terminalStepPoint[1, 0] = 0; terminalStepPoint[1, 1] = 0; terminalStepPoint[1, 2] = 0; terminalStepTime = 0; } } //Step Length and Step Frequency (Left Foot) if (!leftOnFloor) { if (!stepProcessingLeft) { stepProcessingLeft = true; initialStepPoint[0, 0] = footLeft.Position.X; initialStepPoint[0, 1] = footLeft.Position.Y; initialStepPoint[0, 2] = footLeft.Position.Z; initialStepTime = timeInSecond; } else { terminalStepPoint[0, 0] = footLeft.Position.X; terminalStepPoint[0, 1] = footLeft.Position.Y; terminalStepPoint[0, 2] = footLeft.Position.Z; terminalStepTime = timeInSecond; } } else { if (stepProcessingLeft) { stepProcessingLeft = false; ++stepCounter; stepLengthTotal += Math.Round(Math.Sqrt(Math.Pow(initialStepPoint[0, 0] - terminalStepPoint[0, 0], 2) + Math.Pow(initialStepPoint[0, 1] - terminalStepPoint[0, 1], 2) + Math.Pow(initialStepPoint[0, 2] - terminalStepPoint[0, 2], 2)) * 100, 2); stepLength = Math.Round(stepLengthTotal / stepCounter, 2); stepTimeTotal += terminalStepTime - initialStepTime; stepTime = Math.Round(stepTimeTotal / stepCounter, 2); stepFrequency = Math.Round(stepCounter / (totalTime), 2); initialStepPoint[0, 0] = 0; initialStepPoint[0, 1] = 0; initialStepPoint[0, 2] = 0; initialStepTime = 0; terminalStepPoint[0, 0] = 0; terminalStepPoint[0, 1] = 0; terminalStepPoint[0, 2] = 0; terminalStepTime = 0; } } //Stride Length (Left Foot) if (stance && strideProcessingLeft) { strideProcessingLeft = false; initialStridePoint[1, 0] = footRight.Position.X; initialStridePoint[1, 1] = footRight.Position.Y; initialStridePoint[1, 2] = footRight.Position.Z; terminalStridePoint[1, 0] = footLeft.Position.X; terminalStridePoint[1, 1] = footLeft.Position.Y; terminalStridePoint[1, 2] = footLeft.Position.Z; ++strideCounter; strideLengthTotal += Math.Round(Math.Sqrt(Math.Pow(initialStridePoint[1, 0] - terminalStridePoint[1, 0], 2) + Math.Pow(initialStridePoint[1, 1] - terminalStridePoint[1, 1], 2) + Math.Pow(initialStridePoint[1, 2] - terminalStridePoint[1, 2], 2)) * 100, 2); strideLength = Math.Round(strideLengthTotal / strideCounter, 2); } //Stride Length (Right Foot) /*if (leftOnFloor) * { * if (!strideProcessingRight) * { * strideProcessingRight = true; * initialStridePoint[0, 0] = footLeft.Position.X; * initialStridePoint[0, 1] = footLeft.Position.Y; * initialStridePoint[0, 2] = footLeft.Position.Z; * } * * if (!rightOnFloor) * { * terminalStridePoint[0, 0] = footRight.Position.X; * terminalStridePoint[0, 1] = footRight.Position.Y; * terminalStridePoint[0, 2] = footRight.Position.Z; * * } * * else * { * if (strideProcessingRight) * { * * strideProcessingRight = false; ++strideCounter; * strideLengthTotal += Math.Round(Math.Sqrt(Math.Pow(initialStridePoint[0, 0] - terminalStridePoint[0, 0], 2) + Math.Pow(initialStridePoint[0, 1] - terminalStridePoint[0, 1], 2) + Math.Pow(initialStridePoint[0, 2] - terminalStridePoint[0, 2], 2)) * 100, 2); * strideLength = Math.Round(strideLengthTotal / strideCounter, 2); * * initialStridePoint[0, 0] = 0; * initialStridePoint[0, 1] = 0; * initialStridePoint[0, 2] = 0; * * terminalStridePoint[0, 0] = 0; * terminalStridePoint[0, 1] = 0; * terminalStridePoint[0, 2] = 0; * } * } * }*/ //Stance Time and Swing Time if (stance) { if (!(initialSwingTime == 0)) { ++swingCounter; swingTimeTotal += terminalSwingTime - initialSwingTime; swingTime = Math.Round(swingTimeTotal / swingCounter); } if (initialStanceTime == 0) { initialStanceTime = timeInSecond; } else { terminalStanceTime = timeInSecond; } } if (!stance) { strideProcessingLeft = true; if (!(initialStanceTime == 0)) { ++stanceCounter; stanceTimeTotal += terminalStanceTime - initialStanceTime; stanceTime = Math.Round(stanceTimeTotal / stanceCounter); } if (initialSwingTime == 0) { initialSwingTime = timeInSecond; } else { terminalSwingTime = timeInSecond; } } if (frame % 300 == 9) { Console.Clear(); } Console.WriteLine("Frame: " + ++frame); Console.WriteLine(); Console.WriteLine("Gait Parameters"); Console.WriteLine("Step Length: " + stepLength + "cm"); Console.WriteLine("Step Time: " + stepTime + "s"); Console.WriteLine("Step Frequency: " + stepFrequency + " steps/sec"); Console.WriteLine("Stride Length: " + strideLength + "cm"); Console.WriteLine("Stride Velocity: " + strideVelocity + "cm/s"); Console.WriteLine("Stance Time: " + stanceTime + "s"); Console.WriteLine("Swing Time: " + swingTime + "s"); //Console.WriteLine(); //Console.WriteLine("Step Counter: " + stepCounter + " step/s"); //Console.WriteLine("Stride Counter: " + strideCounter + " step/s"); /*Console.WriteLine("Left Foot distance from Floor: " + leftFootFloorDistance); * Console.WriteLine("Right Foot distance from Floor: " + rightFootFloorDistance); * Console.WriteLine("Stance Status: " + stance);*/ //Console.WriteLine("Distance Traveled: " + totalDistance + "cm"); //Console.WriteLine("Time Traveled: " + totalTime + "s"); /*Console.WriteLine(); * Console.WriteLine("Start Time: " + startTime.Hour + ":" + startTime.Minute + ":" + startTime.Second); * Console.WriteLine("Current Time: " + time.Hour + ":" + time.Minute + ":" + time.Second);*/ Console.WriteLine(); } } else { terminateTime = DateTime.Now; if (timeInSecond + 5 == terminateTime.Minute * 60 + terminateTime.Second) { Console.Clear(); return; } } } } }
private void nui_AllFramesReady(object sender, AllFramesReadyEventArgs e) { //DepthStream과 SkeletonStream에 동시에 추가한 이벤트 핸들러 SkeletonFrame sf = e.OpenSkeletonFrame(); //현재 인식한 골격정보(스캘리톤)을 sf라는 변수에 저장 if (sf == null) { return; } //골격이 인식되지 못하면, 즉 사람이 인식되지 않으면 보여줄 상자, 이를 이은 선을 보여줄 필요가 없으므로 종료 Skeleton[] skeletonData = new Skeleton[sf.SkeletonArrayLength]; //스캘리톤(골격정보)를 저장하라 배열을 인식된 수만큼 크기 지정 sf.CopySkeletonDataTo(skeletonData); //현재 SkeletonFrame안에서 스캘리톤 데이터를 복사 using (DepthImageFrame depthImageFrame = e.OpenDepthImageFrame()) { //현재 DepthImageFrame 안에서 데이터 복사 if (depthImageFrame != null) { //데이터가 있다면 foreach (Skeleton sd in skeletonData) { //복사해온 스캘리톤 데이터를 하나씩 차근차근 반복한다 if (sd.TrackingState == SkeletonTrackingState.Tracked) { //인식된 사용자 인덱스 중 추적이 되는 Tracked에 해당하는 골격정보만 사용 int nMax = 20; //키넥트가 인식하는 관절 포인트가 20개 이므로 Joint[] joints = new Joint[nMax]; //만들 조인트만큼(키넥트가 인식하는 것만큼> 20) 조인트 배열 선언 for (int j = 0; j < nMax; j++) { //조인트 생성(초기화 및 설정) joints[j] = sd.Joints[(JointType)j]; } //여기까지 찾아진 골격상태에서 각 골격의 정보를 얻어오기 위함 Point[] points = new Point[nMax]; //뼈대 위치를 저장할 배열 for (int j = 0; j < nMax; j++) { DepthImagePoint depthPoint; depthPoint = depthImageFrame.MapFromSkeletonPoint(joints[j].Position); points[j] = new Point((int)((user_img.Width * depthPoint.X / depthImageFrame.Width) + 340), (int)(user_img.Height * depthPoint.Y / depthImageFrame.Height)); } //여기까지 각 조인트정보로부터 좌표를 얻기 위함 for (int j = 0; j < nMax; j++) { m_rect[j].Visibility = Visibility.Visible; //아까 만들었던 사각형을 보이도록 함 Canvas.SetTop(m_rect[j], points[j].Y - (m_rect[j].Height / 2)); Canvas.SetLeft(m_rect[j], points[j].X - (m_rect[j].Width / 2)); //사각형 배치 } //여기까지 가져온 각 조인트의 정보를 화면에 표시하는 코드 //엉덩이 중앙부터 머리까지 연결되는 선을 긋는 코드 PointCollection pc0 = new PointCollection(4); //이을 관절 개수만큼 크기를 지정하고 위치를 저장할 변수 pc0.Add(points[(int)JointType.HipCenter]); //엉덩이 중간 pc0.Add(points[(int)JointType.Spine]); //등뼈 pc0.Add(points[(int)JointType.ShoulderCenter]); //어깨 중간 pc0.Add(points[(int)JointType.Head]); //머리 m_poly[0].Points = pc0; //관절들 위치를 저장한 변수를 선으로 그리는 함수로 선언한 배열에 넣는다 m_poly[0].Visibility = Visibility.Visible; //넣었으니 활성화시켜 위치를 토대로 그린 선을 보여준다 //왼쪽 손부터 어깨까지 연결되는 선을 긋는 코드 PointCollection pc1 = new PointCollection(5); pc1.Add(points[(int)JointType.ShoulderCenter]); //어깨 중간 pc1.Add(points[(int)JointType.ShoulderLeft]); //왼쪽 어깨 pc1.Add(points[(int)JointType.ElbowLeft]); //왼쪽 팔꿈치 pc1.Add(points[(int)JointType.WristLeft]); //왼쪽 손목 pc1.Add(points[(int)JointType.HandLeft]); //왼손 m_poly[1].Points = pc1; m_poly[1].Visibility = Visibility.Visible; //오른쪽 손부터 어깨까지 연결되는 선을 긋는 코드 PointCollection pc2 = new PointCollection(5); pc2.Add(points[(int)JointType.ShoulderCenter]); //어깨 중간 pc2.Add(points[(int)JointType.ShoulderRight]); //오른쪽 어깨 pc2.Add(points[(int)JointType.ElbowRight]); //오른쪽 팔꿈치 pc2.Add(points[(int)JointType.WristRight]); //오른쪽 손목 pc2.Add(points[(int)JointType.HandRight]); //오른손 m_poly[2].Points = pc2; m_poly[2].Visibility = Visibility.Visible; //왼발부터 엉덩이까지 연결되는 선을 긋는 코드 PointCollection pc3 = new PointCollection(5); pc3.Add(points[(int)JointType.HipCenter]); //엉덩이 중간 pc3.Add(points[(int)JointType.HipLeft]); //엉덩이 왼쪽 pc3.Add(points[(int)JointType.KneeLeft]); //왼쪽 무릎 pc3.Add(points[(int)JointType.AnkleLeft]); //왼쪽 발목 pc3.Add(points[(int)JointType.FootLeft]); //왼쪽 발 m_poly[3].Points = pc3; m_poly[3].Visibility = Visibility.Visible; //오른발부터 엉덩이까지 연결되는 선을 긋는 코드 PointCollection pc4 = new PointCollection(5); pc4.Add(points[(int)JointType.HipCenter]); //엉덩이 중간 pc4.Add(points[(int)JointType.HipRight]); //엉덩이 오른쪽 pc4.Add(points[(int)JointType.KneeRight]); //오른쪽 무릎 pc4.Add(points[(int)JointType.AnkleRight]); //오른쪽 발목 pc4.Add(points[(int)JointType.FootRight]); //오른쪽 발 m_poly[4].Points = pc4; m_poly[4].Visibility = Visibility.Visible; } } } } }
void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e) { if (closing) { return; } //Get a skeleton Skeleton first = GetFirstSkeleton(true, e); //initialize the initial points for head and hands if (!init_flag && first != null) { head_position = first.Joints[JointType.Head].Position.Y; rightH_position = first.Joints[JointType.HandRight].Position.Y; leftH_position = first.Joints[JointType.HandLeft].Position.Y; init_flag = true; } if (first == null) { headImage.Visibility = Visibility.Collapsed; headImage2.Visibility = Visibility.Collapsed; init_flag = false; return; } //activate control when hand is above head if (first.Joints[JointType.HandRight].Position.Y > head_position) { if (first.Joints[JointType.HandRight].Position.X > first.Joints[JointType.Head].Position.X && !pausetime) { SendKeys.SendWait("{RIGHT}"); pausetime = true; } else if (!pausetime) { SendKeys.SendWait("{LEFT}"); pausetime = true; } } if (first.Joints[JointType.HandRight].Position.Y < head_position) { pausetime = false; } headImage.Visibility = Visibility.Visible; //set scaled position //ScalePosition(headImage, first.Joints[JointType.Head]); ScalePosition(leftEllipse, first.Joints[JointType.HandLeft]); ScalePosition(rightEllipse, first.Joints[JointType.HandRight]); GetCameraPoint(first, true, e); using (SkeletonFrame skeletonFrameData = e.OpenSkeletonFrame()) { try{ (from s in allSkeletons where s.TrackingState == SkeletonTrackingState.Tracked select s).ElementAt(1); }catch (ArgumentOutOfRangeException ex) { headImage2.Visibility = Visibility.Collapsed; return; } Skeleton second = GetFirstSkeleton(false, e); headImage2.Visibility = Visibility.Visible; GetCameraPoint(second, false, e); } }
private static void PrintSkeletonFrames(SkeletonFrame frame) { Console.WriteLine("Frame Number: {0}", frame.FrameNumber); Console.WriteLine("Quality: {0}", frame.Quality); Console.WriteLine("TimeStamp: {0}", frame.TimeStamp); foreach (var skeleton in frame.Skeletons.Where(skel => skel.TrackingState == SkeletonTrackingState.Tracked)) { Console.WriteLine(); Console.WriteLine("\tUserIndex: {0}", skeleton.UserIndex); Console.WriteLine("\tTracking Id: {0}", skeleton.TrackingID); Console.WriteLine("\tTracking State: {0}", skeleton.TrackingState); Console.WriteLine("\tQuality: {0}", skeleton.Quality); Console.WriteLine("\tPosition: [W={0}, X={1}, Y={2}, Z={3}]", skeleton.Position.W, skeleton.Position.X, skeleton.Position.Y, skeleton.Position.Z); } Console.WriteLine(); Console.WriteLine("==============================================="); Console.WriteLine(); }
/// <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, SkeletonFrameReadyEventArgs e) { Skeleton[] skeletons = new Skeleton[0]; using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { if (skeletonFrame != null) { skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength]; skeletonFrame.CopySkeletonDataTo(skeletons); } } using (DrawingContext dc = this.drawingGroup.Open()) { // Draw a transparent background to set the render size dc.DrawRectangle(Brushes.Black, null, new Rect(0.0, 0.0, RenderWidth, RenderHeight)); if (skeletons.Length != 0) { if (skeletons.Count(t => t.TrackingState == SkeletonTrackingState.Tracked) == 2) { player1 = skeletons.First(p => p.TrackingState == SkeletonTrackingState.Tracked); player2 = skeletons.Last(p => p.TrackingState == SkeletonTrackingState.Tracked); if (ingame == true) { BangLogik(); } if (player1.Joints[JointType.HandRight].Position.Y < player1.Joints[JointType.Head].Position.Y && player2.Joints[JointType.HandRight].Position.Y < player2.Joints[JointType.Head].Position.Y && ingame == false) { Bang.Text = "Ready"; ingame = true; player1shot = false; player2shot = false; bang = false; } } foreach (Skeleton skel in skeletons) { RenderClippedEdges(skel, dc); if (skel.TrackingState == SkeletonTrackingState.Tracked) { this.DrawBonesAndJoints(skel, dc); } else if (skel.TrackingState == SkeletonTrackingState.PositionOnly) { dc.DrawEllipse( this.centerPointBrush, null, this.SkeletonPointToScreen(skel.Position), BodyCenterThickness, BodyCenterThickness); } } } // prevent drawing outside of our render area this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, RenderWidth, RenderHeight)); } }
void kinectRuntime_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { SkeletonFrame skeletonFrame = e.OpenSkeletonFrame(); if (skeletonFrame == null) { debugValue.Text = "Skeleton not tracked"; return; } Skeleton[] rawskels = new Skeleton[skeletonFrame.SkeletonArrayLength]; skeletonFrame.CopySkeletonDataTo(rawskels); var trackedSkels = rawskels.Where((s) => s.TrackingState != SkeletonTrackingState.NotTracked).Select((s) => s).ToList(); if (trackedSkels.Count == 0) { nbFrameWithoutSkeleton++; if (nbFrameWithoutSkeleton == 30) { Dispatcher.BeginInvoke(new Action(() => { sbHideLaser.Begin(); })); } return; } //SkeletonData data = (from s in skeletonFrame.Skeletons // where s.TrackingState == SkeletonTrackingState.Tracked // select s).FirstOrDefault(); // on ne traite que le 1er skelete détecté //if (data == null) //{ // debugValue.Text = "Skeleton not tracked"; // return; //} if (nbFrameWithoutSkeleton != 0) { Dispatcher.BeginInvoke(new Action(() => { sbShowLaser.Begin(); })); } nbFrameWithoutSkeleton = 0; if (laserHidden) { laserHidden = false; sbShowLaser.Begin(); //if (canvLaser.Visibility != Visibility.Visible) // canvLaser.Visibility = Visibility.Visible; } //var neck = data.Joints[JointID.ShoulderCenter]; var neck = trackedSkels[0].Joints[JointType.ShoulderCenter]; MovetoJointPosition(cou, neck); //var leftHandJoint = data.Joints[JointID.HandLeft]; var leftHandJoint = trackedSkels[0].Joints[JointType.HandLeft]; MovetoJointPosition(leftHand, leftHandJoint); if (neck.Position.Z - leftHandJoint.Position.Z > 0.30f) // si la main est au moins a 36cm en avant des épaules. { leftHand.Fill = Brushes.White; LaserRay oldleftLaser = leftHand.Tag as LaserRay; var newleftlaser = FindLaserUnder(leftHand); if (newleftlaser != oldleftLaser) { if (oldleftLaser != null) { StopNoteFor((string)oldleftLaser.Tag); } if (newleftlaser != null) { PlayMidiNoteFor((string)newleftlaser.Tag); } } } else { LaserRay leftLaser = leftHand.Tag as LaserRay; if (leftLaser != null) { StopNoteFor((string)leftLaser.Tag); leftLaser.Untouched(); } leftHand.Fill = Brushes.Red; } //var rightHandJoint = data.Joints[JointID.HandRight]; var rightHandJoint = trackedSkels[0].Joints[JointType.HandRight]; MovetoJointPosition(rightHand, rightHandJoint); if (neck.Position.Z - rightHandJoint.Position.Z > 0.30f) // si la main est au moins a 36cm en avant des épaules { rightHand.Fill = Brushes.White; LaserRay oldrightLaser = rightHand.Tag as LaserRay; var newlaser = FindLaserUnder(rightHand); if (newlaser != oldrightLaser) { if (oldrightLaser != null) { StopNoteFor((string)oldrightLaser.Tag); } if (newlaser != null) { PlayMidiNoteFor((string)newlaser.Tag); } } } else { LaserRay rightLaser = rightHand.Tag as LaserRay; if (rightLaser != null) { StopNoteFor((string)rightLaser.Tag); rightLaser.Untouched(); } rightHand.Fill = Brushes.Red; } }
private void AllFramesReady(object sender, AllFramesReadyEventArgs allFramesReadyEventArgs) { ColorImageFrame colorImageFrame = null; DepthImageFrame depthImageFrame = null; SkeletonFrame skeletonFrame = null; try { colorImageFrame = allFramesReadyEventArgs.OpenColorImageFrame(); depthImageFrame = allFramesReadyEventArgs.OpenDepthImageFrame(); skeletonFrame = allFramesReadyEventArgs.OpenSkeletonFrame(); if (colorImageFrame == null || depthImageFrame == null || skeletonFrame == null) { return; } // Check for changes in any of the data this function is receiving // and reset things appropriately. if (this.depthImageFormat != depthImageFrame.Format) { this.DestroyFaceTracker(); this.depthImage = null; this.depthImageFormat = depthImageFrame.Format; } if (this.colorImageFormat != colorImageFrame.Format) { this.DestroyFaceTracker(); this.colorImage = null; this.colorImageFormat = colorImageFrame.Format; this.colorImageWritableBitmap = null; this.ColorImage.Source = null; this.theMaterial.Brush = null; } if (this.skeletonData != null && this.skeletonData.Length != skeletonFrame.SkeletonArrayLength) { this.skeletonData = null; } // Create any buffers to store copies of the data we work with if (this.depthImage == null) { this.depthImage = new short[depthImageFrame.PixelDataLength]; } if (this.colorImage == null) { this.colorImage = new byte[colorImageFrame.PixelDataLength]; } if (this.colorImageWritableBitmap == null) { this.colorImageWritableBitmap = new WriteableBitmap( colorImageFrame.Width, colorImageFrame.Height, 96, 96, PixelFormats.Bgr32, null); this.ColorImage.Source = this.colorImageWritableBitmap; this.theMaterial.Brush = new ImageBrush(this.colorImageWritableBitmap) { ViewportUnits = BrushMappingMode.Absolute }; } if (this.skeletonData == null) { this.skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength]; } // Copy data received in this event to our buffers. colorImageFrame.CopyPixelDataTo(this.colorImage); depthImageFrame.CopyPixelDataTo(this.depthImage); skeletonFrame.CopySkeletonDataTo(this.skeletonData); this.colorImageWritableBitmap.WritePixels( new Int32Rect(0, 0, colorImageFrame.Width, colorImageFrame.Height), this.colorImage, colorImageFrame.Width * Bgr32BytesPerPixel, 0); // Find a skeleton to track. // First see if our old one is good. // When a skeleton is in PositionOnly tracking state, don't pick a new one // as it may become fully tracked again. Skeleton skeletonOfInterest = this.skeletonData.FirstOrDefault( skeleton => skeleton.TrackingId == this.trackingId && skeleton.TrackingState != SkeletonTrackingState.NotTracked); if (skeletonOfInterest == null) { // Old one wasn't around. Find any skeleton that is being tracked and use it. skeletonOfInterest = this.skeletonData.FirstOrDefault( skeleton => skeleton.TrackingState == SkeletonTrackingState.Tracked); if (skeletonOfInterest != null) { // This may be a different person so reset the tracker which // could have tuned itself to the previous person. if (this.faceTracker != null) { this.faceTracker.ResetTracking(); } this.trackingId = skeletonOfInterest.TrackingId; } } if (skeletonOfInterest != null && skeletonOfInterest.TrackingState == SkeletonTrackingState.Tracked) { if (this.faceTracker == null) { try { this.faceTracker = new FaceTracker(this.Kinect); } catch (InvalidOperationException) { // During some shutdown scenarios the FaceTracker // is unable to be instantiated. Catch that exception // and don't track a face. Debug.WriteLine("AllFramesReady - creating a new FaceTracker threw an InvalidOperationException"); this.faceTracker = null; } } if (this.faceTracker != null) { FaceTrackFrame faceTrackFrame = this.faceTracker.Track( this.colorImageFormat, this.colorImage, this.depthImageFormat, this.depthImage, skeletonOfInterest); if (faceTrackFrame.TrackSuccessful) { if (!visited) { visited = true; //counter.Text = "60 seconds"; aTimer.Interval = 1000; aTimer.Tick += new EventHandler(aTimer_Tick); aTimer.Start(); } if (saveModel) { saveDepthImagebmp(depthImageFrame); saveColorImage(colorImageFrame.Width, colorImageFrame.Height, (colorImageFrame.Width * Bgr32BytesPerPixel)); saveFaceModel(); } } } } else { this.trackingId = -1; } } finally { if (colorImageFrame != null) { colorImageFrame.Dispose(); } if (depthImageFrame != null) { depthImageFrame.Dispose(); } if (skeletonFrame != null) { skeletonFrame.Dispose(); } } }
/// <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, SkeletonFrameReadyEventArgs e) { Skeleton[] skeletons = new Skeleton[0]; using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { if (skeletonFrame != null) { skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength]; skeletonFrame.CopySkeletonDataTo(skeletons); } } using (DrawingContext dc = this.drawingGroup.Open()) { //ImageSource imageSource = Image.("image1.jpg"); Rect rec = new Rect(0.0, 0.0, RenderWidth - 200, RenderHeight - 200); Joint joint1 = new Joint(); Joint joint2 = new Joint(); // Draw a transparent background to set the render size //dc.DrawImage(imageSource, rec); //dc.DrawRectangle(Brushes.Black, null, new Rect(0.0, 0.0, RenderWidth, RenderHeight)); // only to say the background has to be dark but actually it's not our case if (skeletons.Length != 0) { foreach (Skeleton skel in skeletons) { RenderClippedEdges(skel, dc); if (skel.TrackingState == SkeletonTrackingState.Tracked) { this.DrawBonesAndJoints(skel, dc); // draw the skeleton } else if (skel.TrackingState == SkeletonTrackingState.PositionOnly) // if the skeleton is seated { dc.DrawEllipse( this.centerPointBrush, null, this.SkeletonPointToScreen(skel.Position), BodyCenterThickness, BodyCenterThickness); } foreach (Joint joint in skel.Joints) { if (joint.JointType == JointType.HandLeft || joint.JointType == JointType.HandRight) { if (joint.JointType == JointType.HandLeft) { joint1 = joint; } } else { joint2 = joint; } if ((joint2.Position.X + 0.5f) < joint1.Position.X) { dc.DrawRectangle(Brushes.Brown, null, rec); } } } } // prevent drawing outside of our render area this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, RenderWidth, RenderHeight)); } }
private void Sensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { if (skeletonFrame != null && skeletonFrame.SkeletonArrayLength > 0) { if (skeletons == null || skeletons.Length != skeletonFrame.SkeletonArrayLength) { skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength]; } else { for (int i = 0; i < skeletons.Length; i++) { skeletons[i] = null; } } skeletonFrame.CopySkeletonDataTo(skeletons); int playerIndex = 0; Skeleton updatedSkeleton = null; if (this.trackedSkeleton != null) { for (int i = 0; i < skeletons.Length; i++) { if (skeletons[i].TrackingId == this.trackedSkeleton.TrackingId) { playerIndex = i; updatedSkeleton = skeletons[i]; break; } } } if (updatedSkeleton == null) { double closestX = 1; for (int i = 0; i < skeletons.Length; i++) { Skeleton newSkeleton = skeletons[i]; if (newSkeleton.TrackingState != SkeletonTrackingState.NotTracked && Math.Abs(newSkeleton.Position.X) < closestX) { playerIndex = i; updatedSkeleton = skeletons[i]; } } } this.trackedSkeleton = updatedSkeleton; if (updatedSkeleton != null && this.sensor != null) { // set the silhouette using (DepthImageFrame depthFrame = this.sensor.DepthStream.OpenNextFrame(15)) { this.GetPlayerSilhouette(depthFrame, playerIndex + 1); } if (this.trackedSkeletonTimer != null) { this.trackedSkeletonTimer.Stop(); this.trackedSkeletonTimer = null; } this.HasActiveSkeleton = true; this.SkeletonUpdated(updatedSkeleton); return; } } this.trackedSkeleton = null; this.Silhouette = null; if (this.trackedSkeletonTimer == null) { this.trackedSkeletonTimer = new Timer(2000); this.trackedSkeletonTimer.Elapsed += (o, s) => { this.HasActiveSkeleton = false; }; this.trackedSkeletonTimer.Start(); } } }
/// <summary> /// Event called when the kinect believes new skeletal data exits (Player moved). /// Event then collects data on wanted joints /// </summary> private void kinectSensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { //If the player is using the kinect controller if (isKinectController) { //Retrieve players SkeletonFrame frame = e.OpenSkeletonFrame(); if (frame == null) { return; } //Store joints from players Skeleton[] players = new Skeleton[frame.SkeletonArrayLength]; frame.CopySkeletonDataTo(players); //Grab the first player that is being tracked Skeleton firstPlayer = null; for (int i = 0; i < players.Length; ++i) { if (players[i].TrackingState == SkeletonTrackingState.Tracked || players[i].TrackingState == SkeletonTrackingState.PositionOnly) { firstPlayer = players[i]; } } //Dispose the non tracking frame if (firstPlayer == null) { Player.gameState = Player.States.noplayer; frame.Dispose(); return; } //If there was no player found in the game if (Player.gameState == Player.States.noplayer) { //Change the state to setup Player.gameState = Player.States.setup; } //Store the left and right joints for later scaling leftHand = firstPlayer.Joints[JointType.HandLeft]; rightHand = firstPlayer.Joints[JointType.HandRight]; //Remove previous points from Dictionary skeletonPoints.Clear(); //Map specific joints int joint = 0; for (int i = 0; i < 2; ++i) { //Update the left arm joint if (i == 0) { joint = 7; } //Update the right arm joint else { joint = 11; } //Retrienve the joint type JointType type = ((JointType[])Enum.GetValues(typeof(JointType)))[joint]; //Map the joint point on the ColorImage ColorImagePoint mappedPoints; mappedPoints = kinectSensor.CoordinateMapper.MapSkeletonPointToColorPoint(firstPlayer.Joints[type].Position, ColorImageFormat.RgbResolution640x480Fps30); //Add mapped Coordinate into dictionary skeletonPoints.Add(type, mappedPoints); } frame.Dispose(); } }
public void SetSkeletonFrame(SkeletonFrame extframe) { this.frame = extframe; return; }
public BodyFrame(SkeletonFrame skeletonFrame) { _skeletonFrame = skeletonFrame ?? throw new ArgumentNullException(nameof(skeletonFrame)); }
private void OnAllFramesReady(object sender, AllFramesReadyEventArgs allFramesReadyEventArgs) { ColorImageFrame colorImageFrame = null; DepthImageFrame depthImageFrame = null; SkeletonFrame skeletonFrame = null; try { colorImageFrame = allFramesReadyEventArgs.OpenColorImageFrame(); depthImageFrame = allFramesReadyEventArgs.OpenDepthImageFrame(); skeletonFrame = allFramesReadyEventArgs.OpenSkeletonFrame(); if (colorImageFrame == null || depthImageFrame == null || skeletonFrame == null) { return; } // Check for image format changes. The FaceTracker doesn't // deal with that so we need to reset. if (this.depthImageFormat != depthImageFrame.Format) { this.resetFaceTracking(); this.depthImage = null; this.depthImageFormat = depthImageFrame.Format; } if (this.colorImageFormat != colorImageFrame.Format) { this.resetFaceTracking(); this.colorImage = null; this.colorImageFormat = colorImageFrame.Format; } // Create any buffers to store copies of the data we work with if (this.depthImage == null) { this.depthImage = new short[depthImageFrame.PixelDataLength]; } if (this.colorImage == null) { this.colorImage = new byte[colorImageFrame.PixelDataLength]; } // Get the skeleton information if (this.skeletonData == null || this.skeletonData.Length != skeletonFrame.SkeletonArrayLength) { this.skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength]; } colorImageFrame.CopyPixelDataTo(this.colorImage); depthImageFrame.CopyPixelDataTo(this.depthImage); skeletonFrame.CopySkeletonDataTo(this.skeletonData); // Update the list of trackers and the trackers with the current frame information foreach (Skeleton skeleton in this.skeletonData) { if (skeleton.TrackingState == SkeletonTrackingState.Tracked || skeleton.TrackingState == SkeletonTrackingState.PositionOnly) { try { this.trackedSkeleton.OnFrameReady(this.Kinect, colorImageFormat, colorImage, depthImageFormat, depthImage, skeleton); } catch (NullReferenceException) { //se si perder il tracking del viso si evita un crash } this.trackedSkeleton.LastTrackedFrame = skeletonFrame.FrameNumber; } } this.InvalidateVisual(); } finally { if (colorImageFrame != null) { colorImageFrame.Dispose(); } if (depthImageFrame != null) { depthImageFrame.Dispose(); } if (skeletonFrame != null) { skeletonFrame.Dispose(); } } }
private List<Player> IdentifyPlayers(SkeletonFrame skeletonframe) { foreach (var data in skeletonframe.Skeletons) { if (SkeletonTrackingState.Tracked == data.TrackingState) { var data1 = data; var player = _players.FirstOrDefault(x => x.PlayerId == data1.TrackingID); if (player == null) { player = new Player(); player.PlayerId = data1.TrackingID; player.Name = "Player " + (_players.Count + 1); player.LastLeftHandXPosition = int.MaxValue; player.LastRightHandXPosition = int.MaxValue; _players.Add(player); } player.LeftHand = data.Joints[JointID.HandLeft]; player.LeftElbow = data.Joints[JointID.ElbowLeft]; player.RightHand = data.Joints[JointID.HandRight]; player.RightElbow = data.Joints[JointID.ElbowRight]; player.Head = data.Joints[JointID.Head]; } } return _players; }
void sensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { Joint Spine = new Joint(); Joint LeftFeet = new Joint(); Joint RightFeet = new Joint(); float delta = 0.00f; float leftFeetXPosition = 0.00f; float rightFeetXPosition = 0.00f; try { using (SkeletonFrame frame = e.OpenSkeletonFrame()) { if (frame != null) { frame.CopySkeletonDataTo(this._FrameSkeletons); Skeleton skeleton = GetPrimarySkeleton(this._FrameSkeletons); if (skeleton != null) { if (skeleton.TrackingState == SkeletonTrackingState.Tracked) { delta = 0.00f; Spine = skeleton.Joints[JointType.Spine]; LeftFeet = skeleton.Joints[JointType.FootLeft]; RightFeet = skeleton.Joints[JointType.FootRight]; leftFeetXPosition = LeftFeet.Position.X - delta; rightFeetXPosition = RightFeet.Position.X + delta; } else if (skeleton.TrackingState == SkeletonTrackingState.PositionOnly) { delta = 0.08f; LeftFeet.Position = skeleton.Position; RightFeet.Position = skeleton.Position; Spine.Position = skeleton.Position; leftFeetXPosition = LeftFeet.Position.X - delta; rightFeetXPosition = RightFeet.Position.X + delta; } if (skeleton.TrackingState == SkeletonTrackingState.Tracked || skeleton.TrackingState == SkeletonTrackingState.PositionOnly) { //Recognize Gestures either way //User being detected lastUserVisibleTime = DateTime.Now; if (Globals.currentAppState == RippleSystemStates.UserPlayingAnimations || Globals.currentAppState == RippleSystemStates.NoUser || Globals.currentAppState == RippleSystemStates.UserDetected) { //Run Mouse Interop #region Calibrated MouseInterop if ((LeftFeet.Position.Z > frontDistance && LeftFeet.Position.Z < backDistance) && (LeftFeet.Position.X > (leftDistance) && LeftFeet.Position.X < rightDistance)) { double CursorX = (((LeftFeet.Position.Z + RightFeet.Position.Z) / 2 - (frontDistance)) / (backDistance - frontDistance)) * Globals.CurrentResolution.HorizontalResolution; CursorX = Globals.CurrentResolution.HorizontalResolution - CursorX; double CursorY = (((LeftFeet.Position.X + RightFeet.Position.X) / 2 - (leftDistance)) / (rightDistance - leftDistance)) * Globals.CurrentResolution.VerticalResolution; int x = Convert.ToInt32(CursorX); int y = Convert.ToInt32(CursorY); Mouse.OverrideCursor = Cursors.None; //if (count == 0) //{ // RippleCommonUtilities.OSNativeMethods.SendMouseInput(x, y, (int)Globals.CurrentResolution.HorizontalResolution, (int)Globals.CurrentResolution.VerticalResolution, true); // count = 10; //} //count--; //RippleCommonUtilities.OSNativeMethods.SendMouseInput(x, y, (int)Globals.CurrentResolution.HorizontalResolution, (int)Globals.CurrentResolution.VerticalResolution, true); RippleCommonUtilities.OSNativeMethods.SendMouseInput(x, y, (int)Globals.CurrentResolution.HorizontalResolution, (int)Globals.CurrentResolution.VerticalResolution, false); } #endregion } //Run block identification only if not in above mode else { #region Calibrated Tile Detection bool locationChanged = false; for (int i = 0; i < tileCount; i++) { if ((LeftFeet.Position.Z > topTileBoundary[i] && LeftFeet.Position.Z < bottomTileBoundary[i]) && (RightFeet.Position.Z > topTileBoundary[i] && RightFeet.Position.Z < bottomTileBoundary[i]) && (leftFeetXPosition > (leftTileBoundary[i]) && leftFeetXPosition < rightTileBoundary[i]) && (rightFeetXPosition > (leftTileBoundary[i]) && rightFeetXPosition < rightTileBoundary[i])) { CurrentLocation = i; locationChanged = true; i = 0; break; } } if (locationChanged == false) { CurrentLocation = -1; } #endregion } } else { CurrentLocation = -1; } activeRecognizer.Recognize(sender, frame, this._FrameSkeletons); } else { CurrentLocation = -1; } } } } catch (Exception ex) { //Do nothing RippleCommonUtilities.LoggingHelper.LogTrace(1, "Went wrong in Kinect helper {0}", ex.Message); } }
//-------------------------------------------------------------------------------------- // Runs the enrollment state machine, called every frame //-------------------------------------------------------------------------------------- public void Update(GameTime Time) { if (Frame == null) return; TimeSinceLastFrame += Time.ElapsedGameTime; if (TimeSinceLastFrame.TotalSeconds > 3) //Been over a few seconds since we've recieved a valid skeleton frame clear alll { frame = null; ClearAllEnrollment(); return; } for (int I = 0; I < NumPlayers; ++I) { if (Players[I].SkeletonIndex == -1 || Frame.Skeletons[Players[I].SkeletonIndex].TrackingState == SkeletonTrackingState.Tracked) { switch (Players[I].State) { case PlayerEnrollmentState.NoSkeleton: FindSkeletonToEnroll(I); break; case PlayerEnrollmentState.NotInPosition: CheckForCenteredSkeleton(I); break; case PlayerEnrollmentState.WaitingForHandRaise: CheckForHandRaise(I); break; case PlayerEnrollmentState.Enrolled: break; default: break; } } else { Players[I].SkeletonIndex = -1; Players[I].State = PlayerEnrollmentState.NoSkeleton; } } }
private void SkeletonsReady(object sender, SkeletonFrameReadyEventArgs e) { using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { if (skeletonFrame != null) { int skeletonSlot = 0; if ((this.skeletonData == null) || (this.skeletonData.Length != skeletonFrame.SkeletonArrayLength)) { this.skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength]; } skeletonFrame.CopySkeletonDataTo(this.skeletonData); foreach (Skeleton skeleton in this.skeletonData) { if (SkeletonTrackingState.Tracked == skeleton.TrackingState) { Player player; if (this.players.ContainsKey(skeletonSlot)) { player = this.players[skeletonSlot]; } else { player = new Player(skeletonSlot); player.SetBounds(this.playerBounds); this.players.Add(skeletonSlot, player); } player.LastUpdated = DateTime.Now; // Update player's bone and joint positions if (skeleton.Joints.Count > 0) { player.IsAlive = true; // Head, hands, feet (hit testing happens in order here) player.UpdateJointPosition(skeleton.Joints, JointType.Head); player.UpdateJointPosition(skeleton.Joints, JointType.HandLeft); player.UpdateJointPosition(skeleton.Joints, JointType.HandRight); player.UpdateJointPosition(skeleton.Joints, JointType.FootLeft); player.UpdateJointPosition(skeleton.Joints, JointType.FootRight); // Hands and arms player.UpdateBonePosition(skeleton.Joints, JointType.HandRight, JointType.WristRight); player.UpdateBonePosition(skeleton.Joints, JointType.WristRight, JointType.ElbowRight); player.UpdateBonePosition(skeleton.Joints, JointType.ElbowRight, JointType.ShoulderRight); player.UpdateBonePosition(skeleton.Joints, JointType.HandLeft, JointType.WristLeft); player.UpdateBonePosition(skeleton.Joints, JointType.WristLeft, JointType.ElbowLeft); player.UpdateBonePosition(skeleton.Joints, JointType.ElbowLeft, JointType.ShoulderLeft); // Head and Shoulders player.UpdateBonePosition(skeleton.Joints, JointType.ShoulderCenter, JointType.Head); player.UpdateBonePosition(skeleton.Joints, JointType.ShoulderLeft, JointType.ShoulderCenter); player.UpdateBonePosition(skeleton.Joints, JointType.ShoulderCenter, JointType.ShoulderRight); // Legs player.UpdateBonePosition(skeleton.Joints, JointType.HipLeft, JointType.KneeLeft); player.UpdateBonePosition(skeleton.Joints, JointType.KneeLeft, JointType.AnkleLeft); player.UpdateBonePosition(skeleton.Joints, JointType.AnkleLeft, JointType.FootLeft); player.UpdateBonePosition(skeleton.Joints, JointType.HipRight, JointType.KneeRight); player.UpdateBonePosition(skeleton.Joints, JointType.KneeRight, JointType.AnkleRight); player.UpdateBonePosition(skeleton.Joints, JointType.AnkleRight, JointType.FootRight); player.UpdateBonePosition(skeleton.Joints, JointType.HipLeft, JointType.HipCenter); player.UpdateBonePosition(skeleton.Joints, JointType.HipCenter, JointType.HipRight); // Spine player.UpdateBonePosition(skeleton.Joints, JointType.HipCenter, JointType.ShoulderCenter); } } skeletonSlot++; } } } }
public void MatchFrame(SkeletonFrame frame) { foreach (SkeletonData skeleton in frame.Skeletons) { if (skeleton.TrackingState != SkeletonTrackingState.Tracked) { continue; } Point handPosition = null; switch (hand) { case GestureHandType.LeftHand: handPosition = new Point(skeleton.Joints[JointID.HandLeft].Position); break; case GestureHandType.RightHand: handPosition = new Point(skeleton.Joints[JointID.HandRight].Position); break; } // special case: first frame if (framesMatched == 0) { Reset(handPosition); return; } bool primaryConditionMet = false; switch (direction) { case SingleHandedSwipeGestureDirectionType.BottomToTop: primaryConditionMet = handPosition.Y > previous.Y; break; case SingleHandedSwipeGestureDirectionType.TopToBottom: primaryConditionMet = handPosition.Y < previous.Y; break; case SingleHandedSwipeGestureDirectionType.LeftToRight: primaryConditionMet = handPosition.X > previous.X; break; case SingleHandedSwipeGestureDirectionType.RightToLeft: primaryConditionMet = handPosition.X < previous.X; break; } if (!primaryConditionMet) { Reset(handPosition); return; } bool varianceConditionMet = false; switch (direction) { case SingleHandedSwipeGestureDirectionType.BottomToTop: case SingleHandedSwipeGestureDirectionType.TopToBottom: varianceConditionMet = Math.Abs(handPosition.X - initial.X) < SECONDARY_AXES_VARIANCE_THRESHOLD; break; case SingleHandedSwipeGestureDirectionType.LeftToRight: case SingleHandedSwipeGestureDirectionType.RightToLeft: varianceConditionMet = Math.Abs(handPosition.Y - initial.Y) < SECONDARY_AXES_VARIANCE_THRESHOLD; break; } varianceConditionMet = varianceConditionMet && Math.Abs(handPosition.Z - initial.Z) < SECONDARY_AXES_VARIANCE_THRESHOLD; if (!varianceConditionMet) { Reset(handPosition); return; } if (framesMatched > FRAMES_THRESHOLD) { // We have already fired an event for this gesture previous = handPosition; framesMatched++; return; } else if (framesMatched < FRAMES_THRESHOLD) { if (handPosition.DistaceFrom(initial) > PRIMARY_AXIS_MAX_DISTANCE_THRESHOLD) { Reset(handPosition); return; } previous = handPosition; framesMatched++; return; } else if (framesMatched == FRAMES_THRESHOLD) { float dist = handPosition.DistaceFrom(initial); if (dist > PRIMARY_AXIS_MIN_DISTANCE_THRESHOLD && dist < PRIMARY_AXIS_MAX_DISTANCE_THRESHOLD) { previous = handPosition; framesMatched++; if (GestureRecognized != null) { SingleHandedSwipeGesture result = new SingleHandedSwipeGesture(hand, direction, 1.0, initial, previous); GestureRecognized(this, new GestureRecognizedEventArgs(result)); } return; } else { Reset(handPosition); return; } } } // We reach here if there are no tracked skeleton Reset(null); }
/// <summary> /// Handles the AllFramesReady event of the kinectSensor control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="Microsoft.Kinect.AllFramesReadyEventArgs"/> instance containing the event data.</param> void kinectSensor_AllFramesReady(object sender, AllFramesReadyEventArgs e) { // Retrieve each single frame and copy the data using (ColorImageFrame colorImageFrame = e.OpenColorImageFrame()) { if (colorImageFrame == null) { return; } colorImageFrame.CopyPixelDataTo(colorPixelData); } using (DepthImageFrame depthImageFrame = e.OpenDepthImageFrame()) { if (depthImageFrame == null) { return; } depthImageFrame.CopyPixelDataTo(depthPixelData); } using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { if (skeletonFrame == null) { return; } skeletonFrame.CopySkeletonDataTo(skeletonData); } // Retrieve the first tracked skeleton if any. Otherwise, do nothing. var skeleton = skeletonData.FirstOrDefault(s => s.TrackingState == SkeletonTrackingState.Tracked); if (skeleton == null) { return; } // Make the faceTracker processing the data. FaceTrackFrame faceFrame = faceTracker.Track(kinectSensor.ColorStream.Format, colorPixelData, kinectSensor.DepthStream.Format, depthPixelData, skeleton); // If a face is tracked, then we can use it. if (faceFrame.TrackSuccessful) { var triangles = faceFrame.GetTriangles(); // Retrieve only the Animation Units coeffs. var AUCoeff = faceFrame.GetAnimationUnitCoefficients(); var jawLowerer = AUCoeff[AnimationUnit.JawLower]; jawLowerer = jawLowerer < 0 ? 0 : jawLowerer; MouthScaleTransform.ScaleY = jawLowerer * 5 + 0.1; MouthScaleTransform.ScaleX = (AUCoeff[AnimationUnit.LipStretcher] + 1); LeftBrow.Y = RightBrow.Y = (AUCoeff[AnimationUnit.BrowLower]) * 40; RightBrowRotate.Angle = (AUCoeff[AnimationUnit.BrowRaiser] * 20); LeftBrowRotate.Angle = -RightBrowRotate.Angle; CanvasRotate.Angle = -faceFrame.Rotation.Z; // CanvasTranslate.X = faceFrame.Translation.X; // CanvasTranslate.Y = faceFrame.Translation.Y; if (logToFile) { writeToFile(filename_txt.Text, faceFrame); } if (writeToOSC) { sendOsc(osc_channel_txt.Text, faceFrame, oscWriter); } } }
private bool AreHandsClose(SkeletonFrame frame) { bool areHandsclose = false; SkeletonFrame currentFrame = frame; foreach (SkeletonData data in currentFrame.Skeletons) { if (SkeletonTrackingState.Tracked == data.TrackingState) { Joint rightHandJoint = data.Joints[JointID.WristRight]; Joint leftHandJoint = data.Joints[JointID.WristLeft]; double handdiffx = rightHandJoint.Position.X - leftHandJoint.Position.X; double handdiffy = rightHandJoint.Position.Y - leftHandJoint.Position.Y; double handpointsdiff = Math.Sqrt((handdiffx * handdiffx) + (handdiffy * handdiffy)); if (handpointsdiff < 0.05) { areHandsclose = true; break; } } } return areHandsclose; }
void Kinect_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { string sMensaje = "No hay datos de esqueleto"; string sMensajeCaptura = ""; Skeleton[] Skeletons = null; using (SkeletonFrame framesEsqueleto = e.OpenSkeletonFrame()) { if (framesEsqueleto != null) { Skeletons = new Skeleton[framesEsqueleto.SkeletonArrayLength]; framesEsqueleto.CopySkeletonDataTo(Skeletons); } } if (Skeletons == null) { return; } foreach (Skeleton esqueleto in Skeletons) { if (esqueleto.TrackingState == SkeletonTrackingState.Tracked) { if (esqueleto.ClippedEdges == 0) { sMensajeCaptura = "Colocado Perfectamente"; } else { if ((esqueleto.ClippedEdges & FrameEdges.Bottom) != 0) { sMensajeCaptura += "Moverse mas arriba"; } if ((esqueleto.ClippedEdges & FrameEdges.Top) != 0) { sMensajeCaptura += "Moverse mas abajo"; } if ((esqueleto.ClippedEdges & FrameEdges.Right) != 0) { sMensajeCaptura += "Moverse mas a la izquierda"; } if ((esqueleto.ClippedEdges & FrameEdges.Left) != 0) { sMensajeCaptura += "Moverse mas a la derecha"; } } Joint jointRH = esqueleto.Joints[JointType.HandRight]; Joint jointLH = esqueleto.Joints[JointType.HandLeft]; Joint jointRW = esqueleto.Joints[JointType.WristRight]; SkeletonPoint posRH = jointRH.Position; SkeletonPoint posLH = jointLH.Position; SkeletonPoint posRW = jointRW.Position; sMensaje = string.Format("Right Hand: X:{0:0.0} Y:{1:0.0} Z:{2:0.0} \n" + "Left Hand: X:{3:0.0} Y:{4:0.0} Z:{5:0.0} \n" + "Right Wrist: X:{6:0.0.0} Y:{7:0.0.0} Z:{8:0.0.0}", posRH.X, posRH.Y, posRH.Z, posLH.X, posLH.Y, posLH.Z, posRW.X, posRW.Y, posRW.Z ); sKLH = posLH; sKRH = posRH; } } ControlerLeft(sKLH); if (sKRH.Y > 0 && iNum > 10) { InputSimulator.SimulateKeyDown(VirtualKeyCode.SPACE); } skAux = sKLH; iNum++; SkeletonEstatus.Text = sMensaje; SkeletonCapture.Text = sMensajeCaptura; }
public Dictionary<JointID, Vector> TransformSkeleton(SkeletonFrame frame) { SkeletonData latestSkeleton = (from skeletons in frame.Skeletons where skeletons.TrackingState == SkeletonTrackingState.Tracked select skeletons).FirstOrDefault(); float theta = CalculateTheta(latestSkeleton.Joints[JointID.ShoulderRight].Position.X, latestSkeleton.Joints[JointID.ShoulderRight].Position.Y, latestSkeleton.Joints[JointID.ShoulderRight].Position.Z, latestSkeleton.Joints[JointID.ShoulderLeft].Position.X, latestSkeleton.Joints[JointID.ShoulderLeft].Position.Y, latestSkeleton.Joints[JointID.ShoulderLeft].Position.Z); kinectEventLogger.Debug("theta = " + theta); foreach (Joint newJoint in latestSkeleton.Joints) { glbTransformedSkeleton.jointsDictionary[glbTransformedSkeleton.jointsDictionary.Keys.First(v => v.Equals(newJoint.ID))] = newJoint.Position; } Vector translate = latestSkeleton.Joints[JointID.HipCenter].Position; Dictionary<JointID, Vector>.KeyCollection allKeys = this.glbTransformedSkeleton.jointsDictionary.Keys; int keyCount = allKeys.Count; for (int i = 0; i < keyCount; i++) { Vector newVector = new Vector(); kinectEventLogger.Debug("Before translate.X = " + translate.X); kinectEventLogger.Debug("Before translate.Y = " + translate.Y); kinectEventLogger.Debug("Before translate.Z = " + translate.Z); //Translate to origin newVector.X = this.glbTransformedSkeleton.jointsDictionary[allKeys.ToArray()[i]].X - translate.X; newVector.Y = this.glbTransformedSkeleton.jointsDictionary[allKeys.ToArray()[i]].Y - translate.Y; newVector.Z = this.glbTransformedSkeleton.jointsDictionary[allKeys.ToArray()[i]].Z - translate.Z; kinectEventLogger.Debug("Before this.glbTransformedSkeleton.jointsDictionary[allKeys.ToArray()[i]].X = " + this.glbTransformedSkeleton.jointsDictionary[allKeys.ToArray()[i]].X); kinectEventLogger.Debug("Before this.glbTransformedSkeleton.jointsDictionary[allKeys.ToArray()[i]].Y = " + this.glbTransformedSkeleton.jointsDictionary[allKeys.ToArray()[i]].Y); kinectEventLogger.Debug("Before this.glbTransformedSkeleton.jointsDictionary[allKeys.ToArray()[i]].Z = " + this.glbTransformedSkeleton.jointsDictionary[allKeys.ToArray()[i]].Z); kinectEventLogger.Debug("Before newVector.X = " + newVector.X); kinectEventLogger.Debug("Before newVector.Y = " + newVector.Y); kinectEventLogger.Debug("Before newVector.Z = " + newVector.Z); ////rotate at origin along y newVector.X = newVector.X * (float)Math.Cos(theta) + newVector.Z * (float)Math.Sin(theta); newVector.Z = -newVector.X * (float)Math.Sin(theta) + newVector.Z * (float)Math.Cos(theta); kinectEventLogger.Debug("After translate.X = " + translate.X); kinectEventLogger.Debug("After translate.Y = " + translate.Y); kinectEventLogger.Debug("After translate.Z = " + translate.Z); //Translate back newVector.X = newVector.X + translate.X; newVector.Y = newVector.Y + translate.Y; newVector.Z = newVector.Z + translate.Z; kinectEventLogger.Debug("After this.glbTransformedSkeleton.jointsDictionary[allKeys.ToArray()[i]].X = " + this.glbTransformedSkeleton.jointsDictionary[allKeys.ToArray()[i]].X); kinectEventLogger.Debug("After this.glbTransformedSkeleton.jointsDictionary[allKeys.ToArray()[i]].Y = " + this.glbTransformedSkeleton.jointsDictionary[allKeys.ToArray()[i]].Y); kinectEventLogger.Debug("After this.glbTransformedSkeleton.jointsDictionary[allKeys.ToArray()[i]].Z = " + this.glbTransformedSkeleton.jointsDictionary[allKeys.ToArray()[i]].Z); kinectEventLogger.Debug("After newVector.X = " + newVector.X); kinectEventLogger.Debug("After newVector.Y = " + newVector.Y); kinectEventLogger.Debug("After newVector.Z = " + newVector.Z); //Store the transformed points in global glbTransformedSkeleton.jointsDictionary[allKeys.ToArray()[i]] = newVector; } return glbTransformedSkeleton.jointsDictionary; }
public override void AddFrame(SkeletonFrame frame) { }
public void nui_SkeletonFrameReady(SkeletonFrame skeletonFrame, Canvas skeleton, Runtime nui) { int iSkeleton = 0; Brush[] brushes = new Brush[6]; brushes[0] = new SolidColorBrush(Color.FromRgb(255, 0, 0)); brushes[1] = new SolidColorBrush(Color.FromRgb(0, 255, 0)); brushes[2] = new SolidColorBrush(Color.FromRgb(64, 255, 255)); brushes[3] = new SolidColorBrush(Color.FromRgb(255, 255, 64)); brushes[4] = new SolidColorBrush(Color.FromRgb(255, 64, 255)); brushes[5] = new SolidColorBrush(Color.FromRgb(128, 128, 255)); skeleton.Children.Clear(); foreach (SkeletonData data in skeletonFrame.Skeletons) { if (SkeletonTrackingState.Tracked == data.TrackingState) { // Draw bones Brush brush = brushes[iSkeleton % brushes.Length]; skeleton.Children.Add(getBodySegment(nui, skeleton, data.Joints, brush, JointID.HipCenter, JointID.Spine, JointID.ShoulderCenter, JointID.Head)); skeleton.Children.Add(getBodySegment(nui, skeleton, data.Joints, brush, JointID.ShoulderCenter, JointID.ShoulderLeft, JointID.ElbowLeft, JointID.WristLeft, JointID.HandLeft)); skeleton.Children.Add(getBodySegment(nui, skeleton, data.Joints, brush, JointID.ShoulderCenter, JointID.ShoulderRight, JointID.ElbowRight, JointID.WristRight, JointID.HandRight)); skeleton.Children.Add(getBodySegment(nui, skeleton, data.Joints, brush, JointID.HipCenter, JointID.HipLeft, JointID.KneeLeft, JointID.AnkleLeft, JointID.FootLeft)); skeleton.Children.Add(getBodySegment(nui, skeleton, data.Joints, brush, JointID.HipCenter, JointID.HipRight, JointID.KneeRight, JointID.AnkleRight, JointID.FootRight)); // Draw joints foreach (Joint joint in data.Joints) { Point jointPos = Geometrics.getDisplayPosition(joint, nui, skeleton); Line jointLine = new Line(); jointLine.X1 = jointPos.X - 3; jointLine.X2 = jointLine.X1 + 6; jointLine.Y1 = jointLine.Y2 = jointPos.Y; jointLine.Stroke = jointColors[joint.ID]; jointLine.StrokeThickness = 6; skeleton.Children.Add(jointLine); } } iSkeleton++; } // for each skeleton }
private void KSensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { userPanel.Children.Clear(); Skeleton[] skeletons = null; //copy skeleton data to skeleton array using (SkeletonFrame skeletonframe = e.OpenSkeletonFrame()) { if (skeletonframe != null) { skeletons = new Skeleton[skeletonframe.SkeletonArrayLength]; skeletonframe.CopySkeletonDataTo(skeletons); } } //if no skeleton data if (skeletons == null) { return; } //for each skeleton foreach (Skeleton skeleton in skeletons) { //if skeleton is tracked if (skeleton.TrackingState == SkeletonTrackingState.Tracked) { //Using drawbone function only when implement framelb.Content = "Recording.."; DrawBone(skeleton, JointType.Head, JointType.ShoulderCenter); DrawBone(skeleton, JointType.ShoulderCenter, JointType.Spine); DrawBone(skeleton, JointType.Spine, JointType.HipCenter); //left arm DrawBone(skeleton, JointType.ShoulderCenter, JointType.ShoulderLeft); DrawBone(skeleton, JointType.ShoulderLeft, JointType.ElbowLeft); DrawBone(skeleton, JointType.ElbowLeft, JointType.WristLeft); DrawBone(skeleton, JointType.WristLeft, JointType.HandLeft); //right arm DrawBone(skeleton, JointType.ShoulderCenter, JointType.ShoulderRight); DrawBone(skeleton, JointType.ShoulderRight, JointType.ElbowRight); DrawBone(skeleton, JointType.ElbowRight, JointType.WristRight); DrawBone(skeleton, JointType.WristRight, JointType.HandRight); //left leg DrawBone(skeleton, JointType.HipCenter, JointType.HipLeft); DrawBone(skeleton, JointType.HipLeft, JointType.KneeLeft); DrawBone(skeleton, JointType.KneeLeft, JointType.AnkleLeft); DrawBone(skeleton, JointType.AnkleLeft, JointType.FootLeft); //Right leg DrawBone(skeleton, JointType.HipCenter, JointType.HipRight); DrawBone(skeleton, JointType.HipRight, JointType.KneeRight); DrawBone(skeleton, JointType.KneeRight, JointType.AnkleRight); DrawBone(skeleton, JointType.AnkleRight, JointType.FootRight); skel = skeleton; //motion.Add(new BodyJoint(skel, count)); if (type == "Motion") { try { img = new Image <Bgr, byte>(ImageSourceToBitmap((BitmapSource)userImage.Source)); videoWriter.Write(img.Mat); } catch (Exception) { } } count++; Console.Write(count + ". X: " + skeleton.Joints[JointType.HipCenter].Position.X); Console.Write(" Y: " + skeleton.Joints[JointType.HipCenter].Position.Y); Console.Write(" Z: " + skeleton.Joints[JointType.HipCenter].Position.Z); Console.WriteLine(" "); } } }
public void Render(Panel skeleton, Runtime tr, SkeletonFrame skeletonFrame, Brush[] brushes) { int iSkeleton = 0; skeleton.Children.Clear(); foreach (SkeletonData data in skeletonFrame.Skeletons) { if (SkeletonTrackingState.Tracked == data.TrackingState) { // Draw bones Brush brush = brushes[iSkeleton % brushes.Length]; Render(skeleton, tr, data, brush); } iSkeleton++; } // for each skeleton }
public KinectSkeletonFrame(SkeletonFrame frame) { _frame = frame; }
public void UpdateSkeleton(SkeletonFrame SK) { if (timer > 0) timer -= 200; gSkeletonFrame = SK; gCurSkeleton = (from s in gSkeletonFrame.Skeletons where s.TrackingState == SkeletonTrackingState.Tracked select s).FirstOrDefault(); }
private void Sensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { Skeleton[] skeletons = new Skeleton[0]; //fpsTextBlock.Text = myNumberOfFrames.ToString(); if (myFrameTimers.Count > 0) { fpsTextBlock.Text = ""; foreach (int tempCounter in myFrameTimers) { fpsTextBlock.Text += "Skel. " + mySkeletonIDs[myFrameTimers.IndexOf(tempCounter)].ToString() + ": " + tempCounter.ToString() + "\n"; Console.Write("Skel. " + mySkeletonIDs[myFrameTimers.IndexOf(tempCounter)].ToString() + ": " + tempCounter.ToString() + " | "); } Console.WriteLine(); } using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { if (skeletonFrame != null) { skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength]; skeletonFrame.CopySkeletonDataTo(skeletons); } } if (skeletons.Length != 0) { foreach (Skeleton skel in skeletons) { if (skel.TrackingState == SkeletonTrackingState.Tracked || skel.TrackingState == SkeletonTrackingState.Tracked) { Console.WriteLine("Z: " + skel.Position.Z); if (skel.Position.Z <= 3.0) { if (mySkeletonIDs.IndexOf(skel.TrackingId) == -1) { //myNumberOfFrames = 0; //fireFlag = true; mySkeletonIDs.Add(skel.TrackingId); myFrameTimers.Insert(mySkeletonIDs.IndexOf(skel.TrackingId), 0); myFlags.Insert(mySkeletonIDs.IndexOf(skel.TrackingId), true); Console.WriteLine("Skeleton ID: " + skel.TrackingId.ToString()); noOfSkeletons++; } else { //myNumberOfFrames++; //if((myNumberOfFrames >= 300) && (fireFlag==true)) int tempTimer = (int)myFrameTimers[mySkeletonIDs.IndexOf(skel.TrackingId)]; tempTimer++; myFrameTimers[mySkeletonIDs.IndexOf(skel.TrackingId)] = tempTimer; if ((tempTimer >= 300) && ((Boolean)myFlags[mySkeletonIDs.IndexOf(skel.TrackingId)] == true)) { interestedSkeleton(mySkeletonIDs.IndexOf(skel.TrackingId)); } } } //counterTextBlock.Text = noOfSkeletons.ToString(); } } } counterTextBlock.Text = "Total People: " + noOfSkeletons.ToString() + " | Interested People: " + noOfInterestedPeople.ToString(); }
/// <summary> /// Event handler for Kinect sensor's DepthFrameReady event /// </summary> /// <param name="sender">object sending the event</param> /// <param name="e">event arguments</param> private void SensorAllFramesReady(object sender, AllFramesReadyEventArgs e) { // in the middle of shutting down, so nothing to do if (null == this.sensor) { return; } bool depthReceived = false; bool colorReceived = false; using (DepthImageFrame depthFrame = e.OpenDepthImageFrame()) { if (null != depthFrame) { // Copy the pixel data from the image to a temporary array depthFrame.CopyDepthImagePixelDataTo(this.depthPixels); depthReceived = true; } } Skeleton[] skeletons = new Skeleton[0]; using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { if (skeletonFrame != null) { skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength]; skeletonFrame.CopySkeletonDataTo(skeletons); } } using (DrawingContext dc = this.drawingGroup.Open()) { // Draw a transparent background to set the render size dc.DrawRectangle(Brushes.Transparent, null, new Rect(0.0, 0.0, RenderWidth, RenderHeight)); if (skeletons.Length != 0) { foreach (Skeleton skel in skeletons) { if (skel.TrackingState == SkeletonTrackingState.Tracked) { this.seleccion_sonido(skel); } else if (skel.TrackingState == SkeletonTrackingState.PositionOnly) { dc.DrawEllipse( this.centerPointBrush, null, this.SkeletonPointToScreen(skel.Position), BodyCenterThickness, BodyCenterThickness); } } } // prevent drawing outside of our render area this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, RenderWidth, RenderHeight)); } //Llamamos a la función que controla los estados por los que hay que pasar detectar_estado(skeletons); using (ColorImageFrame colorFrame = e.OpenColorImageFrame()) { if (null != colorFrame) { // Copy the pixel data from the image to a temporary array colorFrame.CopyPixelDataTo(this.colorPixels); colorReceived = true; } } // do our processing outside of the using block // so that we return resources to the kinect as soon as possible if (true == depthReceived) { this.sensor.CoordinateMapper.MapDepthFrameToColorFrame( DepthFormat, this.depthPixels, ColorFormat, this.colorCoordinates); Array.Clear(this.playerPixelData, 0, this.playerPixelData.Length); // loop over each row and column of the depth for (int y = 0; y < this.depthHeight; ++y) { for (int x = 0; x < this.depthWidth; ++x) { // calculate index into depth array int depthIndex = x + (y * this.depthWidth); DepthImagePixel depthPixel = this.depthPixels[depthIndex]; int player = depthPixel.PlayerIndex; // if we're tracking a player for the current pixel, sets it opacity to full if (player > 0) { // retrieve the depth to color mapping for the current depth pixel ColorImagePoint colorImagePoint = this.colorCoordinates[depthIndex]; // scale color coordinates to depth resolution int colorInDepthX = colorImagePoint.X / this.colorToDepthDivisor; int colorInDepthY = colorImagePoint.Y / this.colorToDepthDivisor; // make sure the depth pixel maps to a valid point in color space // check y > 0 and y < depthHeight to make sure we don't write outside of the array // check x > 0 instead of >= 0 since to fill gaps we set opaque current pixel plus the one to the left // because of how the sensor works it is more correct to do it this way than to set to the right if (colorInDepthX > 0 && colorInDepthX < this.depthWidth && colorInDepthY >= 0 && colorInDepthY < this.depthHeight) { // calculate index into the player mask pixel array int playerPixelIndex = colorInDepthX + (colorInDepthY * this.depthWidth); // set opaque this.playerPixelData[playerPixelIndex] = opaquePixelValue; // compensate for depth/color not corresponding exactly by setting the pixel // to the left to opaque as well this.playerPixelData[playerPixelIndex - 1] = opaquePixelValue; } } } } } // do our processing outside of the using block // so that we return resources to the kinect as soon as possible if (true == colorReceived) { // Write the pixel data into our bitmap this.colorBitmap.WritePixels( new Int32Rect(0, 0, this.colorBitmap.PixelWidth, this.colorBitmap.PixelHeight), this.colorPixels, this.colorBitmap.PixelWidth * sizeof(int), 0); if (this.playerOpacityMaskImage == null) { this.playerOpacityMaskImage = new WriteableBitmap( this.depthWidth, this.depthHeight, 96, 96, PixelFormats.Bgra32, null); MaskedColor.OpacityMask = new ImageBrush { ImageSource = this.playerOpacityMaskImage }; } this.playerOpacityMaskImage.WritePixels( new Int32Rect(0, 0, this.depthWidth, this.depthHeight), this.playerPixelData, this.depthWidth * ((this.playerOpacityMaskImage.Format.BitsPerPixel + 7) / 8), 0); } }
public override void AddFrame(SkeletonFrame frame) { if (frame != null && !frame.IsEmpty) { writeableBlock.Add(this.FrameToMasterDetail(frame)); if (writeableBlock.Count == BlockBufferSize) { engine.WriteStream(writer, writeableBlock.ToArray()); writeableBlock.Clear(); } } }