昇腾Ascend 310和310p处理器生成的RGB888格式的数据文件,需要转化为Bmp格式后才能在电脑端正常查看
下面是通过Python3自带的PIL图像处理库将RGB888格式的原始数据转换为Bmp格式的图像文件的方法
该程序带4个参数:输入文件名 宽度 高度 输出文件名
python3 raw2bmp.py resize_out_1280x720.rgb 1280 720 resize_out_1280x720.bmp
参考资料:
Concepts — Pillow (PIL Fork) 9.1.1 documentation
raw2bmp.py源代码如下:
# importing image object from PIL
from PIL import Image
import sys
if __name__ == "__main__":
if (len(sys.argv) != 5):
print('Usage: python3 raw2bmp.py out.1920x1080.rgb 1920 1080 out.1920x1080.bmp')
sys.exit()
file = open(sys.argv[1], 'rb')
rawData = file.read()
file.close()
imgSize = (int(sys.argv[2]), int(sys.argv[3]))
# Use the PIL raw decoder to read the data.
im = Image.frombytes("RGB", imgSize, rawData)
# Save to file
im.save(sys.argv[4])