我正在使用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-3.6,所以我正在使用Python-2.7
发布于 2019-05-15 21:15:04
Python2仍然内置了base64模块。使用
base64.standard_b64encode(s)
#and
base64.standard_b64decode(s)
#Where 's' is an encoded string应该还能用。
https://stackoverflow.com/questions/56149779
复制相似问题