Esempio n. 1
0
class StereoCamera(Camera):
    """
   """
    def __init__(self, leftcamera, rightcamera):
        """
      Stereo Vision.
      """
        self._leftcamera = leftcamera
        self._rightcamera = rightcamera
        self._dev = Stereo(self._leftcamera._dev, self._rightcamera._dev)
        self.vision = VisionSystem()
        self._dev.setRGB(leftcamera.rgb[0], leftcamera.rgb[1],
                         leftcamera.rgb[2])
        self.rgb = leftcamera.rgb
        self.format = leftcamera.format
        self.vision.registerCameraDevice(self._dev)
        self._cbuf = self.vision.getMMap()
        ## -------------------------------------------------
        Camera.__init__(self, self._dev.getWidth(), self._dev.getHeight(),
                        self._dev.getDepth(), "Stereo Camera")
        self.data = CBuffer(self._cbuf)

    def update(self):
        if not self.active: return
        self._dev.updateMMap()
        self.processAll()
Esempio n. 2
0
class StereoCamera(Camera):
   """
   """
   def __init__(self, leftcamera, rightcamera):
      """
      Stereo Vision.
      """
      self._leftcamera = leftcamera
      self._rightcamera = rightcamera
      self._dev = Stereo( self._leftcamera._dev, self._rightcamera._dev)
      self.vision = VisionSystem()
      self._dev.setRGB(leftcamera.rgb[0], leftcamera.rgb[1], leftcamera.rgb[2])
      self.rgb = leftcamera.rgb
      self.format = leftcamera.format
      self.vision.registerCameraDevice(self._dev)
      self._cbuf = self.vision.getMMap()
      ## -------------------------------------------------
      Camera.__init__(self, self._dev.getWidth(), self._dev.getHeight(), self._dev.getDepth(),
                      "Stereo Camera")
      self.data = CBuffer(self._cbuf)

   def update(self):
      if not self.active: return
      self._dev.updateMMap()
      self.processAll()
Esempio n. 3
0
class FourwayCamera(Camera):
   """
   """
   def __init__(self, camera, splits, quad, rot = 0):
      """
      Can split a camera 2 or 4 ways.
      """
      self._camera = camera
      self._splits = splits
      self._quad   = quad
      self._dev = Fourway( self._camera._dev, splits, quad, rot)
      self.vision = VisionSystem()
      self._dev.setRGB(camera.rgb[0], camera.rgb[1], camera.rgb[2])
      self.rgb = camera.rgb
      self.format = camera.format
      self.vision.registerCameraDevice(self._dev)
      self._cbuf = self.vision.getMMap()
      ## -------------------------------------------------
      Camera.__init__(self, self._dev.getWidth(), self._dev.getHeight(), self._dev.getDepth(),
                      "Quad #%d" % quad)
      self.data = CBuffer(self._cbuf)

   def update(self):
      if not self.active: return
      self._dev.updateMMap()
      self.processAll()
Esempio n. 4
0
 def __init__(self, width, height, depth):
     self.width = width
     self.height = height
     self.depth = depth
     self._dev = Fake("", self.width, self.height, self.depth)
     self.vision = VisionSystem()
     self.vision.registerCameraDevice(self._dev)
     self._cbuf = self.vision.getMMap()
     # -------------------------------------------------
     self.rgb = (0, 1, 2)  # offsets to RGB
     self.format = "RGB"
     Camera.__init__(self, self.width, self.height, self.depth,
                     "Fake Camera View")
     self.subtype = "simulated"
     self.data = CBuffer(self._cbuf)
Esempio n. 5
0
 def __init__(self, robot, visionSystem):
     self.robot = robot
     self.width = 320
     self.height = 240
     self.depth = 3
     self._dev = Fake("", self.width, self.height, self.depth)
     self.vision = VisionSystem()
     self.vision.registerCameraDevice(self._dev)
     self._cbuf = self.vision.getMMap()
     # -------------------------------------------------
     self.rgb = (0, 1, 2)  # offsets to RGB
     self.format = "RGB"
     Camera.__init__(self, self.width, self.height, self.depth,
                     "Rovio Camera View")
     self.subtype = "rovio"
     self.data = CBuffer(self._cbuf)
Esempio n. 6
0
 def __init__(self, leftcamera, rightcamera):
     """
   Stereo Vision.
   """
     self._leftcamera = leftcamera
     self._rightcamera = rightcamera
     self._dev = Stereo(self._leftcamera._dev, self._rightcamera._dev)
     self.vision = VisionSystem()
     self._dev.setRGB(leftcamera.rgb[0], leftcamera.rgb[1],
                      leftcamera.rgb[2])
     self.rgb = leftcamera.rgb
     self.format = leftcamera.format
     self.vision.registerCameraDevice(self._dev)
     self._cbuf = self.vision.getMMap()
     ## -------------------------------------------------
     Camera.__init__(self, self._dev.getWidth(), self._dev.getHeight(),
                     self._dev.getDepth(), "Stereo Camera")
     self.data = CBuffer(self._cbuf)
Esempio n. 7
0
def INIT(robot):
    return {
        "camera":
        FakeCamera(pattern="vision/iarc2006/fiducial-?.ppm",
                   start=1,
                   stop=5,
                   interval=1,
                   visionSystem=VisionSystem())
    }
def INIT(robot):
    return {
        "camera":
        FakeCamera(pattern="vision/blimp/bullseye-?.pbm",
                   start=1,
                   stop=5,
                   interval=1,
                   visionSystem=VisionSystem())
    }
def INIT(robot):
    return {
        "camera":
        FakeCamera(pattern="vision/tutorial2/?.ppm",
                   start=1,
                   stop=10,
                   interval=1,
                   visionSystem=VisionSystem())
    }
Esempio n. 10
0
 def setup(self):
     self.imageCount = 1
     if not self.robot.hasA("camera"):
         self.robot.startDevice("Frequency")
         self.robot.startDevice({
             "camera":
             V4LCamera(640, 480, channel=0, visionSystem=VisionSystem())
         })
         self.robot.startDevice(setupFourway(self.robot))
         self.robot.camera[3].addFilter("grayScale")
Esempio n. 11
0
def INIT(robot):
    if robot.name == "Aria":
        # Pioneers. You may have to set channel by hand to one that works
        ch = 0  # channel
    else:
        # For framegrabbers:
        # Channel -  0: television; 1: composite; 2: S-Video
        ch = 1  # channel
    return {
        "camera":
        V4LGrabber(160,
                   120,
                   device="/dev/video0",
                   channel=ch,
                   visionSystem=VisionSystem()),
        "camera":
        V4LGrabber(160,
                   120,
                   device="/dev/video1",
                   channel=ch,
                   visionSystem=VisionSystem())
    }
Esempio n. 12
0
 def __init__(self, width, height, depth):
    self.width = width
    self.height = height
    self.depth = depth
    self._dev = Fake("", self.width, self.height, self.depth)
    self.vision = VisionSystem()
    self.vision.registerCameraDevice(self._dev)
    self._cbuf = self.vision.getMMap()
    # -------------------------------------------------
    self.rgb = (0, 1, 2) # offsets to RGB
    self.format = "RGB"
    Camera.__init__(self, self.width, self.height, self.depth,
                    "Fake Camera View")
    self.subtype = "simulated"
    self.data = CBuffer(self._cbuf)
Esempio n. 13
0
def INIT(robot):
    retval = ask("Please enter the parameters for the Video4Linux Camera",
                 (("Device", "/dev/video0"),
                  ("Width", "160"),
                  ("Height", "120"),
                  ("Channel", "0"),                  
                  ))
    if retval["ok"]:
        return {"camera" : V4LCamera( int(retval["Width"]), 
                                      int(retval["Height"]), 
                                      device = retval["Device"],
                                      channel = int(retval["Channel"]), 
                                      visionSystem = VisionSystem())}
    else:
        raise "Cancelled!"
Esempio n. 14
0
 def __init__(self, leftcamera, rightcamera):
    """
    Stereo Vision.
    """
    self._leftcamera = leftcamera
    self._rightcamera = rightcamera
    self._dev = Stereo( self._leftcamera._dev, self._rightcamera._dev)
    self.vision = VisionSystem()
    self._dev.setRGB(leftcamera.rgb[0], leftcamera.rgb[1], leftcamera.rgb[2])
    self.rgb = leftcamera.rgb
    self.format = leftcamera.format
    self.vision.registerCameraDevice(self._dev)
    self._cbuf = self.vision.getMMap()
    ## -------------------------------------------------
    Camera.__init__(self, self._dev.getWidth(), self._dev.getHeight(), self._dev.getDepth(),
                    "Stereo Camera")
    self.data = CBuffer(self._cbuf)
Esempio n. 15
0
    def startDeviceBuiltin(self, item, index=0):
        if item == "laser":
            return {"laser": PlayerLaserDevice(self._client)}
        elif item == "sonar":
            return {"sonar": PlayerSonarDevice(self._client)}
        elif item == "camera":
            from pyrobot.camera.player import PlayerCamera
            from pyrobot.vision.cvision import VisionSystem
            camera = PlayerCamera(self.hostname,
                                  self.port,
                                  visionSystem=VisionSystem())
            return {"camera": camera}
        elif item == "fiducial":
            return {"fiducial": PlayerFiducialDevice(self._client)}
        elif item == "gripper":
            return {"gripper": PlayerGripperDevice(self._client)}
        elif item == "position":
            return {"position": PlayerPositionDevice(self._client)}
        elif item == "speech":
            return {"speech": PlayerSpeechDevice(self._client)}
        elif item == "graphics2d":
            return {"graphics2d": PlayerGraphics2dDevice(self._client)}
        elif item == "map":
            return {"map": PlayerMapDevice(self._client)}
        elif item == "simulation":
            obj = None
            try:
                obj = PlayerSimulationDevice(self.hostname)
            except:
                pass
            return {"simulation": obj}
        elif item == "ptz":
            return {"ptz": PlayerPTZDevice(self._client, "ptz")}
        elif item == "bumper":
            return {"bumper": PlayerBumperDevice(self._client)}


##         elif item == "camera":
##             if self.simulated:
##                 return self.startDevice("BlobCamera", visible=0)
##             else:
##                 return self.startDevice("V4LCamera")
##        elif item in self.builtinDevices:
        return {item: PlayerDevice(self._client, item, index=index)}
Esempio n. 16
0
def INIT(robot):
    return {
        "camera": V4LCamera(160, 120, channel=1, visionSystem=VisionSystem())
    }
Esempio n. 17
0
            self.start = self.oldStart
            self.oldStart = None
            self.oldStop = None

    def update(self):
        if not self.active: return
        if (self.current < self.stop):
            currentTime = time.time()
            if currentTime - self.lastUpdate > self.interval:
                if self.match:
                    currname = self.pattern[:self.match.start()] + \
                               self.fstring % self.current + \
                               self.pattern[self.match.end():]
                else:
                    currname = self.pattern
                if self.verbose:
                    print("info: reading file '%s'..." %
                          (self.path + currname))
                self._dev.updateMMap(self.path + currname)
                self.processAll()
                self.current += 1
                self.lastUpdate = currentTime
        else:
            self.current = self.start


if __name__ == "__main__":
    from pyrobot.vision.cvision import VisionSystem
    camera = FakeCamera(visionSystem=VisionSystem())
    camera.update()
Esempio n. 18
0
def INIT(robot):
    return {"camera": RobocupCamera(robot, visionSystem=VisionSystem())}
Esempio n. 19
0
def INIT(robot):
    return {"camera": FakeCamera(visionSystem=VisionSystem())}
Esempio n. 20
0
        self.depth = self.vision.getDepth()
        self._cbuf = self.vision.getMMap()
        self.data = CBuffer(self._cbuf)
        self.rgb = (0, 1, 2)  # offsets to RGB
        self.format = "RGB"
        Camera.__init__(self,
                        self.width,
                        self.height,
                        self.depth,
                        "Rovio Camera View",
                        async=1)
        self.subtype = "rovio"
        self.data = CBuffer(self._cbuf)

    def update(self):
        """
       This is called very often, or as fast as possible.
       """
        if not self.active: return
        self._dev.updateMMap(1)  # read and map very often
        self.processAll()  # need to process filters


if __name__ == "__main__":
    from pyrobot.vision.cvision import VisionSystem

    class MyRobot:
        theurl = "http://liquidsoapdispenser.com/rovio/treo_cam.jpg"

    camera = RovioCamera(MyRobot(), VisionSystem())
Esempio n. 21
0
        self.depth = self.vision.getDepth()
        self._cbuf = self.vision.getMMap()
        self.data = CBuffer(self._cbuf)
        self.rgb = (0, 1, 2)  # offsets to RGB
        self.format = "RGB"
        Camera.__init__(self, self.width, self.height, self.depth,
                        "Aibo Camera View")
        self.subtype = "aibo"
        self.data = CBuffer(self._cbuf)

    def update(self):
        """
       This is called very often, or as fast as possible.
       """
        if not self.active: return
        self._dev.updateMMap(1)  # read and map very often
        self.processAll()  # need to process filters


if __name__ == "__main__":
    from pyrobot.vision.cvision import VisionSystem

    class MyRobot:
        host = "k-8"
        PORT = {"Raw Cam Server": 10011}

        def setRemoteControl(self, *args):
            pass

    camera = AiboCamera(MyRobot(), VisionSystem())
Esempio n. 22
0
class ManualFakeCamera(Camera):
   """
   camera = ManualFakeCamera(w, h, d)

   Used when you are creating the image from Python, and wish
   to have the camera class show or manipulate the image.

   Currently only depth 3 works.

   Values in camera array are ints between 0 and 255.
   """
   def __init__(self, width, height, depth):
      self.width = width
      self.height = height
      self.depth = depth
      self._dev = Fake("", self.width, self.height, self.depth)
      self.vision = VisionSystem()
      self.vision.registerCameraDevice(self._dev)
      self._cbuf = self.vision.getMMap()
      # -------------------------------------------------
      self.rgb = (0, 1, 2) # offsets to RGB
      self.format = "RGB"
      Camera.__init__(self, self.width, self.height, self.depth,
                      "Fake Camera View")
      self.subtype = "simulated"
      self.data = CBuffer(self._cbuf)

   def blankImage(self, val=0):
      for w in range(self.width):
         for h in range(self.height):
            for d in range(self.depth):
               self.vision.setVal(w, h, d, val)

   def setGrayImage(self, array):
      """
      Will set the RGB camera image from a grayscale array (depth 1)
      assuming column major order.
      """
      for w in range(self.width):
         for h in range(self.height):
            val = array[h * self.width + w]
            for d in range(self.depth):
               self.vision.setVal(w, h, d, val)

   def setRGBImage(self, array):
      """
      Will set the RGB camera image from a RGB array (depth 3)
      assuming column major order.
      """
      for w in range(self.width):
         for h in range(self.height):
            for d in range(self.depth):
               self.vision.setVal(w, h, d, array[(w + h * self.width) * self.depth + d])

   def setRGB3Image(self, array):
      """
      Will set the RGB camera image from a RGB array (depth 3)
      assuming column major order.
      """
      for w in range(self.width):
         for h in range(self.height):
            for d in range(self.depth):
               self.vision.setVal(w, h, d, array[w][h][d])
Esempio n. 23
0
class RovioCamera(Camera):
    """
   camera = RovioCamera()
   """
    def __init__(self, robot, visionSystem):
        self.robot = robot
        self.width = 320
        self.height = 240
        self.depth = 3
        self._dev = Fake("", self.width, self.height, self.depth)
        self.vision = VisionSystem()
        self.vision.registerCameraDevice(self._dev)
        self._cbuf = self.vision.getMMap()
        # -------------------------------------------------
        self.rgb = (0, 1, 2)  # offsets to RGB
        self.format = "RGB"
        Camera.__init__(self, self.width, self.height, self.depth,
                        "Rovio Camera View")
        self.subtype = "rovio"
        self.data = CBuffer(self._cbuf)

    def blankImage(self, val=0):
        for w in range(self.width):
            for h in range(self.height):
                for d in range(self.depth):
                    self.vision.setVal(w, h, d, val)

    def setGrayImage(self, array):
        """
      Will set the RGB camera image from a grayscale array (depth 1)
      assuming column major order.
      """
        for w in range(self.width):
            for h in range(self.height):
                val = array[h * self.width + w]
                for d in range(self.depth):
                    self.vision.setVal(w, h, d, val)

    def setRGBImage(self, array):
        """
      Will set the RGB camera image from a RGB array (depth 3)
      assuming column major order.
      """
        for w in range(self.width):
            for h in range(self.height):
                for d in range(self.depth):
                    self.vision.setVal(
                        w, h, d, array[(w + h * self.width) * self.depth + d])

    def setRGB3Image(self, array):
        """
      Will set the RGB camera image from a RGB array (depth 3)
      assuming column major order.
      """
        for w in range(self.width):
            for h in range(self.height):
                for d in range(self.depth):
                    self.vision.setVal(w, h, d, array[w][h][d])

    def update(self):
        self.robot.camLock.acquire()
        if not self.active: return
        import PIL.Image as PyImage
        import array
        self.processAll()
        filename = "/home/rwalker1/research/test.jpg"
        width = 352
        height = 288
        #fp = open(filename, "r")
        #fp = self.robot.imageGrab()
        #image = PyImage.open(fp)
        image = PyImage.open(filename)
        width, height = image.size
        pixels = image.load()
        for w in range(width):
            for h in range(height):
                r, g, b = pixels[w, h]
                self.vision.setVal(w, h, 0, r)
                self.vision.setVal(w, h, 1, g)
                self.vision.setVal(w, h, 2, b)
        self.robot.camLock.release()
Esempio n. 24
0
def INIT(robot):
    return {
        "camera": V4LCamera(640, 480, channel=0, visionSystem=VisionSystem())
    }
Esempio n. 25
0
def INIT(robot):
    return {"camera": BT848Camera(160, 120, visionSystem=VisionSystem())}
Esempio n. 26
0
      self._dev = Fourway( self._camera._dev, splits, quad, rot)
      self.vision = VisionSystem()
      self._dev.setRGB(camera.rgb[0], camera.rgb[1], camera.rgb[2])
      self.rgb = camera.rgb
      self.format = camera.format
      self.vision.registerCameraDevice(self._dev)
      self._cbuf = self.vision.getMMap()
      ## -------------------------------------------------
      Camera.__init__(self, self._dev.getWidth(), self._dev.getHeight(), self._dev.getDepth(),
                      "Quad #%d" % quad)
      self.data = CBuffer(self._cbuf)

   def update(self):
      if not self.active: return
      self._dev.updateMMap()
      self.processAll()

if __name__ == "__main__":
   from pyrobot.camera.fake import FakeCamera
   cam = FakeCamera(pattern = "../../vision/tutorial/test-?.ppm", start = 0,
                    stop = 11, interval = 1, visionSystem = VisionSystem())
   cam.update()
   cam.makeWindow()
   cam.updateWindow()
   cameras = [0] * 4
   for i in range(4):
      cameras[i] = FourwayCamera(cam, 4, i)
      cameras[i].update()
      cameras[i].makeWindow()
      cameras[i].updateWindow()
Esempio n. 27
0
class ManualFakeCamera(Camera):
    """
   camera = ManualFakeCamera(w, h, d)

   Used when you are creating the image from Python, and wish
   to have the camera class show or manipulate the image.

   Currently only depth 3 works.

   Values in camera array are ints between 0 and 255.
   """
    def __init__(self, width, height, depth):
        self.width = width
        self.height = height
        self.depth = depth
        self._dev = Fake("", self.width, self.height, self.depth)
        self.vision = VisionSystem()
        self.vision.registerCameraDevice(self._dev)
        self._cbuf = self.vision.getMMap()
        # -------------------------------------------------
        self.rgb = (0, 1, 2)  # offsets to RGB
        self.format = "RGB"
        Camera.__init__(self, self.width, self.height, self.depth,
                        "Fake Camera View")
        self.subtype = "simulated"
        self.data = CBuffer(self._cbuf)

    def blankImage(self, val=0):
        for w in range(self.width):
            for h in range(self.height):
                for d in range(self.depth):
                    self.vision.setVal(w, h, d, val)

    def setGrayImage(self, array):
        """
      Will set the RGB camera image from a grayscale array (depth 1)
      assuming column major order.
      """
        for w in range(self.width):
            for h in range(self.height):
                val = array[h * self.width + w]
                for d in range(self.depth):
                    self.vision.setVal(w, h, d, val)

    def setRGBImage(self, array):
        """
      Will set the RGB camera image from a RGB array (depth 3)
      assuming column major order.
      """
        for w in range(self.width):
            for h in range(self.height):
                for d in range(self.depth):
                    self.vision.setVal(
                        w, h, d, array[(w + h * self.width) * self.depth + d])

    def setRGB3Image(self, array):
        """
      Will set the RGB camera image from a RGB array (depth 3)
      assuming column major order.
      """
        for w in range(self.width):
            for h in range(self.height):
                for d in range(self.depth):
                    self.vision.setVal(w, h, d, array[w][h][d])
Esempio n. 28
0
def INIT(robot):
    return {
        "camera": PlayerCamera("localhost", 6665, visionSystem=VisionSystem())
    }
Esempio n. 29
0
        self.robot.camLock.acquire()
        if not self.active: return
        import PIL.Image as PyImage
        import array
        self.processAll()
        filename = "/home/rwalker1/research/test.jpg"
        width = 352
        height = 288
        #fp = open(filename, "r")
        #fp = self.robot.imageGrab()
        #image = PyImage.open(fp)
        image = PyImage.open(filename)
        width, height = image.size
        pixels = image.load()
        for w in range(width):
            for h in range(height):
                r, g, b = pixels[w, h]
                self.vision.setVal(w, h, 0, r)
                self.vision.setVal(w, h, 1, g)
                self.vision.setVal(w, h, 2, b)
        self.robot.camLock.release()


if __name__ == '__main__':
    x = RovioRobot('10.0.0.9')
    x.update()
    x.move(1, 0)
    from pyrobot.vision.cvision import VisionSystem
    camera = RovioCamera(x, visionSystem=VisionSystem())
    camera.update()
Esempio n. 30
0
        self.format = camera.format
        self.vision.registerCameraDevice(self._dev)
        self._cbuf = self.vision.getMMap()
        ## -------------------------------------------------
        Camera.__init__(self, self._dev.getWidth(), self._dev.getHeight(),
                        self._dev.getDepth(), "Quad #%d" % quad)
        self.data = CBuffer(self._cbuf)

    def update(self):
        if not self.active: return
        self._dev.updateMMap()
        self.processAll()


if __name__ == "__main__":
    from pyrobot.camera.fake import FakeCamera
    cam = FakeCamera(pattern="../../vision/tutorial/test-?.ppm",
                     start=0,
                     stop=11,
                     interval=1,
                     visionSystem=VisionSystem())
    cam.update()
    cam.makeWindow()
    cam.updateWindow()
    cameras = [0] * 4
    for i in range(4):
        cameras[i] = FourwayCamera(cam, 4, i)
        cameras[i].update()
        cameras[i].makeWindow()
        cameras[i].updateWindow()
Esempio n. 31
0
def INIT(robot):
    return {"camera": AiboCamera(robot, visionSystem=VisionSystem())}
Esempio n. 32
0
      """
        self._dev = PlayerCam(host, port)
        # connect vision system: --------------------------
        self.vision = visionSystem
        self.vision.registerCameraDevice(self._dev)
        self.width = self.vision.getWidth()
        self.height = self.vision.getHeight()
        self.depth = self.vision.getDepth()
        self._cbuf = self.vision.getMMap()
        self.data = CBuffer(self._cbuf)
        self.rgb = (0, 1, 2)  # offsets to RGB
        self.format = "RGB"
        Camera.__init__(self, self.width, self.height, self.depth,
                        "Player Camera View")
        self.subtype = "player"
        self.data = CBuffer(self._cbuf)

    def update(self):
        if not self.active: return
        self._dev.updateMMap(1)  # read and map
        self.processAll()  # need to process filters


if __name__ == "__main__":
    from pyrobot.vision.cvision import VisionSystem
    camera = PlayerCamera("localhost", 6665, VisionSystem())
    camera.makeWindow()
    while 1:
        camera.update()
        camera.updateWindow()