Пример #1
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])
Пример #2
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])
Пример #3
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()