解决方法:opencv读取中文路径图像报错 | AttributeError: ‘NoneType‘ object has no attribute ‘astype‘

简介: ‘NoneType‘ object has no attribute ‘astype‘



在使用开源项目 blind_watermark 给图像添加数字盲水印时,传入图像路径中文时,会出现以上报错。分析它的源码:



self.img=cv2.imread(filename).astype(np.float32)


它用的 opencv 读取图像和转换类型。读取水印图像也是类似的方法。



解决方法:用 numpy 读取处理图片,再对 numpy 处理后的图片数据用 cv2.imdecode 方法进行转码,转化为图片对象。


# self.img = cv2.imread(filename).astype(np.float32)# 用numpy读取处理图片  再对numpy的读取的图片进行转码,转化为图片对象self.img=cv2.imdecode(np.fromfile(filename, dtype=np.uint8), -1).astype(np.float32)


# 读入图片格式的水印,并转为一维 bit 格式# self.wm = cv2.imread(filename)[:, :, 0]self.wm=cv2.imdecode(np.fromfile(filename, dtype=np.uint8), -1)[:, :, 0]


将原来读取图像的代码注释掉,用新的方法重写后保存,然后再读取图像加数字盲水印,不再有报错。


print(":".join(["CSDN叶庭云", "https://yetingyun.blog.csdn.net/"]))


目录
相关文章
|
2月前
|
计算机视觉 Python
解决 NoneType‘ object has no attribute ‘astype’ 问题
解决 NoneType‘ object has no attribute ‘astype’ 问题
30 0
|
4月前
AttributeError: 'NoneType' object has no attribute 'to_capabilities'
AttributeError: 'NoneType' object has no attribute 'to_capabilities'
384 0
|
14天前
|
计算机视觉
OpenCV报错: cv::Exception,位于内存位置 0x00000078226FEE58 处。
OpenCV报错: cv::Exception,位于内存位置 0x00000078226FEE58 处。
|
2月前
|
Java Android开发 计算机视觉
报错opencv2:compileDebugJavaWithJavac
报错opencv2:compileDebugJavaWithJavac
18 0
|
4月前
AttributeError ‘NoneType‘ object has no attribute ‘to_capabilities‘
AttributeError ‘NoneType‘ object has no attribute ‘to_capabilities‘
107 0
|
5月前
|
数据采集
运行爬虫时报错AttributeError—— 'str' object has no attribute 'capabilities'
运行爬虫时报错AttributeError—— 'str' object has no attribute 'capabilities'
292 0
|
5月前
'WebDriver' object has no attribute 'find_element_by_tag_name'
'WebDriver' object has no attribute 'find_element_by_tag_name'
124 0
|
7月前
|
Java
【面试题精讲】Object类的常见方法有哪些?
【面试题精讲】Object类的常见方法有哪些?
|
8月前
|
Java API 开发工具
Java之API详解之Object类的详细解析(下)
Java之API详解之Object类的详细解析(下)
40 0
|
3天前
|
C#
c# 所有类的最终基类:Object
c# 所有类的最终基类:Object
5 0