import numpy as np
import cv2
from matplotlib import pyplot as plt
img = cv2.imread('messi5.jpg',0)
plt.imshow(img, cmap = 'gray', interpolation = 'bicubic')
plt.xticks([]), plt.yticks([]) # to hide tick values on X and Y axis
plt.show()
当输入代码如图所示时,shell将错误输出为标题
"TypeError: Image data can not convert to float"
我不知道如何解决问题,我希望得到答案。非常感谢你
答案 0 :(得分:1)
您的代码运行良好,所以我认为文件路径不正确,请尝试运行此代码以查看文件路径:
import os
import cv2
from matplotlib import pyplot as plt
path='messi5.jpg'
if os.path.isfile(path):
img = cv2.imread(path,0)
plt.imshow(img, cmap = 'gray', interpolation = 'bicubic')
plt.xticks([]), plt.yticks([]) # to hide tick values on X and Y axis
plt.show()
else:
print("file not exists")