Python-Opencv错误:(-215)scn == 3 || scn == 4在函数cv :: cvtColor中 [英] Python-Opencv error: (-215) scn == 3 || scn == 4 in function cv::cvtColor

查看:1409
本文介绍了Python-Opencv错误:(-215)scn == 3 || scn == 4在函数cv :: cvtColor中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

import numpy as 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():
  for i 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))
          for (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
        for (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
//

我遇到此错误,请解决此错误.预先感谢和爱;) 追溯(最近一次通话): 在第17行的"C:\ Users \ Saddaqat \ Desktop \疲劳检测代码"文件中 灰色= cv2.cvtColor(cur,cv2.COLOR_BGR2GRAY) 错误:........ \ opencv \ modules \ imgproc \ src \ color.cpp:3739:错误:(-215)scn == 3 ||函数cv :: cvtColor中的scn == 4

I am facing this error Kindly resolve this error . thanks and 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

推荐答案

对我来说,VideoCapture无法正常工作.阅读图像后,您应该检查图像是否可以阅读:

Well, for me it looks like the VideoCapture is not working. You should check after reading the image, if it could have read something:

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

在这种情况下,SO中有一些答案可能会对您有所帮助,例如:

If that's the case, there has been some answers here in SO that might help you, for example: OpenCV 2.4 VideoCapture not working on Windows Basically, they say that you might have problems with the ffmpeg. Maybe you have to add it to Windows path, and/or rename it to have the OpenCV version on it.

这篇关于Python-Opencv错误:(-215)scn == 3 || scn == 4在函数cv :: cvtColor中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆