32板子驱动OV7725是成功的,用串口将数据传送到PC端,用Python写的串口读取一帧的代码并显示该帧,即显示一张图片,不知为什么显示的老是错误的,下面部分代码,求各路大神指点错误,在下我不胜感激。读出来的图片也是全花的
Python代码:
import serial
from time import sleep
from PIL import Image
def parsergb565(byte1):
byte12 = int.from_bytes(byte1, byteorder='big', signed=False)
red =byte12 >> 11
green = (byte12 >> 5) & 0x3f
blue = byte12 & 0x1f
red *= 8
green *= 4
blue *= 8
return (red, green, blue)
def recv(serial):
data = serial.read(4)
'''while True:
data = serial.read(2)
if data == '':
continue
else:
break'''
#sleep(0.02)
return data
def read():
serial.write('1'.encode())
i=0
for x in range(0, 240):
for y in range(0, 320):
data = recv(serial)
print(data)
i = i+1
print(i)
color = parsergb565(data)
image.putpixel((x,y),color)
print("finsh")
image.show()
image.save("00.jpg")
if __name__ == '__main__':
image_width = 240
image_height = 320
serial = serial.Serial(
port='COM6',
baudrate=115200,
parity=serial.PARITY_NONE,#奇偶校验位
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=0.000000001)
if serial.isOpen() :
print("open success")
else :
print("open failed")
image = Image.new("RGB",(240,320))
read()
[color=rgb(0, 0, 0) !important]STM32F103部分代码
if(ov_sta)//有帧中断更新
{
LCD_Scan_Dir(U2D_L2R); //从上到下,从左到右
LCD_Set_Window((lcddev.width-OV7725_WINDOW_WIDTH)/2,(lcddev.height-OV7725_WINDOW_HEIGHT)/2,OV7725_WINDOW_WIDTH,OV7725_WINDOW_HEIGHT);//将显示区域设置到屏幕中央
if(lcddev.id==0X1963)
LCD_Set_Window((lcddev.width-OV7725_WINDOW_WIDTH)/2,(lcddev.height-OV7725_WINDOW_HEIGHT)/2,OV7725_WINDOW_HEIGHT,OV7725_WINDOW_WIDTH);//将显示区域设置到屏幕中央
LCD_WriteRAM_Prepare(); //开始写入GRAM
OV7725_RRST=0; //开始复位读指针
OV7725_RCK_L;
OV7725_RCK_H;
OV7725_RCK_L;
OV7725_RRST=1; //复位读指针结束
OV7725_RCK_H;
for(i=0;i<OV7725_WINDOW_HEIGHT;i++)
{
for(j=0;j<OV7725_WINDOW_WIDTH;j++)
{
OV7725_RCK_L;
color=GPIOC->IDR&0XFF; //读数据
OV7725_RCK_H;
color<<=8;
OV7725_RCK_L;
c=GPIOC->IDR&0XFF; //读数据
color = color|c;
OV7725_RCK_H;
printf("%X",color);
LCD->LCD_RAM=color;
}
}
ov_sta=0; //清零帧中断标记
ov_frame++;
LCD_Scan_Dir(DFT_SCAN_DIR); //恢复默认扫描方向
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>