小言_互联网的博客

numpy DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly

667人阅读  评论(0)
DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(imgString,np.uint8)

在做图像base64与numpy array(cv2传统格式)之间的转换测试的时候出现了以上报错,将原np.fromstring函数更新为np.frombuffer即可,如下

import base64
import numpy as np
import cv2


with open("/home/images/friend.jpg","rb") as f:#转为二进制格式
    base64_data = base64.b64encode(f.read())#使用base64进行加密
    
	#base64转换为numpy array格式:
    imgData = base64.b64decode(base64_data)
    # nparr = np.fromstring(imgData, np.uint8) #报错
    nparr = np.frombuffer(imgData,np.uint8) 
    image = cv2.imdecode(nparr,cv2.IMREAD_COLOR)
   	
   	cv2.imwrite("/home/images/friend_copy.jpg",image)

转载:https://blog.csdn.net/weixin_33127753/article/details/105100525
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场