PTZ Foscam Object/ Motion tracking.
Derek Bair  [2 posts]
8 year
I am attempting to get a Foscam Ip camera (F18910W) with PTZ (Pan Tilt Zoom) to pan and tilt to follow an object or movement. So that the camera will use the center of gravity or some other type of tracking to move the pan and tilting accordingly. There is already an interface for the camera that I am using and it displays and filters can be applied to the live feed. It also has a section specifically for the camera with a function to control the pan and tilt. I am learning scripting/ and this program and do not know how to link a motion. The goals would be for the camera to pan or tilt to stay centered on whatever is moving (or ideally a recognized object) eg. If I was to wave my hand slowly in front of it - it would follow along and try to keep what is moving within the 'center of gravity' or within the field of view. If there wasn't anything moving it would wait until there was and then center in on it and keep it centered.

Does anyone know if this is possible or if there is already a way to do it that I just don't know about? I'm guessing there is a way to link the center of gravity function with the pan and tilt controls as they are both already available within the program. There may be another way to do this that I am overlooking. I would also be willing to get an arduino or whatever other types of usb controllers that would allow for the same type of thing. Thanks!

Steven Gentner from United States  [1446 posts] 8 year

Based on your image, you will see the VBScript module has relevant code in it to translate a joystick movement into a camera movement. Namely the variable move_dir (seen in the Foscam module) would be assigned either a 4 (left) or 8 (right) based on the location of the object. If you are using the Center of Gravity that will produce a COG_X variable based on the location of the object. Checking to see if this variable is in the left or right side of the image you can then assign the correct number to the variable which will move the camera. For example,

x = GetVariable("COG_X")

if x < (GetVariable("IMAGE_WIDTH) / 2) then
  SetVariable "move_dir", 4
  SetVariable "move_dir", 8
end if

would do the job ... but cause the camera to oscillate when the object is in center of the image. So instead

x = GetVariable("COG_X")

if x < ((GetVariable("IMAGE_WIDTH) / 2) - 40) then
  SetVariable "move_dir", 4
elseif x > ((GetVariable("IMAGE_WIDTH) / 2) + 40) then
  SetVariable "move_dir", 8
  SetVariable "move_dir", 0
end if

would stop that.

While this is VBScript its a simple conditional test that can be done in other languages easily too. Or even using the IF_Statement module.

This all assume that you have some sort of tracking going on before this that uses the COG module to run. If you don't know how to do this see the Red Object Tracking example in the main RR menu tree and remove the Parallax module. This tracks red color and also has some VBScript to translate the COG_X into a servo value ...

Note, we did exactly this when we first got the Foscam ... you will have to move the object quite slowly since the camera is not meant to pan very quickly.

Derek Bair  [2 posts] 8 year
Thank you for your reply! I returned that camera for a higher resolution model that does not seem to be supported by roborealm (Foscam F19826P) although I found that iSpy software will accomplish the same thing automatically, but not very accurately. After some research it seems like "Pixy" camera is the way to go.


This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index