Sunday, March 20, 2011

Open CVhat I can do!

Greetings:

I have decided to take a short break from Lego building(let us just say that I stepped on one too many Lego bricks) and decided to learn something new. I always wanted to incorporate vision in my programs, so I decided to learn a little bit of OpenCV. I actually want to use OpenCV with Lego Mindstorms, but since I am using OpenCV for c++, I would have to use JNI to get my LeJOS Mindstorms to successfully communicate with my C++ OpenCV program. (EDIT: I just found out that a Java Wrapper for OpenCV exists, so I may be able to give my Mindstorms "vision" after all!) Anyway, What I really was interested in was to use OpenCV to track eyeball movement. I will tell you why in the next post. Now how OpenCV tracks face and eye movements is relatively complex. I do not understand all of it, just enough to make my small eye tracking program work. Pretty much the face detection algorithm scans an image for Haar like Features, and if the image satisfies the condition of having a face, the algorithm further subdivides the face into many categories. For example in a typical face, the eye is darker than the cheek, and so when the algorithm compares the intensities of the pixels that make up the eye and cheek, it finds the difference in intensities and is able to distinguish between the eye and a cheek in a face.
          This is a very watered down explanation of what is *really* happening behind the scenes, and in reality, the face and eye detection algorithms in openCV are clunky at best without proper optimization. So I decided to create  small c++ program that takes in input from a webcam ans tracks the face and eyes in real time. It also superimposes images over the face. Face detection was pretty much straightforward. But the eye detection algorithm required further optimization. How it worked was that it all eyes that it discovered in an image(or video frame) it would store in a array. But the problem was that it detected 6-7 eyes at once! Now I only have 2 eyes(4 with glasses, but that not the point), so I had to make the algorithm pick only two eye objects from all that it had discovered. The optimization that I used was to pick the two eye objects with the largest area, and see how their x and y coordinates match up relative to themselves and the face(This is better explained in the annotated code posted below). After hours of tinkering, I have a created a program that tracks human eyes with movement in all 3 dimensions with ~85% accuracy in real time. It is good enough to start out with, but I figure I will have to do much more of optimization if I want to carry out a certain project(more on this later).
              I have posted the links to the annotated code below which explains how my optimizations work. They are no work of art, but they work satisfactorily. Also here is short video of the eye tracking in progress in real time.


Link to download the folder with code, .exe, classifiers and the other good stuff.

This is not the end......

13 comments:

  1. Hi,
    i am a newbie in programing and i hope u can help me in the source code part.My project is to detect the object boundary, can u make 1 video for the tutorial to detect the object outside boundary and provide me the source code. thanks.

    ReplyDelete
    Replies
    1. U can use the couture to detect and draw the boundary of any object

      Delete
  2. I am not sure I understand you...what do you mean when you say detect the object outside the boundary?

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. hi there.. i;m running your code but there is a error that cv.h can not run.? any help?

    ReplyDelete
  5. So if i want to detect nose and hand what do i have to do?

    ReplyDelete
  6. Can you help me? I've problem with my programs.
    I'd like to detect 4 objects in an image (size image = 1327x1052 pixel). 4 objects are buildings, roads, plants, and marine. I'm already training them all.the 4 files *xml are finishing.
    I make my project using C++ with console application, but when I run the programs, the program can't debugging and they show a message null pointer (invalid classifier cascade)in function cvHaarDetectObjects, C:\User\VP\opencv\cv\src\cvhaar.cpp(890).
    I've search the path,but the path did not find in my C drive. Can you give me a solution , please.
    Nice to know and learn about the opencv with you. Best regards
    can you give me your address email?thx.

    ReplyDelete
  7. you have coded using visual studio or eclipse?

    ReplyDelete
  8. Hmm, you need to install JavaCV in order to use this. Once you install JavaCV, use Netbeans to create a project and run the program. If you have linker problems, refer to this: http://stackoverflow.com/questions/6784740/javacv-giving-java-lang-unsatisfiedlinkerror/6881894#6881894

    ReplyDelete
  9. Hi, I`d rather to see your code. Have you email to send you ?
    Thanks a lot.

    ReplyDelete
  10. Hi,
    I am working on my project wheel chair movement using eye control. could this above algorithm be useful for me?

    ReplyDelete