TypeError: Image data of dtype object cannot be converted to float


源码如下:

import os
import cv2
import random
import numpy as np
from tqdm import tqdm

from matplotlib import pyplot as plt

# 查看两张图片
img_path1 = "cat2.jpg"
img_check1 = cv2.imread(img_path1, cv2.IMREAD_GRAYSCALE)
img_path2 = "cat3.jpg"
img_check2 = cv2.imread(img_path2, cv2.IMREAD_GRAYSCALE)
# 显示图片
fig, axes = plt.subplots(nrows=1, ncols=2,figsize=(13,7))
axes[0].imshow(img_check1,'gray')
axes[1].imshow(img_check2,'gray')
plt.show()

程序运行时一直在标红的代码处报错,找了好久才发现自己犯了十分愚蠢的错误:路径写错了(同时路径中含有了中文),虽然是路径错了,但一直报的是另外一个错误,所以也很难发现这个问题。

所以当你也出现了同样的错误,可以去检查一下路径中是否含有中文名或者路径写错了。解决方案仅供参考,如果有更好的方案欢迎留言。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



猜您在找 【error】 for i in range(len(shape)/2): TypeError: 'float' object cannot be interpreted as an integer Uncaught TypeError: Cannot convert undefined or null to object TypeError: 'list' object cannot be interpreted as an integer TypeError: Cannot handle this data type: (1, 1, 6), |u1 TypeError: 'list' object cannot be interpreted as an integer Python常见错误 记录:tensoflow改错TypeError: Cannot interpret feed_dict key as Tensor: Can not convert a float into a Te Vue的报错:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#' create-react-app 遇到问题 TypeError: Cannot assign to read only property 'jsx' of object '#' Vue的报错:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#' asp.net core 3.1 EFcore 执行sql,datatable转List对象时 Object of type 'System.UInt64' cannot be converted to type 'System.Boolean'.
 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM