我正在使用OpenCV
对图像进行一些处理。现在,我需要将base64字符串转换为字节。在Python-3.6
中,我可以使用base64.decodebytes
,但是在Python-2.7
中找不到替代模块。 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)
注意:我正在使用Python-2.7
,因为我正在使用的模块之一尚未转换为Python-3.6
答案 0 :(得分:0)
Python 2仍然内置了base64模块。 使用
base64.standard_b64encode(s)
#and
base64.standard_b64decode(s)
#Where 's' is an encoded string
应该仍然可以工作。