程序我是单片机摄像头拍摄的rgb565图片数据用串口发送到电脑后转换使用的
github地址:Hengbote/RGB565-jpeg (github.com)
这是处理单张图像的
from PIL import Image, ImageDraw
import os
# 定义图像大小
w = 320 # 宽
h = 240 # 高
input_path = os.getcwd() + "\\2.txt" # 源文件路径
output_path = os.getcwd() + "\\out.jpeg" # 输出文件名称
# 此函数将RGB565格式的颜色值转换为RGB888格式的颜色值
def convert_rgb565_to_rgb888(hex_value: int) -> tuple:
r = (hex_value & 0xF800) >> 8
g = (hex_value & 0x07E0) >> 3
b = (hex_value & 0x001F) << 3
return r, g, b
#读取输入文件的内容,并去除空格
with open(input_path, encoding="utf-8") as f:
file_content = f.read().replace(" ", "")
#计算输入文件的长度,并输出文件信息
input_length = (len(file_content) // 4) # 输入文件大小
print(f"定义图像大小: {w * h}, 输入文件大小: {input