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 -0600

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

2 answers

Sort by ยป oldest newest most voted
0

answered 2018-11-16 14:24:59 -0600

import cv2

import numpy as np

img = cv2.imread('yuz1.jpg')

frontal = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

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

f_face = frontal.detectMultiScale((gray, 1.1, 4))

for (x, y, w, h) in f_face: cv2.rectangle(img(x, y), (x + y + w + h), (0, 255, 0), 3)

cv2.imshow('Frontal Face', img) cv2.waitKey(0) img.release() cv2.destroyAllWindows()

@berak help me bro please.

edit flag offensive delete link more
0

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

berak gravatar image

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

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 image[email protected] ( 2018-07-12 05:12:36 -0600 )edit

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

berak gravatar imageberak ( 2018-07-12 05:13:51 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 2,052 times

Last updated: Jul 12 '18