Is there a basic image reader module in default Pi Python 2 setup?
I'm just looking to reading in a image - reduce it in size to 8x8 and display it on a Unicorn Hat
Simon
Not that I'm aware of...simplesi wrote:I was wondering if there was anything basic that is installed by default?
Pygame doesn't need installing with python 2.7, is that what you mean or do you mean installing even a python program?simplesi wrote:I need (want) a module that doesn't need installing by the user for ScratchGPO to read in an image and then display it on a led matrix
Its just occured to me that maybe I bodge things by calling bash image commands
Simon
Code: Select all
if self.bFindValue('image'):
subprocess.Popen(['convert', '-resize', '8x8!', '+matte', '/home/pi/sghdev/scratch_gpio/' +self.value , '/home/pi/sghdev/scratch_gpio/sghimage.bmp'])
# When reading a binary file, always add a 'b' to the file open mode
with open('sghimage.bmp', 'rb') as f:
#with open(self.value + '.bmp', 'rb') as f:
# BMP files store their width and height statring at byte 18 (12h), so seek
# to that position
f.seek(10)
# The width and height are 4 bytes each, so read 8 bytes to get both of them
bytes = f.read(4)
# Here, we decode the byte array from the last step. The width and height
# are each unsigned, little endian, 4 byte integers, so they have the format
# code '<II'. See http://docs.python.org/3/library/struct.html for more info
bmpdata = int(struct.unpack('<I', bytes)[0])
print bmpdata
# Print the width and height of the image
print('Data starts at: ' + str(bmpdata))
#print('Image height: ' + str(size[1]))
f.seek(bmpdata)
for i in range(0,64):
bytes = f.read(3)
pixel = struct.unpack('BBB', bytes)#[0]
#pixel = struct.unpack('<I', bytes)[0]
print i,pixel
self.matrixBlue,self.matrixGreen,self.matrixRed = pixel
ym = int(int(i) / 8)
xm = i % 8
#print "xm,ym" ,xm,ym
#print self.matrixRed,self.matrixGreen,self.matrixBlue
#print self.matrixMult,self.matrixLimit,self.matrixRangemax,led, ym, ym
UH.set_pixel(xm,7 - ym,self.matrixRed,self.matrixGreen,self.matrixBlue)
UH.show() Code: Select all
bytes = f.read(192)
pixel = struct.unpack('192B', bytes)
pixel = numpy.array(pixel).reshape(8, 8, 3)
for i, p in enumerate(pixel):
for j, pp in enumerate(p[::-1]):
UH.set_pixel(i, j, pp[0], pp[1], pp[2])Code: Select all
bytes = f.read(192)
pixel = struct.unpack('192B', bytes)
print "pixel",pixel
for i in range(0,64):
UH.set_pixel( i % 8, 7 - (i // 8), pixel[(i * 3) +2], pixel[(i * 3) +1], pixel[(i * 3) +0])