I receive from front-end an image in base64 into JSON file, and need take image and decode with OpenCV, the JSON there is:
{
'photo': "b'/9j/4AAQSkZJR...(continue)"
}
and code is
obj = json.loads(json.dumps(event))
obj = obj['foto']
obj = bytes(obj,'utf-8')
obj_d = base64.decodebytes(obj)
print(type(obj_d))
img_buffer = np.frombuffer(obj_d, dtype=np.uint8)
print(img_buffer)
img = cv2.imdecode(img_buffer, flags=cv2.IMREAD_COLOR)
print(img.shape)
And received error is, AttributeError: 'NoneType' object has no attribute 'shape'.
When I code and decode in base64 the image in the Python, I not have problem.