1

I'm using the camshiftdemo.c program that comes bundled with OpenCV 2.3.1:

https://code.ros.org/trac/opencv/browser/trunk/opencv/samples/c/camshiftdemo.c?rev=1429

I was wondering how I can use this program to instruct a robot to follow an object of choice? I'm trying to run an experiment to see if it will work, but I obviously need to tweak it a little bit.

The way camshiftdemo works is it draws a red ellipse around the object you chose (by clicking on it with your mouse). As the object moves so does the red ellipse. If the object moves further away the ellipse decreases in size and increases if it comes closer to the camera.

To instruct a robot I was thinking I tell it to move forward if the size of the red eclipse decreases, and move backward if it increases. The robot will move left if the eclipse moves to the left and moves right if the eclipse moves right.

Sounds simple enough, but where in this code is the eclipse being drawn? And what if the object moves back and forth in 10 seconds? Does this mean the robot stays in the same place (i.e. should I introduce a delay in the robots movements?)?

My goal is to get the camshiftdemo.c code to instruct the robot to move {forward,backward, turn left, turn right}.

So how can I get the robot to follow an object, either by using the size of the eclipse or otherwise?

user1068636
  • 1,871
  • 7
  • 33
  • 57

1 Answers1

1

It seems like you are asking for a way to seed the detection of an object into the CamShift tracker.

Depending on the amount of processing power your robot has, you may want to consider a simpler approach. If you can select the target you are looking for, I would choose something like a tennis-ball as they are a very bright and unique color. Now your object has a known color signature, and you can track it fairly simply using contour processing. Also, if you decide to use color tracking, consider switching to a color space like HSV or YCbCr. This will allow the color detection to be less sensitive to intensity change. Here is one of my older posts on color isolation in OpenCV.

The main steps you'll be taking are:

  1. inRange (isolates the object using color thresholds)
  2. findContours (use this to find the object blob; you'll probably want the biggest one, but you could also filter by circularity if it's circular)
  3. moments (to find the centroid of the detected object)

Optionally, you can feed the object centroid into the CamShift tracker, and just use the above mentioned steps as an acquisition mode.

Hope you find that helpful...

Community
  • 1
  • 1
mevatron
  • 13,911
  • 4
  • 55
  • 72