Opencv Python display raw image

后端 未结 3 1580
广开言路
广开言路 2021-01-02 07:14

I can\'t figure out how to display a raw image which contains 640x480 pixel information, each pixel 8 bit. (Gray image)

I need to go from an np array to Mat format to

3条回答
  •  误落风尘
    2021-01-02 07:32

    Just an example if you want to save your 'raw' image to 'png' file (each pixel 32 bit, colored image):

    import numpy as np
    import matplotlib.pyplot as plt
    
    img = np.fromfile("yourImage.raw", dtype=np.uint32)
    print img.size #check your image size, say 1048576
    #shape it accordingly, that is, 1048576=1024*1024
    img.shape = (1024, 1024)
    
    plt.imshow(img)
    plt.savefig("yourNewImage.png")
    

提交回复
热议问题