python Opencv错误-215 scn == 3 || scn == 4

时间:2015-10-03 17:29:05

标签: python opencv

我在使用python-tesseract-0.9-0.4.win32-py2.7时在Windows 8.1上使用python 2.7我之前的代码并没有像面部检测那样正常工作。 下面的代码是检测图片中的面部。当我卸载python-tesseract-0.9-0.4.win32-py2.7时,它工作正常。但我需要它用于OCR。 我该怎么办。? 错误是:open cv error: (-215) scn == 3 || scn == 4 in function cvtColor

import cv2
import sys

imagepath = ('C:\Users\Default\Downloads\group1.jpg')
cascpath  ('C:\opencv\opencv\sources\data\haarcascades\haarcascade_frontalface_default.xml')
caspatheye=('C:\opencv\opencv\sources\data\haarcascades\haarcascade_eye.xml')

faceCascade = cv2.CascadeClassifier(cascpath)
eye_cascade  = cv2.CascadeClassifier(caspatheye)

img = cv2.imread(imagepath)

gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.3,
minNeighbors=5,
minSize=(15,15),
flags=cv2.CASCADE_SCALE_IMAGE
)

for (x,y,w,h) in faces:
    img = cv2.rectangle(img,(x,y),((x+w),(y+h)),(255,0,0),2)
    roi_gray = gray[y:y+h, x:x+w]
    roi_color = img[y:y+h, x:x+w]
    eyes = eye_cascade.detectMultiScale(roi_gray)
    for (ex,ey,ew,eh) in eyes:
         cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,255,0),2)

cv2.namedWindow("faces found", cv2.WINDOW_NORMAL)
cv2.imshow("faces found",img)
cv2.waitKey(0)
cv2.destroyAllWindows()

0 个答案:

没有答案