Just value your mind

Hand detection using openCV

 

In this post, as the progress goes, the hand detection technologies using openCV is introduced. As the pictures inllustrated below, this detection method is independent  with distance and background ( just not the background full of hands ), and the main segment method is color abstract which means getting the hand color pixels filtered. As the result tested within several environments, it workd well except slightly noise varying. But the noise is easy to take off.

The tested source code file is offered underneath the illustrations, feel free to use it.

handdetection

handdetection2
SOURCE FILE HERE:  handDetection.CPP
Related post which may interest you:
Hand gesture detection and recognition

 

Revised by Andol on 28 Oct 2013

As asked by Niaz:

Among these or outside of these which method you think is the possible best approach to take.

1. Skin tone detection (Adaptive skin detection: opencv)
2. Blob detection (cvBlob: opencv)
3. Haar cascade classification
4. Feature-based scale invariant hand detection (using something like openSURF, SIFT, RANSAAC etc)

My anser is HAAR CASCADE CLASSIFICATION detection is the first choice, it take a lot time to work out the classifier though. Based on my experiences, if the background is clean and simple then skin colour detection is also a good choice;

while blob detection has generally lower detection accuracy in hand recognition; lastly the feature-based detection is only a choice for rigid object matching, that is, hands have different combination of features such like finger length and the ration between fingers and palm, that is not suitable for feature detection – as these hand features change all the time.

 






QR code for this post, SCAN ME
QR:  Hand detection using openCV

Posts may be of your interests

89 Comments On “ Hand detection using openCV”

  1. Edwin says:

    Hello, I need your help on hand detection in OpenCV, I am quite poor at computer programing and I want to use this technique to control a robot eye. I have successfully managed to acquire and capture the image from my web cam and now need to move on to the next step. I was told i have to use the Haar libraries and the same concept of Face detection by my professors. What should i do? Thank you

    • Andol says:

      well, if haar is adopted to detect the hand’s gestures, the first thing you should do is to capture enough number of samples including positive and negative. Then you can train your application according to these samples you have gathered. for more details, it is possible to refer the machine learning part of openCV.

    • jygfuyf says:

      you gotta require to do a lot of reading on the topic before asking these kind of questions.

  2. Nguyen Van Bao says:

    great….
    i using EgmuCV, can you Hand detection using EgmuCV, my email:baonv2109@gmail.com
    thank !!

  3. Nguyen Van Bao says:

    great….
    i using EgmuCV, can you send me Hand detection using EmguCV, my email:baonv2109@gmail.com
    thank you!!

  4. Nguyen Van Bao says:

    great….
    i using EgmuCV, can you send me Hand detection using EmguCV code, my email:baonv2109@gmail.com
    thank you!!

  5. quarks says:

    hi i would like to control cursor movements by using hand so please help me to find coordinates of hand..please help me in this urgent

  6. quarks says:

    hi i need to get the coordinates of the hand while moving ….. please help me …its urgent

    • Andol says:

      first, detecting the hand, and then finding a centre of detected hand as a rectangle, and at last connecting the cursor to coordinates of the hand.

  7. quarks says:

    hi thanks for this i had done still but i dont know how to proceed again (ie) to detect the gesture and perform mouse clicks help me please

    • Andol says:

      once you segment clean hand contours, the next step would be detect the convexities by using a function in openCV called ‘CvConvexityDefect’ to get the hand’s features.

  8. Avesum says:

    how can i perform left click and right click by my finger using webcam in open CV library plz help..

    • Andol says:

      the way is to assign different gesture to left click and right click, e.g. four fingers means left click, full palm means right click.

      • spiffy says:

        hi andol.i am doing work on computer control using fingure movement.i have done worke till by decteing fingure movement of pointer can you plz help me how in i perform left and right click?

        • Andol says:

          @spiffy
          there needs two distinguishable gestures that are associated with left and right click. In that case, left and right clicks may need two other finger gestures, such like bending a finger.

  9. kabir hossain says:

    Hi, i got your code.This is working well but i want to find the hand location.I have used contour but still can not find hand location.can your help me?plz

  10. Namesake says:

    Hi Andol,
    After detecting the hand, Is there a way to connect the mouse pointer to coordinate(x,y)? I am using Ubuntu. What command should I use to do so?

  11. sobia says:

    hi Andol
    i have to control a robotic car by fingers i hv saw ur code.it working for hand exraction.nw i hve to count of fingers in a particular moment.plaese help me wat i do next..

  12. Finch says:

    Hello Andol, thanks for the advice, your helping me on my way but i have a few questions.

    Im trying to make an application that responds to hand gestures. At the moment all I want to do it figure out where (in terms of x,y) the center of the hand is in the image and how many fingers are being held up.

    So once I have the black and white image you show in this post, how do i then draw areas round them and get the .Center values from it ? I see in another one of your posts you have managed to draw a very precise contour round the hand, how did you manage that ? I know you only do OpenCV and not Emgu but if you show me the specific method calls you would use I can probably figure out the Emgu equivalents.

    Thank you for your time.

    Also, I see a few people asking how to do it in the Emgu CV version. Well…


    Capture camera = new Capture()
    Image originalImage = camera.QueryFrame() ; // Raw image

    /* All the colour segmentation is done in Hsv not Bgr so we need a Hsv version of our image */
    Image hsvImage = originalImage.convert();

    /* Now we need to define the upper (max) and lower (min) Hsv values that we want to extract from the image */
    Hsv hsv_min = new Hsv(127, 66, 57);
    Hsv hsv_max = new Hsv(183, 203, 124);

    /* Note: I am trying to detect hands in my webcam image and in a dark room, you will need to play around with the parameters in hsv_min & hsv_max to find the colours you want to extract

    Now, the process of checking if pixels are in range of these min and max values results in a greyscale image, so we'll need one of those. */

    Image greyedImage = hsvImage.InRange(hsv_min, hsv_max);

    /* BAM ! A greyscale image containing only the pixels with Hsv values between the hsv_min & hsv_max ranges. *.

    • Andol says:

      Hi Finch, after ive got the while-black result, i use:
      “cvSmooth” to reduce the noises, “cvCandy” to extract lines, “cvFindContours” to extract the most possible hand contours, once i ve got the right contours, i use “cvBoundingRect” to locate the position of hand as a rectangle, then draw out the rectangle which is the picture you see. Or you can refer here for detail codes here http://download.andol.info/hsv.cpp. PS: thanks for your codes sharing.

    • sudharsan.n.s says:

      just if we use this value for hsv
      Hsv hsv_min = new Hsv(0, 30, 80);
      Hsv hsv_max = new Hsv(20, 150, 255);

      instead of this
      Hsv hsv_min = new Hsv(127, 66, 57);
      Hsv hsv_max = new Hsv(183, 203, 124);

      it works fine…

      • Andol says:

        indeed, the color range matters, cheers

        • sudharsan.n.s says:

          cheers too….. and is there any HaarCascade training set for detecting hand, i searched that many times, but i got nothing….. if there is anything means just help me out, because detecting hand using skin color does not satisfy the result…

          hearing for your reply……….

  13. bon says:

    algorithm your is great, do you have algorithm fire detection using openCV ? Can you send to me .
    my email : trung_lvt@yahoo.com

    • Andol says:

      Hi Bon, i am not sure if the hand detection algorithm fits fire detection by openCV, though thay have some features in common. You can have a try using hand detection algorithm with some improvements according to fire features.

  14. JP Talusan says:

    Sir, i know this code works for a live webcam feed, how do you make it work for an input of still image and .avi video files only

    • Andol says:

      hi JP Talusan, if you had had a look at the source loading codes in opencv, you would find that it is able to load live webcam images, still images, and .avi video files. Here is a simple instance:
      #include “cv.h”
      #include “highgui.h”
      int main( int argc, char** argv )
      {
      IplImage* pImg;
      if( argc == 2 &&
      (pImg = cvLoadImage( argv[1], 1)) != 0 ) //argv[1] is a parameter of image path.
      {
      cvNamedWindow( “Image”, 1 );
      cvShowImage( “Image”, pImg );
      cvWaitKey(0);
      cvDestroyWindow( “Image” );
      cvReleaseImage( &pImg );
      return 0;
      }
      return -1;
      }
      cheers.

  15. Rajkumar says:

    Hi,

    First of all,great work. I found it quite useful.I am currently doing a similar thing although on a depth based camera which does not have colour..

    Right now I have the contour of the hand and the arm and its a motion tracking system. I now need to cut the hand from the arm and use the hand to control a cursor on screen. Could you give me an idea as to how i should separate the hand and how to control a cursor?

  16. Lama says:

    Hi,
    Do you know some free (natural) hand gesture or whole human or upper body database?
    I read about the Massey Gesture Database, but the link does not work :(
    Help me please.

  17. asad kahn says:

    Dear Andol I m working on gesture recognition i need to detect and track the hand so which kind of method is beneficial for me if u have code plz send as well.

  18. asad kahn says:

    Thanx dear but still didnt find appropriate way. Is there any one knows about the handshpe date base use for for tracking? waiting for reply.

  19. Tushar says:

    Hi Andol,
    I need to detect the tips of the fingers…Can you help me with the code for this… I want to know which finger is visible. Please let me know if this is possible. I am new at opencv so any help would be great

Leave a comment

You can use these XHTML tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Copyrights 2006-2014 © Andol Li | Theme Tree2, re-designed by Andol Li| Powered by WordPress
WWW.ANDOL.INFO- 80 queries in 0.635 seconds. Go to TOP