Search code examples
pythonpython-imaging-librarynvidia-jetsonnvidia-jetson-nano

How to convert image data in ndarray encoded in bgr8 to jpeg image in python?


I'm trying to capture an image using the csi camera on jetson nano using the jetcam.csi_camera library. The read method in the library returns an n-dimentional array and uses bgr8 encoding. I want to convert this to an image object in PIL. How can I use PIL.Image.fromarray() to achieve this? I tried but the fromarray() uses rgb mode and my image gets its blue and red channels interchanged. Pardon me and please ask if question is not clear. Thank you in advance:)


Solution

  • Try reversing the channels:

    PILimage = Image.fromarray(... bgr8data[:,:,::-1]... )