Welcome! Log In Create A New Profile

Advanced

Python image conversion help

Posted by ls7u 
Python image conversion help
May 30, 2013 04:37PM
Hi im trying to make a module to be able to send images from a Raspberry pi to a BV469-G with lenny firmware using python.

Bellow is part of my python script that gets image RGB and writes it out to the display using pil image lib.

I have two problems im stuck on ...

1). I can't find away to send image Height / width infomation in 16bit.

2). I am able to make out the image on the display but theres it is repeated three times and the colours are not correct.

any help or advice will be great , as im not getting any further with this.

thanks

Luke









import Image
import StringIO
import serial



ser = serial.Serial('COM20', 2000000)  

def send_image(image):
	pixels = image.load()
	
	
	ser.write('dicls\r\n')    # send cmd to accept image
   
	time.sleep(1);
	
	

	
	ser.write(chr(image.size[1]))      # send Height info
	
	time.sleep(1);
	ser.write(chr(image.size[0]))		 # send width info
	
	
	
	
	time.sleep(1);

	 
	for y in xrange(image.size[1]):
		for x in xrange(image.size[0]):
			(r, g, b) = pixels[x, y]
			
			
         
			
	
			result = (r) |(g) |(b)
		
		
           
			ser.write(chr(result))











Re: Python image conversion help
May 30, 2013 06:45PM
Luke,
the BV4629_g is the older version of the (BV4629_V2) BV514 but the image format is the same, here is the actual code that reads the serial port and displays the image:

// ******************************************************************************
// load bitmap using binary input, I think this should work
// bitmap format:
// <height:H><heigh:L><width:H><width:L>
// <r><g><b>......
// ******************************************************************************
void IL_bitmap(unsigned char x, signed int y)
{
int j, height, width;
unsigned char c;
COLOUR colr;

  	IL_crSus(1);
	if(I2Cf) height=i2c1_get()*256; else height=getch()*256;		// high byte
	if(I2Cf) height+=i2c1_get(); else height+=getch();		// lowbyte

	if(I2Cf) width=i2c1_get()*256; else width=getch()*256;		// high byte
	if(I2Cf) width+=i2c1_get(); else width+=getch();		// lowbyte

	// basic check
	if(height > MAXy) height=MAXy;
	if(width > MAXx) width=MAXx;
	
	IL_setAddress(x,y);	// set position and global
	while(height--) {
		for(j=0;j<width;j++) {
			if(I2Cf) colr.r=i2c1_get(); else colr.r=getch();
			if(I2Cf) colr.g=i2c1_get(); else colr.g=getch();
			if(I2Cf) colr.b=i2c1_get(); else colr.b=getch(); 
			IL_pix(colr);
		}
		IL_setAddress(cPos.x,++cPos.y);
	}
	IL_crSus(0);
}
ignore the I2C stuff; as you can see 4 bytes are expected before the rgb information. The Python line:

ser.write(chr(image.size[1]))

will only send 1 integer or byte (I think), you need to split image.size[1] into its low and high bytes, possibly:
ser.write((image.size[1]) >> 8)
ser.write((image.size[1]) & 0xff)

Jim
Sorry, only registered users may post in this forum.

Click here to login