Python 在闭上眼睛3秒钟后检测是否闭上眼睛
我想在python中使用openCV在闭眼3秒后检测闭眼。但是当我使用time.sleep(1)来计算时间时,整个程序都停止了。 但该程序必须连续运行,以检测眼睛是否闭上。 我认为可以在python中使用该线程Python 在闭上眼睛3秒钟后检测是否闭上眼睛,python,opencv,Python,Opencv,我想在python中使用openCV在闭眼3秒后检测闭眼。但是当我使用time.sleep(1)来计算时间时,整个程序都停止了。 但该程序必须连续运行,以检测眼睛是否闭上。 我认为可以在python中使用该线程 def get_frame(self): success, image = self.video.read() gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) faces = faceCascade.detectM
def get_frame(self):
success, image = self.video.read()
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.3,
minNeighbors=5,
minSize=(30, 30),
flags=cv2.cv.CV_HAAR_SCALE_IMAGE
)
while True:
for (x, y, w, h) in faces:
cv2.rectangle(image, (x, y), (x + w, y + h), (255, 255, 0), 2)
roi_gray = gray[y:y+h, x:x+w]
roi_color = image[y:y+h, x:x+w]
eyes = eyesCascade.detectMultiScale(roi_gray)
if eyes is not():
for (ex,ey,ew,eh) in eyes:
cv2.rectangle(roi_color,(ex -10 ,ey - 10),(ex+ew + 10,ey+eh + 10),(0,255,0),2)
twoeyes = twoeyesCascade.detectMultiScale(roi_gray)
checkyeys = 0
if twoeyes is not():
for (exx,eyy,eww,ehh) in twoeyes:
checkyeys = 0
led.write(1)
cv2.rectangle(roi_color,(exx-5 ,eyy -5 ),(exx+eww -5,eyy+ehh -5 ),(0,0, 255),2)
else:
#when eyes close
print "------------------------------------"
for i in xrange(10):
time.sleep(1)
if(i % 3 == 0){
#eyes close in 3 seconds
print "Warning"
}
print i
ret, jpeg = cv2.imencode('.jpg', image)
self.string = jpeg.tostring()
self._image = image
return jpeg.tostring()
谢谢你的帮助 尝试改变
if(i % 3 == 0){
#eyes close in 3 seconds
print "Warning"
}
到
您是否识别出任何错误消息?但程序因时间而停止。睡眠(1)是否仍在停止(语法更正后)?它是否显示任何消息?是否包含
import time
语句?以下是我拥有的库导入:import cv2 import time import sys import numpy as np import os import mraa from datetime import datetime import thread是否仍在停止(语法更正后)?它有什么信息吗?
if i % 3 == 0:
#eyes close in 3 seconds
print "Warning"