Ask Your Question
0

OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /build/buildd/opencv-2.4.8+dfsg1/modules/imgproc/src/color.cpp, line 3737

asked 2016-08-17 23:12:12 -0600

chrisbr gravatar image

Stumbled on this problem the embedded camera works fine but when I try to make this work on the remote it throws "OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /build/buildd/opencv-2.4.8+dfsg1/modules/imgproc/src/color.cpp, line 3737 Traceback (most recent call last): File "face.py", line 10, in <module> gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) cv2.error: /build/buildd/opencv-2.4.8+dfsg1/modules/imgproc/src/color.cpp:3737: error: (-215) scn == 3 || scn == 4 in function cvtColor" Apparently the mjpg video is gray-scaled already, I'm lost just trying to learn and make this one thing work if anyone could help it would be really appreciated basically I want to use CascadeClassifier's to find a body or face. and save the image when it does as a date and timestamp


import numpy as np
import cv2
face_cascade = cv2.CascadeClassifier('face.xml')
eye_cascade = cv2.CascadeClassifier('body.xml')
cap = cv2.VideoCapture("http://user:@192.168.1.17/videostream.cgi")
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:
        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()

edit retag flag offensive close merge delete

Comments

1

The video is not being captured , therefore the img is empty giving this error. Please check the stream

supertramp-sid gravatar imagesupertramp-sid ( 2016-08-17 23:45:14 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-08-17 23:43:44 -0600

berak gravatar image

your input to cv2.cvtColor is empty/invalid.

please check:

  cap.isOpened() # do we have a valid capture at all ?
  ret == True    # did we get an image ?

i'm pretty sure, it could not connect properly to your stream url.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-08-17 23:12:12 -0600

Seen: 6,330 times

Last updated: Aug 17 '16