我正在做一台3D扫描仪我第一步是将图像转换为灰度:
from PIL import *
import scipy
import scipy.ndimage as ndimage
import scipy.ndimage.filters as filters
from numpy import *
from pylab import *
import cv2
cv2.namedWindow("Image")
image = cv2.imread('/home/mehdi/Bureau/002.jpg')
im = scipy.misc.imread(image,flatten=1)
cv2.imshow("Image",im)
cv2.waitKey(0)
cv2.destroyALLWindows()
这是我收到的错误消息:
`opengl support available
Traceback (most recent call last):
File "mehdi01.py", line 12, in <module>
im = scipy.misc.imread(image,flatten=1)
File "/usr/lib/python2.7/dist-packages/scip/misc
/pilutil.py", line 97, in imread
im = Image.open(name)
File "/usr/lib/python2.7/dist-packages/PIL/Image.py",
line 1959, in open
prefix = fp.read(16)
AttributeError: 'numpy.ndarray' object has no attribute 'read'
`
1条答案
按热度按时间ego6inou1#
不管您收到的错误消息是什么,您都可以通过为
cv2.imread()
设置cv2.IMREAD_GRAYSCALE
标志来达到您的目标。要键入更少的内容,您可以编写0
而不是cv2.IMREAD_GRAYSCALE
。另请注意,您在
cv2.destroyALLWindows()
中有一个排印错误。请将其改为cv2.destroyAllWindows()
因此,您的代码变得简单:
或者: