diff --git a/usr/openmv-ide.py b/usr/openmv-ide.py index 0aed01915..b1a66227b 100755 --- a/usr/openmv-ide.py +++ b/usr/openmv-ide.py @@ -483,8 +483,8 @@ class OMVGtk: return True if fb: - # create pixbuf from RGB888 - self.pixbuf =gtk.gdk.pixbuf_new_from_data(fb[2], gtk.gdk.COLORSPACE_RGB, False, 8, fb[0], fb[1], fb[0]*3) + # 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(); @@ -677,7 +677,6 @@ class OMVGtk: pass self.save_config() - # exit sys.exit(0) diff --git a/usr/openmv.py b/usr/openmv.py index 4bb770dbe..47a32045b 100755 --- a/usr/openmv.py +++ b/usr/openmv.py @@ -9,7 +9,7 @@ import struct import sys,time import serial import platform -from array import array +import numpy as np from PIL import Image #import pydfu on Linux @@ -48,9 +48,6 @@ def init(serial): global __serial __serial = serial -def _rgb(rgb): - return struct.pack("BBB", ((rgb & 0xF800)>>11)*255/31, ((rgb & 0x07E0)>>5)*255/63, (rgb & 0x001F)*255/31) - def fb_size(): # read fb header __serial.write(struct.pack(">11)*255.0/31.0).astype(np.uint8) + g = (((arr & 0x07E0) >>5) *255.0/63.0).astype(np.uint8) + b = (((arr & 0x001F) >>0) *255.0/31.0).astype(np.uint8) + buff = np.column_stack((r,g,b)) else: # JPEG try: - buff = Image.frombuffer("RGB", (size[0], size[1]), buff, "jpeg", "RGB", "").tostring() + buff = np.asarray(Image.frombuffer("RGB", size[0:2], buff, "jpeg", "RGB", "")) except Exception as e: - #print ("JPEG decode error (%s)"%(e)) + print ("JPEG decode error (%s)"%(e)) return None - if (len(buff) != (size[0]*size[1]*3)): - return None + if (buff.size != (size[0]*size[1]*3)): + return None - return (size[0], size[1], buff) + return (size[0], size[1], buff.reshape((size[1], size[0], 3))) def fb_update(): __serial.write(struct.pack("