Monday, March 16, 2009

Fast Color Based Object Tracking Using C++ and OpenCV




In my first post I want to present something very simple to explain and very funny at the same time. It is a very simple example of color based object tracking. As all we know, color based object tracking can be very simple to achieve but it is not as robust to implement for something very serious but it do can be applied for some funny robots.


This example is implemented using c++ as all my image processing algorithms. While I was searching for some library for capturing the camera frames – I didn’t wanted to wast any time on that – I found a new version of the famous OpenCV library and I wanted to give it a try. If you don’t want to use OpenCV for capturing the camera frames, here is an excellent video grabber library: http://shukaiyang.myweb.hinet.net/vdograb/index.html

The algorithm is very simple. First each frame is captured using the cvQueryFrame, then each frame is processed without using any OpenCV function (I rather like to use mine) .
Each frame is first smoother in order to blur the image a little bit. After the smoothing, the image is analyzed in order to determine whether each pixel belongs to the color we are interested in. in this case the red one. All pixels matching this criteria are leaved untouched, all other pixels are whitened.


Two Red pens are tracked

The next step is to threshold the image, so we will have an white-black image only where the black pixels belong to the object we are follow. In order to improve the recognition, the final step is to use morphological operation to remove undesired spots due to image noise.

After the final step was performed, we have identified the objects matching the color we are tracking.
I use again OpenCV in the final step in order to display the object tracked in the original video frame as you can see in the video.
It is a simple way to start working on object recognition/tracking and start improving it as you learn more complex algorithms.

I have used CamStudio http://sourceforge.net/projects/camstudio/ for capturing the video.

The blog can also be followed with

10 comments:

  1. hi ,

    i have seen your Fast Color Based Object Tracking Using C++ and OpenCV video.

    Right now,i am also working on object tracking project in C++.
    Can you share the source code of this code? It will help me lot.Thank uou.

    Nayan

    ReplyDelete
  2. hello!

    I am working in something like this, but I am having lots of problems with code.

    Can you make your source code available? My email is fatinha.gonc@gmail.com.

    Thanks!

    ReplyDelete
  3. i have seen your fast color based object tracking using c++ and opencv..I am working on it...
    if u can share the codeing it will be really helpful for me
    thank yoy..

    kanna

    ReplyDelete
  4. now, i am working on fast color object tracking. and i have seen your video..
    could you share the code to me?if you could, it will be helpful for me, thank you..
    my email is eminkngia@gmail.com

    regrad..

    ReplyDelete
  5. hey dude ! i m working on object tracking and i have seen ur stuff.. i am having problem in my code which is written in C++. Can u share the code.. my e-mail id is abhinaykankani@gmail.com

    ReplyDelete
  6. hey,i went through ur stuff man..seems very interesting..can u please share the code for this..as m planning to do my project on it..
    my email-id is project.tasm@gmail.com

    ReplyDelete
  7. hey nobady share source code?
    send me please dogan_sezgin@hotmail.com.

    ReplyDelete
  8. It's great...I'm learning about human(who is walking) tracking. I have some problem in C++. Can't u share the code. I think it really helpful for me
    My email-id is huynhphan188@gmail.com
    Thanks u so much

    ReplyDelete
  9. hey can u pls share ur code....
    my email:ajaywilson@gmail.com

    ReplyDelete
  10. Please share your code I also need it for my final project my email is johnp_2007@yahoo.com

    ReplyDelete