I know how to convert an image in the disk to base64 via reading the file. However, in this instance, I already have the image as a numpy array in my program, captured via a camera, like image[:,:,3]
. How do I convert it to base64 string such that the image can still be recovered? I tried this.
from base64 import b64encode
base64.b64encode(image)
It does indeed gives me a string, but when I tested with https://codebeautify.org/base64-to-image-converter, it could not render the image, which means there is something wrong in the conversion. Help please.
I know a solution is to write the image into the disk as a jpg picture and then read it into a base64 string. But obviously, I don't want a file i/o when I can avoid it.