Read a base 64 encoded image from memory using OpenCv python library

This is my solution for python 3.7 and without using PIL

import base64

def readb64(uri):
   encoded_data = uri.split(',')[1]
   nparr = np.fromstring(base64.b64decode(encoded_data), np.uint8)
   img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
   return img

i hope that this solutions works for all

Leave a Comment