cam-track.py - Win, Unix, RPI - opencv, python, Camera Pan Tilt Position Tracker
Описание
GitHub Repo https://github.com/pageauc/cam-track
Code Walkthrough https://youtu.be/lkh3YbbNdYg
1-Sep-2016 Updated to better resist objects moving in frame
Now runs on Windows, Unix using web cam as well as the Raspberry pi using pi-camera module or web cam. Can read from a video file.
CAMERA LOCATION TRACKER
This is an openCV2 program that tracks camera (pan/tilt) movements. It requires a USB Web Camera or RPI camera module installed and working. The program is written in python and uses openCV2.
It crops a search rectangle from the center of a video stream tread image. It then locates the rectangle in subsequent images based on a opencv a template match score value and returns the x y location crop rectangle in the subsequent video images. The search rectangle image is 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 camera position pixel deviation 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.
I am looking at saving high value search rectangles that are spaced out around the full xy range of the camera movement and use those to correct any tracking errors. These check point rectangles will also need to be updated if a better check point rectangle (higher maxVal) is found in the same region. I was thinking approx every half image spacing in xy cam position. This would allow it to self correct position drift (self calibrating). I am hoping to test this on a robot that does not have wheel encoders. Camera tracking could allow the robot to more accurately navigate and rotate.
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/blob/master/imutils/video/pivideostream.py
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-track/master/cam-track/cam-track.py
chmod +x cam-track.py
./cam-track.py
See GitHub Repo additional details
https://github.com/pageauc/motion-track/tree/master/cam-track
Рекомендуемые видео



















