Search code examples
c#kinect-sdk

How to calculate the difference of pitch and yaw anlges in two adjacent frames


I am using FaceTracking application from kinect for Windows SDK samples. I have read that head pose angles will help to detect head movement(Head nod or head shake). At the Moment, i have values of head pose angles. My question is how to calculate the difference of head pose angles? I know that I Need the values of previous Frame. I really dont know how store the values of previous Frame and use it for further Analysis. Does anyone has idea on this Topic? Looking Forward for your suggestions.

Thank you so much in advance.

Edit: I have tried one Approach to store the previous Frame and Display the difference between the angles. But my Frame is not updating and i am not getting expected difference between the angles. I have taken below code from facetracking application. Could some please tell me where am i doing wrong?

internal void OnFrameReady(KinectSensor kinectSensor, ColorImageFormat colorImageFormat, byte[] colorImage, DepthImageFormat depthImageFormat, short[] depthImage, Skeleton skeletonOfInterest)
        {
            this.skeletonTrackingState = skeletonOfInterest.TrackingState;

            if (this.skeletonTrackingState != SkeletonTrackingState.Tracked)
            {
                // nothing to do with an untracked skeleton.
                return;
            }

            if (this.faceTracker == null)
            {
                try
                {
                    this.faceTracker = new FaceTracker(kinectSensor);
                }
                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    frame = this.faceTracker.Track(
                    colorImageFormat, colorImage, depthImageFormat, depthImage, skeletonOfInterest);
                this.lastFaceTrackSucceeded = frame.TrackSuccessful;

                if (this.lastFaceTrackSucceeded)
                {
                /*
                   pitch = frame.Rotation.X;
                yaw = frame.Rotation.Y;
                    roll  = frame.Rotation.Z;*/
                     Vector3DF faceRotation = frame.Rotation;
                     pose = string.Format("Pitch:\t{0:+00;-00}°\nYaw:\t{1:+00;-00}°\nRoll:\t{2:+00;-00}°", faceRotation.X, faceRotation.Y, faceRotation.Z);
                     if (oldFrame != null)
                     {
                         Vector3DF faceRotation1 = oldFrame.Rotation;
                         difference = string.Format("Pitch:\t{0:+00;-00}°\nYaw:\t{1:+00;-00}°\nRoll:\t{2:+00;-00}°", faceRotation.X - faceRotation1.X, faceRotation.Y - faceRotation1.Y, faceRotation.Z-faceRotation1.Z);
                     }
                    if (faceTriangles == null)
                    {
                        // only need to get this once.  It doesn't change.
                        faceTriangles = frame.GetTriangles();
                    }

                    this.facePoints = frame.GetProjected3DShape();
                   }

            }
            oldFrame = frame; // FaceTrackFrame oldFrame;

        }

Solution

  • I have made chnages to the following line to copy the current Frame to other Frame object. I have used the clone method.

     oldFrame = (FaceTrackFrame)frame.Clone();
    

    Now it is giving me the correct difference