sk8ergirl 0 Newbie Poster

I'm learning kinect development in my free time and I've read some books and other webiste and what I'm trying to do is gestures recognition for left swipe , right swipe , hand clapping , clockwise circle with left hand , anticlockwise with left hand I've successfully did the hand clapping I want everything to be in one class which is GestureRecognitionEngine I wrote some code for the left swipe gesture but I'm not sure how to implement it in the correct way here is what I did so far

This is my GestureRecognitionEngine.cs which contain all gestures

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Kinect; 

namespace GestureRecognizer
{
    public class GestureRecognitionEngine
    {
        public GestureRecognitionEngine()
        {
        }
        public event EventHandler<GestureEventArg> GestureRecognized;
        public GestureType GestureType { get; set; }
        public Skeleton Skeleton { get; set; }
        private void InitilizeGesture()
        {
        }

        public static float GetJointDistance(Joint firstJoint, Joint secondJoint)
        {

            float distanceX = firstJoint.Position.X - secondJoint.
            Position.X;
            float distanceY = firstJoint.Position.Y - secondJoint.
            Position.Y;
            float distanceZ = firstJoint.Position.Z - secondJoint.
            Position.Z;
            return (float)Math.Sqrt(Math.Pow(distanceX, 2) + Math.
            Pow(distanceY, 2) + Math.Pow(distanceZ, 2));

        }
        float previousDistance = 0.0f;
        public void clockwiseCircleGesture(Skeleton skeleton)
        {
            //CODE HERE

        }
        public void anticlockwiseCircelGesture(Skeleton skeleton)
        {
            //CODE HERE

        }
        public void RightSwipeGesture(Skeleton skeleton)
        {
            //CODE HERE

        }

            public void LeftSwipeGesture(Skeleton skeleton)
            {
                //CODE HERE
 //            var posLHand = skeleton.Joints[JointType.HandLeft].Position;
            //            var PosRShoulder = skeleton.Joints[JointType.ShoulderRight].Position;
            //            var posSPine = skeleton.Joints[JointType.Spine].Position;
            //            if ((posRHand.Y < PosRShoulder.Y) &&
            //               (posRHand.Y > skeleton.Joints[JointType.ElbowRight].Position.Y) && posLHand.Y < posSPine.Y)
            //            {
            //                shoulderDiff = GestureHelper.GetJointDistance(skeleton.Joints[JointType.HandRight], skeleton.Joints[JointType.ShoulderLeft]);
            //                validatePosition = skeleton.Joints[JointType.HandRight].Position;
            //                startingPostion = skeleton.Joints[JointType.HandRight].Position;
             //            }
            //            // return true if start condition is valid else return false


        }
        private void MatchHandClappingGesture(Skeleton skeleton)
        {
            if (skeleton == null)
            {
                return;
            }
            if (skeleton.Joints[JointType.HandRight].TrackingState == JointTrackingState.Tracked && skeleton.Joints[JointType.HandLeft].TrackingState == JointTrackingState.Tracked)
            {
                float currentDistance = GetJointDistance(skeleton.Joints[JointType.HandRight], skeleton.Joints[JointType.HandLeft]); 
                 if (currentDistance < 0.1f && previousDistance > 0.1f)
                 {                    
                     if (this.GestureRecognized != null)                  
                     {
                         this.GestureRecognized(this,new GestureEventArg(RecognationRes.Success));
                     }
                 }               
                previousDistance = currentDistance; 
            }

        }
        public void StartRecognize()
        {
             switch (this.GestureType)          
             {               
                 case GestureType.HandsClapping:
                     this.MatchHandClappingGesture(this.Skeleton); 
                     break;
                 case GestureType.LeftSwipe:
                     this.LeftSwipeGesture(this.Skeleton);
                     break;
                 case GestureType.RightSwipe:
                     this.RightSwipeGesture(this.Skeleton);
                     break;
                 case GestureType.clockwiseCircle:
                     this.clockwiseCircleGesture(this.Skeleton);
                     break;
                 case GestureType.anticlockwiseCircel:
                     this.anticlockwiseCircelGesture(this.Skeleton);
                     break; 



                 default: break;
             } 



        }


    }


}

this is my second class

  using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;


namespace GestureRecognizer
{

    public class GestureEventArg : EventArgs
    {
        public RecognationRes Result { get; internal set; }

        public GestureEventArg(RecognationRes result)
        {
            this.Result = result;
         }
    }
}

This is my main program

    using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Kinect;
using System.Diagnostics;
using GestureRecognizer;
using iTunesLib; 


namespace TestGesture
{
    class Program
    {
        static GestureRecognitionEngine gestureTool = new GestureRecognitionEngine();
        static iTunesApp itunes = new iTunesLib.iTunesApp(); 
        static void Main(string[] args)
        {



       var sensor = KinectSensor.KinectSensors.Where(s => s.Status == KinectStatus.Connected).FirstOrDefault();

        if (sensor != null)
        {
            sensor.SkeletonStream.Enable();
            sensor.SkeletonFrameReady += sensor_SkeletonFrameReady;
             gestureTool.GestureType = GestureType.HandsClapping;

            gestureTool.GestureRecognized += gestureTool_GestureRecognized;
            sensor.Start();

        }

        Console.ReadKey();
        Console.WriteLine("READY");
        Console.ReadLine(); 


    }

      static void gestureTool_GestureRecognized(object sender, GestureEventArg e)

    {
        Console.WriteLine("OK");
        Console.ReadLine();     
    }

    static void sensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
    {

        Skeleton[] skeletons = new Skeleton[0];

        using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
        {

            if (skeletonFrame == null)
            {

                return;
            }
            skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
            skeletonFrame.CopySkeletonDataTo(skeletons);
            Debug.WriteLine("4.3");
            Skeleton firstSkeleton = (from trackskeleton in skeletons
                                      where trackskeleton.TrackingState == SkeletonTrackingState.Tracked
                                      select trackskeleton).FirstOrDefault();

            if (firstSkeleton != null)
            {
                gestureTool.Skeleton = firstSkeleton;
                gestureTool.StartRecognize();

            }

        }



        }
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.