转换图像灰度python错误

时间:2016-03-31 07:15:53

标签: python opencv numpy scipy python-imaging-library

我正在研发3D扫描仪;我的第一步是将图像转换为灰度:

INSERT INTO orangehrm_mysql.ohrm_attendance_record(employee_id,punch_in_utc_time) 
    (
       SELECT co.USERID, co.CHECKTIME
       FROM att2000.CHECKINOUT co
       WHERE HOUR(co.CHECKTIME) < 12
    );



INSERT INTO orangehrm_mysql.ohrm_attendance_record(employee_id,punch_out_user_time) 
    (
        SELECT co.USERID, co.CHECKTIME
        FROM att2000.CHECKINOUT co
        WHERE HOUR(co.CHECKTIME) >= 12
    );

这是我收到的错误消息:

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

`

1 个答案:

答案 0 :(得分:1)

无论您收到的错误消息如何,都可以通过为cv2.IMREAD_GRAYSCALE设置标记cv2.imread()来实现目标。要输入较少,您可以写0而不是cv2.IMREAD_GRAYSCALE

另请注意,cv2.destroyALLWindows()中有拼写错误。将其更改为cv2.destroyAllWindows()而不是

所以你的代码变得简单:

from numpy import *
import cv2

cv2.namedWindow("Image")
im = cv2.imread('/home/mehdi/Bureau/002.jpg',0)
cv2.imshow("Image",im)
cv2.waitKey(0)
cv2.destroyAllWindows()

或者:

from numpy import *
import cv2

cv2.namedWindow("Image")
im = cv2.imread('/home/mehdi/Bureau/002.jpg',cv2.IMREAD_GRAYSCALE)
cv2.imshow("Image",im)
cv2.waitKey(0)
cv2.destroyAllWindows()