When I decode a base64 encoded cropped face image, it goes black and the data corrupts.
This is the piece of code:
def create_learn_msg(db_name, person_name, last_location, images, labels):
json_string = {}
cv2.imwrite('%s/%s.png' % ("faces/", "original-image"), images[1])
print(type(images[1])) # <type 'numpy.ndarray'>
image_string = images[1].tostring()
encode_string = base64.b64encode(image_string)
# Decode test
decode_string = base64.b64decode(encode_string)
decode_image = numpy.fromstring(decode_string, dtype=numpy.uint8)
print(type(decode_image)) # <type 'numpy.ndarray'>
cv2.imwrite('%s/%s.png' % ("faces/", "decode-image"), decode_image)
json_string['data'] = {'type': "learn", 'db_name': db_name, 'person_name': person_name,
'last_location': last_location, 'image1': base64.b64encode(images[0]),
'image2': base64.b64encode(images[1]), 'label1': labels[0], 'label2': labels[1]}
return json.dumps(json_string)