raw文件与jpg文件的读取/转换/显示

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_41819299/article/details/82428950

⚠️cv2中为bgr,而matplotlib/imageio中为rgb

⚠️基本上基于np和cv2就可以实现了

注:.jpg到.raw 使用.tofile实现,图上忘写了

#jpg---raw
import  cv2
import numpy as np
rgbimg=cv2.imread('rgb.jpg')
print(rgbimg.dtype)#np.uint8
imgshape=rgbimg.shape
rgbimg.tofile('rgb_raw.raw')
#显示
# cv2.imshow('rgbimg',rgbimg)
# cv2.waitKey()

#raw--jpg
rawfile=np.fromfile('rgb_raw.raw',dtype=np.uint8)
rawfile.shape=imgshape
#rawfile.tofile('raw_jpg.jpg')##wrong
#方法一:
cv2.imwrite('rawtojpg.jpg',rawfile)
#方法二:
# import imageio
# imgData_rgb=rawfile[:,:,::-1]
# imageio.imwrite('raw_jpg.jpg',imgData_rgb)
#显示
# cv2.imshow('rawfile',rawfile)
# cv2.waitKey()

猜你喜欢

转载自blog.csdn.net/weixin_41819299/article/details/82428950