Ask Your Question
0

for below code I'm getting this error: OpenCV(3.4.1) C:\build\master_winpack-bindings-win64-vc14-static\opencv\modules\imgproc\src\color.cpp:11147: error: (-215) scn == 3 || scn == 4 in function cv::cvtColor

asked 2018-07-12 02:19:22 -0500

import cv2 import numpy as np

facedetect=cv2.CascadeClassifier('haarcascade_frontalface_default.xml'); cam=cv2.VideoCapture(1);

while(True): retval,img=cam.read();

gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
faces=facedetect.detectMultiScale(gray,1.3,5);
for(x,y,w,h)in faces:
    cv2.rectangle(img,(x,y),(x+w,y+h),(0,0,255),2)
    cv2.imshow("Face",img);
    if(cv2.waitKey(1)==ord('q')):
        break;
cam.release()
cv2.destroyAllWindows()
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-07-12 02:28:36 -0500

berak gravatar image

updated 2018-07-12 02:29:33 -0500

python users NEVER do any nessecary checks, so they get those errors.

your videocapture did not open, or it could not retrieve a frame.

cam=cv2.VideoCapture(1); # try 0 here instead
if not cap.isOpened():
    print("no capture!")
    return

while(True): 
    retval,img=cam.read();
    if retval == False:
        print("no image!")
        return

again, you HAVE TO check the outcome of reading resources, opening streams, etc. (same for cv2.imread() or similar)

if you have only a single webcam attached to your box, the only valid camera id would be 0, not 1.

edit flag offensive delete link more

Comments

Thank you for the quick response! Bt I hv already made changes in 'cam=cv2.VideoCapture(0)'

but stll problem is not solved...

faceDetect=cv2.CascadeClassifier(r'E:\Nikita\software\project\haarcascade_frontalface_default.xml')

cam=cv2.VideoCapture(0) print(cam.isOpened())

while (True): ret,frame=cam.read()

gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
faces=faceDetect.detectMultiScale(gray,1.3,5);
for(x,y,w,h)in faces:
    cv2.rectangle(frame,(x,y),(x+w,y+h),(255,0,0),2)
    cv2.imshow("Face",gray);
    if(cv2.waitKey(1)==ord('q')):
        break;
cam.release()
cv2.destroyAllWindows()

OUTPUT: True

error: OpenCV(3.4.1) C:\build\master_winpack-bindings-win64-vc14-static\opencv\modules\imgproc\src\color.cpp:11147: error: (-215) scn

nikita.pawar9304@gmail.com gravatar imagenikita.pawar9304@gmail.com ( 2018-07-12 05:12:36 -0500 )edit

again, your frame is still empty, and you did not check.

berak gravatar imageberak ( 2018-07-12 05:13:51 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-07-12 02:19:22 -0500

Seen: 267 times

Last updated: Jul 12