Software Archive
Read-only legacy content
17061 Discussions

Recognize gesture if it is detected for particular interval / seconds

Khalil_S_
Beginner
766 Views

I want gesture to be Recognize only if it is detected for some seconds (3 secs). 

camera should not consider it as gesture if hand gesture is changed before 3 secs.

How to achieve this ??

Any help appreciated.

0 Kudos
1 Solution
Johannes_V_
New Contributor I
766 Views

Hello Khalil,

 

Some things I have seen that work really good are going over "votes" in the update method.

- detect the gesture and make a couple of votes for the recognized one ( at least 2)

- decrease the amount of votes for each gesture by 1 each step but only if the amount of votes for the gestures themselves is > 0 

- at the end of update method, check if one of the gestures has enough votes to be taken as "winner". this is done by a specific thershold.

- if a winner has been found, dont forget to reset all votes.

I dont have this camera on my own so I "guessed" the following code, if there are problems, just tell me : 

//GLOBAL variables:
int voteForGesture1 = 0, voteForGesture2 = 0 , voteForGesture3 = 0; // all of them
int thresholdForGestureDetection = 200 // lower this value for more detection, rise this value for less detection


// this looks like an updateFrame method?
int firedGesturesNumber = handAnalysis.QueryFiredGesturesNumber();

for(int i = 0; i < firedGesturesNumber; ++i)
            {

                PXCMHandData.GestureData gestureData;
                if (handAnalysis.QueryFiredGestureData(i, out gestureData) == pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    if (handAnalysis.IsGestureFired("thumb_up", out gestureData))
                        gesnum = 1;
                    if (handAnalysis.IsGestureFired("v_sign", out gestureData))
                        gesnum = 2;
                }
            }





//this looks like a validate method at the end of each frame?

if(voteForGesture1>0)
    voteForGesture1--;
if(voteForGesture2>0)
    voteForGesture2--;
if(voteForGesture3>0)
    voteForGesture3--;

 switch (gesNum)
                {
                    case 1:
                        voteForGesture1+=3;break;
                    case 2:
                        voteForGesture2+=3;break;
                    case 3:
                        voteForGesture3+=3;break;

                }

if (voteForGesture1 >= thresholdForGestureDetection){
       label1.Content = "Gestured Fired 01 thumb Up ";
       voteForGesture1=0;
       voteForGesture2=0;
       voteForGesture3=0;
}
    
    
if (voteForGesture2 >= thresholdForGestureDetection){
    label1.Content = "Gestured Fired 02 V sign ";  
    voteForGesture1=0;
    voteForGesture2=0;
    voteForGesture3=0;
}
    

 

View solution in original post

0 Kudos
8 Replies
Johannes_V_
New Contributor I
766 Views

Hello,

 

So you want the hands to be not moved for 3 seconds and then recognize gestures?

I would try some method like checkHandMotion() and repeatedly measure its status. (f.e. returns 0 if hand not moved).

You would probably need to run this method about every 50ms or so. save the results for up to 3 seconds and then check over the saved results if the hand has moved during the last 3 seconds. if no movement && detected gesture then execute a command

 

if you have a minimum example for the recognition post the code here, i will try to give more details then

0 Kudos
Khalil_S_
Beginner
766 Views

I am using many gestures in my project ,

and it detects gestures very quickly even when i don't do that gesture,

thus i want it to detect only if user do gesture for particular interval(3 secs) .i.e v-sign for 3 sec then only it must perform action assigned on v-sign and so on.

0 Kudos
Johannes_V_
New Contributor I
766 Views

What camera do you have? Do you have some code?

0 Kudos
Khalil_S_
Beginner
766 Views

I am using SR-300 camera. 

0 Kudos
Khalil_S_
Beginner
766 Views

From hand Analysis - 

 int firedGesturesNumber = handAnalysis.QueryFiredGesturesNumber();

for(int i = 0; i < firedGesturesNumber; i++)
            {

                PXCMHandData.GestureData gestureData;
                if (handAnalysis.QueryFiredGestureData(i, out gestureData) == pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    if (handAnalysis.IsGestureFired("thumb_up", out gestureData))
                        gesnum = 1;
                    if (handAnalysis.IsGestureFired("v_sign", out gestureData))
                        gesnum = 2;

gesnum here is global variable which i am assigning manually and using it below in updateUi method in switch case - 

under updateUi method - 

 switch (gesNum)
                {
                    case 1:
                        label1.Content = "Gestured Fired 01 thumb Up ";
                      break;

                      case 1=2:
                        label1.Content = "Gestured Fired 02 V sign ";
                      break;

And so on.

 

0 Kudos
Johannes_V_
New Contributor I
767 Views

Hello Khalil,

 

Some things I have seen that work really good are going over "votes" in the update method.

- detect the gesture and make a couple of votes for the recognized one ( at least 2)

- decrease the amount of votes for each gesture by 1 each step but only if the amount of votes for the gestures themselves is > 0 

- at the end of update method, check if one of the gestures has enough votes to be taken as "winner". this is done by a specific thershold.

- if a winner has been found, dont forget to reset all votes.

I dont have this camera on my own so I "guessed" the following code, if there are problems, just tell me : 

//GLOBAL variables:
int voteForGesture1 = 0, voteForGesture2 = 0 , voteForGesture3 = 0; // all of them
int thresholdForGestureDetection = 200 // lower this value for more detection, rise this value for less detection


// this looks like an updateFrame method?
int firedGesturesNumber = handAnalysis.QueryFiredGesturesNumber();

for(int i = 0; i < firedGesturesNumber; ++i)
            {

                PXCMHandData.GestureData gestureData;
                if (handAnalysis.QueryFiredGestureData(i, out gestureData) == pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    if (handAnalysis.IsGestureFired("thumb_up", out gestureData))
                        gesnum = 1;
                    if (handAnalysis.IsGestureFired("v_sign", out gestureData))
                        gesnum = 2;
                }
            }





//this looks like a validate method at the end of each frame?

if(voteForGesture1>0)
    voteForGesture1--;
if(voteForGesture2>0)
    voteForGesture2--;
if(voteForGesture3>0)
    voteForGesture3--;

 switch (gesNum)
                {
                    case 1:
                        voteForGesture1+=3;break;
                    case 2:
                        voteForGesture2+=3;break;
                    case 3:
                        voteForGesture3+=3;break;

                }

if (voteForGesture1 >= thresholdForGestureDetection){
       label1.Content = "Gestured Fired 01 thumb Up ";
       voteForGesture1=0;
       voteForGesture2=0;
       voteForGesture3=0;
}
    
    
if (voteForGesture2 >= thresholdForGestureDetection){
    label1.Content = "Gestured Fired 02 V sign ";  
    voteForGesture1=0;
    voteForGesture2=0;
    voteForGesture3=0;
}
    

 

0 Kudos
Khalil_S_
Beginner
766 Views

Thank you johannes,

i am implementing it. 

0 Kudos
Khalil_S_
Beginner
766 Views

Thank you Johannes, Code worked for me. 

0 Kudos
Reply