pageauc
Posts: 192
Joined: Fri Jan 04, 2013 10:52 pm

New - RPI Camera Tracker - OpenCV, Python, Video Stream

Mon Aug 22, 2016 4:59 pm

cam-track.py - Camera Movement Tracker Demo Windows, Unix, RPI
A Raspberry Pi, Windows, Unix, Camera Pan-Tilt Tracker using python and opencv

YouTube Video Demo https://youtu.be/yjA3UtwbD80
YouTube Video Code Walkthrough https://youtu.be/lkh3YbbNdYg
Github Repo https://github.com/pageauc/motion-track ... /cam-track

UPDATE - 5-Sep-2016 Updated code to verion 0.85. This version is broken into more specialized functions. Most of the core code has been rewritten (more than once). This version is relatively immune to random motion in the camera view and I am happier with the performance (It can still get out of sync thought). I will work on an option to return camera movement xy positions in degrees between 0 and 360 degrees.
Let me know your comments. Thanks Claude ...

Program Description
This is a raspberry pi computer openCV2 program that tracks camera (pan/tilt) movements in real time. It requires a RPI camera module installed and working. The program is written in python2 and uses openCV2.

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/blo ... ostream.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.

Code: Select all

    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       # defaults to run from RPI desktop terminal session
                                   # Set window_on=False if running in SSH session
Last edited by pageauc on Fri Aug 25, 2017 5:39 pm, edited 2 times in total.
GitHub - https://github.com/pageauc
YouTube - https://www.youtube.com/user/pageaucp

pageauc
Posts: 192
Joined: Fri Jan 04, 2013 10:52 pm

Re: New - RPI Camera Tracker - OpenCV, Python, Video Stream

Tue Sep 06, 2016 11:17 am

UPDATE - 5-Sep-2016 Updated code to verion 0.85. This version is broken into more specialized functions. Most of the core code has been rewritten (more than once). This version is relatively immune to random motion in the camera view and I am happier with the performance (It can still get out of sync though). I will work on an option to return camera movement xy positions in degrees between 0 and 360 degrees.
Let me know your comments. Thanks Claude ...
GitHub - https://github.com/pageauc
YouTube - https://www.youtube.com/user/pageaucp

pageauc
Posts: 192
Joined: Fri Jan 04, 2013 10:52 pm

Re: New - RPI Camera Tracker - OpenCV, Python, Video Stream

Tue Sep 06, 2016 12:47 pm

Robot without wheel encoder Navigation Test using camera tracking
Forgot to mention I am also 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 (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 (calibrating). I am hoping to test this on my robot since it does not have wheel encoders. This camera track could allow the robot to more accurately navigate and rotate. I am pleased with the current FPS with ver 0.85. The multi version is not very stable due to segment faults so I will stick with only the video stream being threaded.
If you decide to try this as well let me know.
Claude ...
GitHub - https://github.com/pageauc
YouTube - https://www.youtube.com/user/pageaucp

User avatar
bonzadog
Posts: 161
Joined: Wed Apr 25, 2012 9:40 am
Location: Rietberg/Germany

Re: New - RPI Camera Tracker - OpenCV, Python, Video Stream

Fri Aug 11, 2017 10:42 am

11.8.2017

Prohblem with install.

wget https://raw.github.com/pageauc/motion-t ... m-track.py
causes
pi@rpi3:~/cam-track $ wget https://raw.github.com/pageauc/motion-t ... m-track.py --2017-08-11 10:40:16-- https://raw.github.com/pageauc/motion-t ... m-track.py
Resolving raw.github.com (raw.github.com)... 151.101.112.133
Connecting to raw.github.com (raw.github.com)|151.101.112.133|:443... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://raw.githubusercontent.com/pagea ... m-track.py [following]
--2017-08-11 10:40:16-- https://raw.githubusercontent.com/pagea ... m-track.py
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.112.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.112.133|:443... connected.
HTTP request sent, awaiting response... 404 Not Found
2017-08-11 10:40:16 ERROR 404: Not Found.

Perhaps any help?

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4601
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: New - RPI Camera Tracker - OpenCV, Python, Video Stream

Fri Aug 11, 2017 12:04 pm

bonzadog wrote:
Fri Aug 11, 2017 10:42 am
11.8.2017

Prohblem with install.

wget https://raw.github.com/pageauc/motion-t ... m-track.py
causes
pi@rpi3:~/cam-track $ wget https://raw.github.com/pageauc/motion-t ... m-track.py --2017-08-11 10:40:16-- https://raw.github.com/pageauc/motion-t ... m-track.py
Resolving raw.github.com (raw.github.com)... 151.101.112.133
Connecting to raw.github.com (raw.github.com)|151.101.112.133|:443... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://raw.githubusercontent.com/pagea ... m-track.py [following]
--2017-08-11 10:40:16-- https://raw.githubusercontent.com/pagea ... m-track.py
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.112.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.112.133|:443... connected.
HTTP request sent, awaiting response... 404 Not Found
2017-08-11 10:40:16 ERROR 404: Not Found.
https://github.com/pageauc/motion-track ... /cam-track
IMPORTANT - This project has moved to https://github.com/pageauc/rpi-cam-track
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Return to “Graphics programming”

Who is online

Users browsing this forum: No registered users and 2 guests