It’s amazing how I can code and have fun for hours, and them suddenly spent 2 hours trying to manually do something, that it’s already resolved in all internet. Today’s challenge:
Convert an OpenCV frame to PIL image
And, why ? very simple, OpenCV follows the BGR convention and PIL follows RBG convention. So even, if the array have the same values, they are in different formats. So, here it goes both scenarios:
OpenCV image to PIL Image
# importing Image from PIL img_tmp = cv2.cvtColor(img_openCV, cv2.COLOR_BGR2RGB) im_PIL = Image.fromarray(img_tmp)
PIL Image to OpenCV Image
# using numpy img_openCV = np.asarray(im_pil)
And, that’s it ! I’ll leave it here and I know I’ll save a couple of hours to myself in the near future.
More posts in my blog ElBruno.com.
More info in https://beacons.ai/elbruno