Code Walkthough - Win, Unix, RPI - Camera Position Tracker - Opencv, Python, web cam, pi-camera

Опубликовано: 18 Август 2026
на канале: Claude Pageau
5,222
22

Code on GitHub https://github.com/pageauc/cam-track
YouTube Demo -    • cam-track.py  - Win, Unix, RPI - opencv,  ...  
1-Sep-2016 Updated to better resist objects moving in frame

Windows, Unix, Raspberry Pi Camera Position Tracker
This is a python opencv program that tracks camera (pan/tilt) position movements. It requires a USB Web Camera or RPI camera module installed and working.

It captures a search rectangle from the center of a video stream tread image. It then locates the rectangle in subsequent images based on a score value and returns the x y location in the image based on a threshold accuracy.

If movement gets too close to the sides of the image or a suitable image search match cannot be found, then another search rectangle is selected. This data is processed to track a cumulative pixel location based on an initial camera image center value of 0,0.
This code could be used for a simple robotics application, movement stabilization, searching for an object image in the video stream rather than taking a search rectangle from the stream itself. Eg look for a dog. where the camera is mounted on a moving platform or object, Etc.

Note: This application is a demo and is currently still in development, but I thought it could still be useful, since I was not able to find a similar RPI application that does this. Will try to implement an object searcher based on this demo.

Thanks to Adrian Rosebrock jrosebr1 at http://www.pyimagesearch.com for the PiVideoStream Class code available on github at https://github.com/jrosebr1/imutils/b...

Setup

Requires a Raspberry Pi computer with a RPI camera module installed, configured and tested to verify it is working. I used a RPI model B2 but a B+ , 3 or earlier will work OK. A quad core processor will greatly improve performance due to threading

From logged in RPI SSH session or console terminal perform the following.

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y python-opencv python-picamera
mkdir ~/cam-track
cd ~/cam-track
wget https://raw.github.com/pageauc/motion...
chmod +x cam-track.py
./cam-track.py

See GitHub Repo additional details
https://github.com/pageauc/motion-tra...