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()
STM32F103部分代码if(ov_sta)//有帧中断更新
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>