如何查看RGB888格式的数据文件

昇腾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])

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值