Opencv Python display raw image

后端 未结 3 1569
广开言路
广开言路 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:42

    .RAW files are not supported in OpenCV see imread,

    But the file can be opened with Python and parsed with Numpy

    import numpy as np
    fd = open('flight0000.raw', 'rb')
    rows = 480
    cols = 640
    f = np.fromfile(fd, dtype=np.uint8,count=rows*cols)
    im = f.reshape((rows, cols)) #notice row, column format
    fd.close()
    

    This makes a numpy array that can be directly manipulated by OpenCV

    import cv2
    cv2.imshow('', im)
    cv2.waitKey()
    cv2.destroyAllWindows()
    

提交回复
热议问题