Ask Your Question

Revision history [back]

How do I read raw RGB data with Python?

I've got raw data with each byte representing the R, G or B values. No header, no compression. I need to read in this data fro processing. I've searched a lot but either they refer to Mat which my cv2 module doesn't have, or with numpy and cv2.imdecode that returns None for me:

npdata = np.frombuffer(img, dtype=np.uint8) cv2.imdecode(npdata, cv2.IMREAD_COLOR)

I'm using Python 3.8 and opencv 4.5.0 on Arch Linux.