Exemplo n.º 1
0
    def update_drawing(self):
        if (not self.connected):
            return True

        try:
            # read drawingarea
            fb = openmv.fb_dump()
        except Exception as e:
            self.disconnect()
            self._update_title()
            print("%s"%(e))
            return True

        if fb:
            # create pixbuf from np array
            self.pixbuf = gtk.gdk.pixbuf_new_from_array(fb[2], gtk.gdk.COLORSPACE_RGB, 8)
            self.pixbuf = self.pixbuf.scale_simple(fb[0]*SCALE, fb[1]*SCALE, gtk.gdk.INTERP_BILINEAR)

            self.drawingarea.realize();
            cm = self.drawingarea.window.get_colormap()
            gc = self.drawingarea.window.new_gc(foreground=cm.alloc_color('#FFFFFF',True,False))

            self.drawingarea.set_size_request(fb[0]*SCALE, fb[1]*SCALE)
            self.drawingarea.window.draw_pixbuf(gc, self.pixbuf, 0, 0, 0, 0)
            if self.selection_started or self.da_menu.flags() & gtk.MAPPED:
                self.drawingarea.window.draw_rectangle(gc, False, self.x1, self.y1, self.x2-self.x1, self.y2-self.y1)

        return True
Exemplo n.º 2
0
    def update_drawing(self):
        fb = None
        if (self.enable_fb and self.connected):
            try:
                # read drawingarea
                fb = openmv.fb_dump()
            except Exception as e:
                self.disconnect()
                self._update_title()
                return True
        if fb:
            self.fb = fb
            # If preview is disabled, don't read any more frames.
            # This needs to be set here, after reading a valid frame,
            # to ensure that fb_request flag is cleared in firmware.
            if self.disable_fb_request:
                self.enable_fb = False
        else:
            fb = self.fb

        if fb:
            # create pixbuf from np array
            self.pixbuf = gtk.gdk.pixbuf_new_from_array(fb[2], gtk.gdk.COLORSPACE_RGB, 8)
            self.pixbuf = self.pixbuf.scale_simple(fb[0]*SCALE, fb[1]*SCALE, gtk.gdk.INTERP_BILINEAR)

            self.drawingarea.realize();
            cm = self.drawingarea.window.get_colormap()
            gc = self.drawingarea.window.new_gc(foreground=cm.alloc_color('#FFFFFF',True,False))

            self.drawingarea.set_size_request(fb[0]*SCALE, fb[1]*SCALE)
            self.drawingarea.window.draw_pixbuf(gc, self.pixbuf, 0, 0, 0, 0)
            if self.selection_started or self.da_menu.flags() & gtk.MAPPED:
                self.drawingarea.window.draw_rectangle(gc, False, self.x1, self.y1, self.x2-self.x1, self.y2-self.y1)

        return True
Exemplo n.º 3
0
    def update_drawing(self):
        # read drawingarea
        fb = openmv.fb_dump()

        if fb:
            # convert to RGB888 and blit
            self.pixbuf = gtk.gdk.pixbuf_new_from_array(
                fb[2].reshape((fb[1], fb[0], 3)), gtk.gdk.COLORSPACE_RGB, 8)
            self.pixbuf = self.pixbuf.scale_simple(fb[0] * SCALE,
                                                   fb[1] * SCALE,
                                                   gtk.gdk.INTERP_BILINEAR)

            self.drawingarea.realize()
            cm = self.drawingarea.window.get_colormap()
            gc = self.drawingarea.window.new_gc(
                foreground=cm.alloc_color('#FFFFFF', True, False))

            self.drawingarea.set_size_request(fb[0] * SCALE, fb[1] * SCALE)
            self.drawingarea.window.draw_pixbuf(gc, self.pixbuf, 0, 0, 0, 0)
            if self.selection_started or self.da_menu.flags() & gtk.MAPPED:
                self.drawingarea.window.draw_rectangle(gc, False, self.x1,
                                                       self.y1,
                                                       self.x2 - self.x1,
                                                       self.y2 - self.y1)
        return True
Exemplo n.º 4
0
    def update_drawing(self):
        if (not self.connected):
            return True

        try:
            # read drawingarea
            fb = openmv.fb_dump()
        except Exception, e:
            self.disconnect()
            self._update_title()
            return True
Exemplo n.º 5
0
    def do_process(self):
        try:
            b = openmv.fb_dump()
        except (IOError, USBError) as e:
            print 'ImageUpdater error: %s' % e
            self.error.emit(e)
        else:
            if b:
                w = b[0]
                h = b[1]
                self.buff = b[2]
                stride = w * 3

                self.img = QImage(self.buff, w, h, stride, QImage.Format_RGB888)
                self.update.emit(self.img)
Exemplo n.º 6
0
    def update_drawing(self):
        # read drawingarea
        fb = openmv.fb_dump()

        if fb:
            # convert to RGB888 and blit
            self.pixbuf = gtk.gdk.pixbuf_new_from_array(fb[2].reshape((fb[1], fb[0], 3)), gtk.gdk.COLORSPACE_RGB, 8)
            self.pixbuf = self.pixbuf.scale_simple(fb[0]*SCALE, fb[1]*SCALE, gtk.gdk.INTERP_BILINEAR)

            self.drawingarea.realize();
            cm = self.drawingarea.window.get_colormap()
            gc = self.drawingarea.window.new_gc(foreground=cm.alloc_color('#FFFFFF',True,False))

            self.drawingarea.set_size_request(fb[0]*SCALE, fb[1]*SCALE)
            self.drawingarea.window.draw_pixbuf(gc, self.pixbuf, 0, 0, 0, 0)
            if self.selection_started or self.da_menu.flags() & gtk.MAPPED:
                self.drawingarea.window.draw_rectangle(gc, False, self.x1, self.y1, self.x2-self.x1, self.y2-self.y1)
        return True
Exemplo n.º 7
0
# init pygame
pygame.init()

# init openmv
openmv.init()

# init screen
running = True
Clock = pygame.time.Clock()
font = pygame.font.SysFont("monospace", 15)
while running:
    Clock.tick(60)

    # read framebuffer
    fb = openmv.fb_dump()

    if fb == None:
        continue

    # create image from RGB888
    image = pygame.image.frombuffer(fb[2].flat[0:], (fb[0], fb[1]), "RGB")
    # TODO check if res changed
    screen = pygame.display.set_mode((fb[0], fb[1]), pygame.DOUBLEBUF, 32)

    # blit stuff
    screen.blit(image, (0, 0))
    screen.blit(font.render("FPS %.2f" % (Clock.get_fps()), 1, (255, 0, 0)), (0, 0))

    # update display
    pygame.display.flip()
Exemplo n.º 8
0
# init pygame
pygame.init()

# init openmv
openmv.init()

# init screen
running = True
Clock = pygame.time.Clock()
font = pygame.font.SysFont("monospace", 15)
while running:
    Clock.tick(60)

    # read framebuffer
    fb = openmv.fb_dump()

    if fb == None:
        continue

    # create image from RGB888
    image = pygame.image.frombuffer(fb[2].flat[0:], (fb[0], fb[1]), 'RGB')
    # TODO check if res changed
    screen = pygame.display.set_mode((fb[0], fb[1]), pygame.DOUBLEBUF, 32)

    # blit stuff
    screen.blit(image, (0, 0))
    screen.blit(font.render("FPS %.2f"%(Clock.get_fps()), 1, (255, 0, 0)), (0, 0))

    # update display
    pygame.display.flip()