weimeitiankong980
weimeitiankong980

Reputation: 29

"TypeError: Image data can not convert to float" unsing matplotlib in python27

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()

when input the code as picture showing, the shell output the error as title

"TypeError: Image data can not convert to float"

i don't know how to solve the problem, i expect the answer.thank you very much

Upvotes: 1

Views: 3976

Answers (1)

McGrady
McGrady

Reputation: 11477

Your code works well, so I suppose the file path is not correct, try to run this to check out the file path:

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")

Upvotes: 1

Related Questions