![]() |
|||||||
| [ Home ] | [ Software ] | [ Curriculum ] | [ Hardware ] | [ Community ] | [ News ] | [ Publications ] | [ Search ] |
|
THIS IS NOW OUTDATED. SEE BELOW FOR UP-TO-DATE MODULES.
Framegrabber InterfaceHere 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:
All cameras derive from PyroImage and Service, discussed below.
PyroImage ClassThis 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
Additional ResourcesReference: PyroSiteNotes
|
| [ Home ] | [ Software ] | [ Curriculum ] | [ Hardware ] | [ Community ] | [ News ] | [ Publications ] | [ Search ] |
View Wiki Source | Edit Wiki Source | Mail Webmaster | |||||||