Wednesday 29 February 2012

R2D2 Robot Vision & Motion Tracking Software


Part 3 - R2D2 Robot Computer Vision

How to use a webcam to detect movement and then track that movement on a X & Y coordinate. Once we have the XY, I then show how to turn that in to real motion.
So, in this blog we I will tackle probably the second most difficult part of a robot - VISION.

My Other R2D2 building blogs...



Part 1) R2D2 DIY / How To / Building Guide
Part 2) R2D2 Electronics, Motors, Servos And Control
Part 3) R2D2 Webcam Vision (C#), Motion Tracking, Robot Head Control



Vision Software - written by me for R2D2 in C#

1) The Vision Application - General overview
2) How it works in user english
3) Physical interfacing - Pololo Maestro and StepperBee+
4) Configuration and tuning
5) Integration into your robot project
6) User / setup / configuration guide
7) Link to C# developers guide in case you writing your own and need help.


Section 1: The Vision Application (making your R2D2 robot see)

Okay so you have read my previous blogs and made yourself a new friend call r2d2 but now you want him to be able to see. As you can imagine this can be pretty tricky for even good programmers but with this application you can add vision to your r2d2 robot in less than half an hour.

Let's start by seeing it in action fitted to a R2D2 on the X-axis (head rotation) for this purpose. The Y-axis for moving his projector eye up and down.




Now we have an idea of what it does let's take a look at the application:



The basic steps to create robot vision are:

1) Capture live video from a camera (webcam, IP Cam)
2) Detect motion
3) Analyse the motion to understand what's happened
4) Move the head or subject to look at the moving item (or follow it)
5) Perform some other action on movement if required or feedback what we are doing to a central core (brain)


There you go now you know what to do...off you go and write one :-)  okay to save you a months work you can download mine.

Capturing Video

The VCS (Vision Control Software) opens any connected USB webcam and takes a stream from there. The default resolution is 640x480 and the more expensive the web cam you have the better the definition and frame rate you will get. I'd not go above 640x480 as you don't really need too. The software uses VFW and is in C#

Motion and Movement Detection in C#

Motion detection is accomplished by comparing each video frame (a stream of still images) to the last to look for movement / changes in real time. A video stream is just a series of still picture just like an 19th century picture card book. 

Once VCS has a stream it looks for areas that have moved above a certain size and then joins them together to form a moving area. Once it has this area the VCS then morphs it to a circle and finds the centre. This centre then forms the red dot target and the X and Y coordinates are stored for tracking.

There are some good resources for motion and video handling using OpenGL or AForge.

Understand what's changed / motion

The nesxt step after detecting somekind of change is to decide if we need to do anything, if so what and also if we see anything we recognise. For the purpose of robot head movement we simply need to decide if an object is away from the center region and if move the head so that it appears central. The static region that is a non-motion zone is called the vision dead zone and is set by default to the 100 centre pixels  ie a column at 320px +- 50 (ie 270 to 370). If motion happens here, r2d2 does nothing on the X axis (Horizontal / Left / Right).

Moving the head and eye / interfacing in the physical world.

For this I have created two class libraries, one for the Polou Maestro 6/12/18 and 24  (costs about £20) and one for the Stepper Bee Plus (StepperBee+) which is a heavier (7amp) stepper motor controller that costs about £50. THe VCS can interface with both at the same time should you need to create something big or have two heads !

The Pololu Maestro


The StepperBee+

...to be continued











http://Three-Shop.com



No comments:

Post a Comment