1
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

2
  • 3
    can you paste the code into the question instead of an image so we can copy and paste it to run it Commented Apr 4, 2017 at 7:26
  • ok, I will try it at once. sorry, i am the freshman in this part Commented Apr 4, 2017 at 7:35

1 Answer 1

1

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")
Sign up to request clarification or add additional context in comments.

1 Comment

what you said is completely right, I tried your code and changed the path(add the complete image path), both were OK. thank you very much

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.