I'm trying to display video stream through an IP webcam.

import cv2
import sys
cascPath = "haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(cascPath)
video_capture = cv2.VideoCapture('')
while True:
# Capture frame-by-frame
  ret, frame = video_capture.read()

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

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

# Draw a rectangle around the faces
  for (x, y, w, h) in faces:
      cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)

# Display the resulting frame
  cv2.imshow('Video', frame)

  if cv2.waitKey(1) & 0xFF == ord('q'):
# When everything is done, release the capture

This code runs perfectly fine on the PC but when I run it on Raspberry it shows the following error:

OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /build/opencv-ISmtkH/opencv-, line 3737
Traceback (most recent call last):
  File "face_vid_detect.py", line 26, in <module>
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.error: /build/opencv-ISmtkH/opencv- error: (-215) scn == 3 || scn == 4 in function cvtColor

Could anyone tell me why this is happening?

  • Instead of editing the question it would have been better if it was answered.
    – NEO
    Dec 4, 2016 at 13:55

1 Answer 1


This error means there is an empty frame and you cannot convert an empty frame to gray. So the your webcam is not able to start. Look for a proper way to run a webcam in Raspberry Pi. In general if you add cv2.VideoCapture(0) in the beginning, by default it should take your webcam as capturing device.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.