I am writing a Kinect-based application. I need to implement a wave-right gesture. I found a code snippet from the Internet using C#, but I have some doubts about this code. Can you help me?
The code:
public class KinectClass
{
public void KinectInitialize ()
{
m_myKinect.Start();
m_myKinect.SkeletonStream.TrackingMode = SkeletonTrackingMode.Seated;
m_myKinect.SkeletonFrameReady += m_myKinect_SkeletonFrameReady;
}
void m_myKinect_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
{
using (SkeletonFrame frame = e.OpenSkeletonFrame())
{
if (frame != null)
{
if (0 == frame.SkeletonArrayLength) return;
m_skeletons = new Skeleton[frame.SkeletonArrayLength];
if (m_skeletons == null) return;
frame.CopySkeletonDataTo(m_skeletons);
}
}
foreach (Skeleton skeleton in m_skeletons)
{
if (skeleton.TrackingState == SkeletonTrackingState.Tracked)
{
UpdateSkeletonHistory(skeleton);
value = gestureobject.Detectgesture();
}
}
}
}
In addition, there is a Gesture class which is checking wave functions:
class Gesture
{
private List<Skeleton> SkeletonHistory;
private List<Skeleton> localSkeletonHistory;
public void UpdateSkeletonHistory(Skeleton SkeletonData)
{
SkeletonHistory.Add(SkeletonData);
if (SkeletonHistory.Count > 90)
{
SkeletonHistory.RemoveAt(0);
}
return ;
}
public short Detectgesture()
{
short sReturnvalue = -1;
int gesturePeriod = 2;
int indexesPerSecond = 30;
int indexesToCheck = gesturePeriod * indexesPerSecond;
localSkeletonHistory = new List<Skeleton>(SkeletonHistory);
if (m_SkeletonHistory.Count > indexesToCheck)
{
localSkeletonHistory = new List<Skeleton>(m_SkeletonHistory);
if( waveright() )
{
Console.Writeline("waveright");
}
}
}
private bool waveright()
{
Console.WriteLine("wave right START");
bool Movedright = false,
Movedleft = false;
float refDistance = 0.2F;
float startPos = localSkeletonHistory[0].Joints[JointType.HandLeft].Position.X;
for (int i = 0; i < localSkeletonHistory.Count; i++)
{
if (!(localSkeletonHistory[i].Joints[JointType.HandLeft].Position.Y <= localSkeletonHistory[i].Joints[JointType.Head].Position.Y))
{
break;
}
if (localSkeletonHistory[i].Joints[JointType.HandLeft].Position.X >= (startPos + refDistance))
{
Movedright = true;
}
if (Movedright && Math.Abs(localSkeletonHistory[i].Joints[JointType.HandLeft].Position.X - startPos) <= 0.1 )
{
Movedleft = true;
m_SkeletonHistory.Clear();
break;
}
}
return Movedleft;
}
}
I can understand Kinect functions, but I am confused about the gesture functions. My questions are as follows:
- Why do they create a SkeletonHistory?
- What is the need for gesturePeriod and indexesPerSecond?
- Why do they check if (m_SkeletonHistory.Count > indexesToCheck)?
- Can you explain the waveright function?