vkapla02
Posts: 2
Joined: Mon Feb 22, 2021 2:35 pm

Web camera position controlled by servos using object tracking

Mon Feb 22, 2021 2:57 pm

Hi all,

I am on a new project where i want me raspberry pi to execute the following.
Hardware: Rapsberry pi 4b
2 servo motors sg90
web camera (usb)
PCA9685

Aim: Object detection and tracking

I have succesfully make my camera to detect the position of an object but i cant find out how i can make the camera follow the object in the pan/tilt stage. Can anyone suggest me a working code to do so?

Thanks in advance !!

Heater
Posts: 17421
Joined: Tue Jul 17, 2012 3:02 pm

Re: Web camera position controlled by servos using object tracking

Mon Feb 22, 2021 4:50 pm

Paul McWhorter has a wonderful series of videos on doing exactly this. He uses OpenCV from Python to do the object detection and ends up driving two servos to pan and tilt a camera for tracking.
https://www.youtube.com/watch?v=5INy0Fv ... RFFPkOuP4_

He does it all on an Nvidea Jetson Nano computer but I'm very sure everything he does there will work on the Pi as well. Albeit a bit slower.

See a significant result here:
https://www.youtube.com/watch?v=CW7NGWE ... _&index=32

It's a long seres but if you are a beginner to all this there is a lot to learn. Perhaps skip parts that are specific to the Jetson Nano.

Edit: Do not be put off by the "AI" in the title of his series. He does not introduce any Artificial Intelligence until after the link I posted above. It's all just normal OpenCV stuff up to that point.
Memory in C++ is a leaky abstraction .

Robu.in
Posts: 9
Joined: Fri Jan 22, 2021 11:58 am

Re: Web camera position controlled by servos using object tracking

Tue Feb 23, 2021 12:26 pm

Hi,
For object tracking, I would suggest using an action camera (like a GoPro). RPLidar is also a viable option for tracking objects in real-time.
Hope this helps!

bjtheone
Posts: 1101
Joined: Mon May 20, 2019 11:28 pm
Location: The Frozen North (AKA Canada)

Re: Web camera position controlled by servos using object tracking

Tue Feb 23, 2021 6:20 pm

Also worth taking a look at FRC (robotics) as many teams use Pis and OpenCV for vision target tracking, as all recent games have retroreflective vision/goal targets and many teams also use vision as part of game piece acquisition systems. Most teams publish and share their code. Two most common development languages are Python and C.

Common applications include fixed cameras applying steering corrections to the robot, and independant 2 or 3 axis acquisition systems.

RpiName
Posts: 724
Joined: Sat Jul 06, 2013 3:14 am

Re: Web camera position controlled by servos using object tracking

Wed Feb 24, 2021 8:55 am

If you are interested in a ready-to-use video tracking solution with the Rpi, you can have a look at this:

https://www.linux-projects.org/uv4l/tut ... nsor-flow/

Return to “General discussion”