gpt4 book ai didi

python - Python-Opencv错误:(-215)scn == 3 || scn == 4在函数cv::cvtColor中

转载 作者:行者123 更新时间:2023-12-02 17:42:03 29 4
gpt4 key购买 nike

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
//
我遇到此错误,请解决此错误。预先感谢和爱;)
Traceback (most recent call last):
File "C:\Users\Saddaqat\Desktop\fatigue detection code", line 17, in <module>
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似乎无法正常工作。阅读图像后,应检查是否可以阅读某些内容:

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

如果是这样,SO中有一些答案可能对您有所帮助,例如: OpenCV 2.4 VideoCapture not working on Windows
基本上,他们说您可能对ffmpeg有问题。也许您必须将其添加到Windows路径,和/或重命名以使其具有OpenCV版本。

关于python - Python-Opencv错误:(-215)scn == 3 || scn == 4在函数cv::cvtColor中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43287796/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com