Ask Your Question

what does this error message means?

asked 2017-06-23 04:12:58 -0500

maynard87 gravatar image

updated 2017-06-24 01:16:22 -0500

berak gravatar image

hello. Im trying to make a face detection from live video feed using haar cascade by using this code:

import cv2 import sys

faceCascade = cv2.CascadeClassifier('/home/pi/opencv-3.1.0/data/haarcascades/haarcascade_frontalface_default.xml')

video_capture = cv2.VideoCapture(0)

while True: ret, frame =

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

faces = faceCascade.detectMultiScale(
    minSize=(30, 30),

for (x, y, w, h) in faces:
    cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)

cv2.imshow('Video', frame)

if cv2.waitKey(1) & 0xFF == ord('q'):

video_capture.release() cv2.destroyAllWindows()

but then I got this error message

Traceback (most recent call last): File "/home/pi/pythonpy/", line 17, in <module> gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) error: /home/pi/opencv-3.1.0/modules/imgproc/src/color.cpp:8000: error: (-215) scn == 3 || scn == 4 in function cvtColor

what does that mean? and how can I fix this? I have tried to look for answer in the internet, but none works. Im new to python programming, so please be nice to me :)

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-06-23 04:20:09 -0500

berak gravatar image

updated 2017-06-23 04:22:23 -0500

it means, your image is empty, it never read something from your webcam.

video_capture = cv2.VideoCapture(0)
# please CHECK, if it worked !
if not video_capture.isOpened(): raise Exception("camera could not be opened !")

while True:
    ret, frame =
    # CHECK again !
    if not ret: # if this was a video *file, it means, that the movie's over.
         print("no image !")
edit flag offensive delete link more


I tried to add your code into mine, and it giving me that Exception message. From what i read, the video_capture.isOpened() returns false, which means i need to initialize or "warm up" my camera. Then I tried to add this line: just after video_capture = cv2.VideoCapture. But I still get the exception message. My picamera is working fine, I tried it with ` from picamera import PiCamera from time import sleep

camera = PiCamera()

camera.start_preview(alpha=200) sleep (10) camera.stop_preview()`

I really dont know where it goes wrong

maynard87 gravatar imagemaynard87 ( 2017-06-24 03:03:40 -0500 )edit

Question Tools

1 follower


Asked: 2017-06-23 04:08:25 -0500

Seen: 560 times

Last updated: Jun 23 '17