8
votes

I am using the OpenCV library for an image processing project to detect hands. I initialized the image in iplimage, colored it, and then converted it to HSV with cvCvtColor(imageHand,imageHand,CV_BGR2HSV ); I don't know the efficient algorithm so that's my problem. Please check my code:

for( int row = 0; row < imageHand->height; row++ )
{
    for ( int col = 0; col < imageHand->width; col++ )
    {
       h =(imageHand->imageData[imageHand->widthStep * row + col * 3]) ;
    s = (imageHand->imageData[imageHand->widthStep * row + col * 3 + 1]);
    v = (imageHand->imageData[imageHand->widthStep * row + col * 3 + 2]);

         if(  h>85)
         {
     imageHand->imageData[imageHand->widthStep * row + col * 3 ]     = 0 ;
     imageHand->imageData[imageHand->widthStep * row + col * 3 + 1 ] =0 ;
     imageHand->imageData[imageHand->widthStep * row + col * 3 + 2 ] = 0 ;
         }
         else
         {
         imageHand->imageData[imageHand->widthStep * row + col * 3 ]     = 255 ;
     imageHand->imageData[imageHand->widthStep * row + col * 3 + 1 ] = 255 ;
         imageHand->imageData[imageHand->widthStep * row + col * 3 + 2 ] = 255 ;

         }


     }
}

I think the range of the searched h is > 85!? If you know a better algorithm than please guide me.

2
I cleaned up the spelling and grammar - please check it to make sure the information is still correct.Pubby
Could you specify for what you need hand detection? Should it be real-time or could be done offline? Do you need this working in huge variety of light conditions? Or maybe you're just playing?Ernest Staszuk
i need hand detection code for porting it to FPGA so it must be real time and high efficient and i want it work for most probable conditionsMohamed Kamal

2 Answers

6
votes

If you take a look at this site, Hand detection using opencv, you'll find a similar algorithm to what you're using. I would say that the easiest way of detecting a hand would be through the use of colour (i.e. skin detection). I would definitely recommend looking at the algorithm provided by that site first. There's another part that also goes into gesture recognition, if that's an eventual problem you're going to need to handle.

Other possibilities include:

  • Background Subtraction
    • This is very simple and prone to breaking, especially if you're planning on the background changing. But, if you're expecting to only use it in front of, say, a white wall... this could be an easy way of going about it.
  • Shape Analysis
    • There has been some success with detecting fingertips using the Generalised Hough Transform. False positives can become a worry, however and efficiency is a worry, particularly in situations with a significant amount of background.
2
votes

as Ancallan has mentioned hand detection using opencv above, I would like to add some more information on the topic of gesture detection. In that post the author used a method of skin colour segmentation, which has got quite good results under specific circumstances.

a new post of hand gesture detection using openCV has been updated, in which the author used a HAAR classifier to detect closed palm, and the results are much more robust than the former ones. but need to point out that the detection objects are somehow limited as one classifier only works for one gesture.