Exemplo 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()
Exemplo n.º 2
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()
Exemplo n.º 3
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()
Exemplo n.º 4
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])
Exemplo n.º 5
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])
Exemplo n.º 6
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()