首页 > 其他 > 详细

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

时间:2022-05-27 20:53:24      阅读:14      评论:0      收藏: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)

 

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

原文:https://www.cnblogs.com/dreamboy2000/p/15350498.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!