UserPreferences

PyroModuleVision


$$$THIS IS NOW OUTDATED. SEE BELOW FOR UP-TO-DATE MODULES.$$$

Framegrabber Interface

Here is an example of the Video for Linux interface:

robot.startDevice("V4LCamera")   
image = self.robot.camera[0].image

There are many kinds of camera subtypes: blob, fake, and video4linux.

Using a Camera in Pyro

from pyrobot.brain import Brain 
import time

def saveListToFile(ls, file): 
    for i in range(len(ls)): 
        file.write(str(ls[i]) + " ") 
    file.write("\n")

def scaleList(ls, maxval):
    for i in range(len(ls)):
        ls[i] = ls[i] / (1.0 * maxval)
    return ls

class SampleImages(Brain):
    def setup(self):
        self.startDevice("V4LCamera")
        self.camera = self.robot.camera[0]
        print "done initializing camera"
        #to save image data in a nnet ready format, uncomment the following line
        #self.cameradat = open("camera.dat", "w")
        self.count = 0
        
    def step(self):
        if self.count < 10:
            self.camera.update()
            image = self.camera.getShrunkenImage(xscale = 0.5, mode = 'sample')
            #to save image data in a nnet ready format, uncomment the following line
            #saveListToFile(scaleList(image.data, 255), self.cameradat)
            #to save image data as ppm files, uncomment the following line
            image.saveToFile("image%d.ppm" % self.count)
            self.wander(0.9)
            time.sleep(0.3)
            self.stop()
            self.count += 1
            print "step", self.count
        else:
            print "done collecting samples"
            self.stop()
            #to save image data in a nnet ready format, uncomment the following line
            #self.cameradat.close()
            self.pleaseStop()
    
    def wander(self, minSide): 
        robot = self.robot
        front = min([s.value for s in self.robot.range["front"]])
        left = min([s.value for s in self.robot.range["front-left"]])
        right = min([s.value for s in self.robot.range["front-right"]])
        if front < minSide:
            robot.move(0,-0.3)
        elif left < minSide: 
            robot.move(0,-0.3) 
        elif right < minSide:
            robot.move(0,0.3) 
        else: 
            robot.move(0.2, 0)

def INIT(engine):
    return SampleImages('SampleImages', engine)

Some notes:

  1. The video4linux camera begins with dimensions 384 by 240. You may want to adjust that using shrunkenImage() and grayScale().

All cameras derive from PyroImage and Service, discussed below.

PyroImage Class

This page documents PyroImage, the main image class in Pyro.

This class has methods to do standard vision processing: blob detection and tracking, convolution, etc.

See pyrobot/vision/init.py for many examples.

from pyrobot.vision import *

PyroImage implements the following methods:

class PyroImage:
   def loadFromFile(filename):
   def saveToFile(filename):
   def shrink(self, xscale=0.5, yscale='unset', mode='average'):
   def getShrunkenImage(self, xscale=0.5, yscale='unset', mode='average'):
   def grayScale(self):
   def getGrayScale(self):
   def getColorFilter(self, r, g, b):
   def display(self):
   def set(self, x, y, val, offset = 0):
   def setVal(self, x, y, val):
   def get(self, x, y, offset = 0):
   def getVal(self, x, y):
   def reset(self, vector):
   def resetToColor(self,r,g,b):
   def incr(self, x, y, offset = 0):
   def cropPixels(self, l, t='unset', r='unset', b='unset'):
   def getBitmap(self, cutoff, cutoff2='unset', mode='brightness'):
   def histogram(self, cols = 20, rows = 20, initvals = 0):
   def convolve(self, convmask, bit = 0, threshold = 0):
   def swapPlanes(self, plane1, plane2):

class Histogram(PyroImage):
   def display(self):
   def compare(self, hist):

class Bitmap(PyroImage):
   def display(self):
   def avgColor(self, img):

class Point:
   def set(self, x, y):
   def setx(self, x):
   def sety(self, y):
   def clear(self):

class Blob:
   def addpixel(self, pixel):
   def joinblob(self, other):
   def width(self):
   def height(self):
   def area(self):
   def density(self):
   def display(self):

class Blobdata:
   def sort(self, mode="mass"):
   def display(self):

Pyro Modules Table of Contents

Modules

  1. PyroModuleIntroduction

  2. PyroModuleObjectOverview

  3. PyroModulePythonIntro

  4. PyroModuleDirectControl

  5. PyroModuleSequencingControl

  6. PyroModuleBehaviorBasedControl

  7. PyroModuleReinforcementLearning

  8. PyroModuleNeuralNetworks

  9. PyroModuleEvolutionaryAlgorithms

  10. PyroModuleComputerVision

  11. PyroModuleMapping

  12. PyroModuleMultirobot

  13. FurtherReading

Additional Resources

  1. PyroIndex

  2. PyroAdvancedTopics

  3. PyroUserManual

  4. [WWW]Pyro Tutorial Movies

Reference: PyroSiteNotes