3

Is there any open source or demo code available in C/C++ for OpenCV that does simple ball tracking?

Basically I want to hold a red-colored ball in front of my web camera and I want OpenCV to detect its location. If I move the ball towards the right or left of the screen the program will detect the location of the ball has changed and output its new location.

I have successfully installed Open CV 2.3.1 on the raspberry pi with a web camera, eventually I want to execute the code on the pi.

pb2q
  • 58,613
  • 19
  • 146
  • 147
user1068636
  • 1,871
  • 7
  • 33
  • 57

5 Answers5

3

I just stumbled upon this. It is a cvBlob example and very similar to what you want to do. Source code is here here.

Sassa
  • 3,294
  • 2
  • 28
  • 42
  • Hi bob - thanks for this link. I pre-tested this on my mac and got it to successfully detect red objects within view of my webcam. I installed this on my pi, but when when I try to run the binary "./red_object_tracking" it seems to be quite slow in loading the window that shows what my webcam sees, and sometimes it never shows up. I executed "top" while it was running and CPU=93.8% MEM=29.7%. Is there anyway I can improve this? – user1068636 Oct 04 '12 at 05:00
  • @user1068636 Just saw that along with your question. Since it seems to be pi specific, I'm afraid I can't be of any help. Did you try simpler examples of OpenCV or cvBlob to see if they run fine? – Sassa Oct 05 '12 at 14:51
2

This seems to be what I'm looking for:

https://github.com/tommed/tommed-opencv-examples/

user1068636
  • 1,871
  • 7
  • 33
  • 57
1

There's a project I've played with a while ago called Touchless

It is perhaps a little bit too complex for what you intend to do, but there's some marker tracking code in there, and it can be useful ;)

Good luck playing with your Pi.

Castilho
  • 3,147
  • 16
  • 15
0

The example that you found - Tommed - uses the RGB to track colours.

You would do a lot better looking at the HSV plane. There is an example in the cvBlob library

However people have varying degrees of success with cvBlob on the Pi. Still the principle of HSV remains the way to go.

Dave Appleton
  • 465
  • 1
  • 6
  • 18
0

If you want to detect simple object such as red colored ball, you may consider using pixy camera.

mon
  • 641
  • 1
  • 7
  • 14