Python-Opencv error: (-215) scn == 3 || scn == 4 in function cv::cvtColor -


import numpy np import cv2 import thread, winsound  face_cascade = cv2.cascadeclassifier('c:\users\saddaqat\desktop\softwares\opencv\build\share\opencv\haarcascades\haarcascade_frontalface_default.xml') eye_cascade = cv2.cascadeclassifier('c:\users\saddaqat\desktop\softwares\opencv\build\share\opencv\haarcascades\haarcascade_eye.xml')  def beep():   in xrange(4):     winsound.beep(1500, 250)  cam = cv2.videocapture(0) count = 0 iters = 0 while(true):       ret, cur = cam.read()       gray = cv2.cvtcolor(cur, cv2.color_bgr2gray)       faces = face      _cascade.detectmultiscale(gray,scalefactor = 1.1, minneighbors=1, minsize=(10,10))           (x,y,w,h) in faces:             #cv2.rectangle(cur,(x,y),(x+w,y+h),(255,0,0),2)             roi_gray = gray[y:y+h,x:x+w]             roi_color = cur[y:y+h,x:x+w]             eyes = eye_cascade.detectmultiscale(roi_gray)         if len(eyes) == 0:           print "eyes closed"         else:           print "eyes open"         count += len(eyes)         iters += 1         if iters == 2:           iters = 0           if count == 0:             print "drowsiness detected!!!"             thread.start_new_thread(beep,())           count = 0         (ex,ey,ew,eh) in eyes:             cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh), (0,255,0),2)       cv2.imshow('frame', cur)       if cv2.waitkey(1) & 0xff == ord('q'):         cv2.destroyallwindows()         break // 

i facing error kindly resolve error . , love in advance ;) traceback (most recent call last): file "c:\users\saddaqat\desktop\fatigue detection code", line 17, in gray = cv2.cvtcolor(cur, cv2.color_bgr2gray) error: ........\opencv\modules\imgproc\src\color.cpp:3739: error: (-215) scn == 3 || scn == 4 in function cv::cvtcolor

well, me looks videocapture not working. should check after reading image, if have read something:

ret, cur = cam.read() if not ret:     print "videocapture read no frame."     break 

if that's case, there has been answers here in might you, example: opencv 2.4 videocapture not working on windows basically, might have problems ffmpeg. maybe have add windows path, and/or rename have opencv version on it.


Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -