error python

asked 2016-11-01 09:00:08 -0600

xiaoerlaigeid gravatar image

updated 2016-11-01 09:04:30 -0600

berak gravatar image
import numpy as np
import cv2
from matplotlib import pyplot as plt

face_cascade = cv2.CascadeClassifier(r'D:\OpenCV\opencv\sources\data\haarcascades\haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier(r'D:\OpenCV\opencv\sources\data\haarcascades\haarcascade_eye.xml')

cap=cv2.VideoCapture(0)

while 1:
    ret, img=cap.read()
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    faces=face_cascade.detectMultiScale(gray,1.3,5)
    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.imshow('img',img)
    k=cv2.waitKey(30)  & 0xff
    if k==27:
        break
    cap.release()
    cv2.destroyAllWindows()

I'm trying to use facedectecting.but I don't know why i cant open my camera. other code can open my camera. this is error information

 File "face.py", line 12, in <module>
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.error: C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:7456: error: (-215) scn == 3 || scn == 4 in function cv::ipp_cvtColor

 -

edit retag flag offensive close merge delete

Comments

Can you slowly take out all the lines of code that are different from a standard example; until it is something like this and working http://docs.opencv.org/3.0-beta/doc/p.... Then we can see which part it does not like.

Messina Vision Systems gravatar imageMessina Vision Systems ( 2016-11-03 05:04:36 -0600 )edit

Thanks, I have find the problem.

xiaoerlaigeid gravatar imagexiaoerlaigeid ( 2016-11-03 05:08:30 -0600 )edit