Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

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()