1

I'm doing some processing on an image using OpenCV. Now I need to convert the base64 string to bytes. In Python-3.6 I could use base64.decodebytes but I can't find the alternate module in Python-2.7 . Is there any other alternative present in Python-2.7 ?

cvimg = cv2.imdecode(np_img_array, cv2.IMREAD_COLOR)
tmp_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = base64.b64encode(cv2.imencode('.jpg', tmp_img)[1])
img = base64.decodebytes(img)

NOTE: I'm using Python-2.7 as one of the module I'm using has not been converted to Python-3.6

1 Answer 1

1

Python 2 still has the base64 module built in. Using

base64.standard_b64encode(s)
#and
base64.standard_b64decode(s)
#Where 's' is an encoded string

Should still work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.