How can I call a function, for example Play a sound, if I do 3 blinks in a space of 2 seconds?
if blinking_ratio > 5.7:
cv2.putText(frame, "BLINKING", (50, 150), font, 7, (255, 0, 0))
winsound.PlaySound("campainha.wav.wav", winsound.SND_FILENAME)
Here if I blink, the sound plays... I want to play, only if I blink 3 times in 2 secs for example...
You could set up a Time
class by using
class Time(datetime.tzinfo):
def utcoffset(self, x):
return datetime.timedelta(hours=-5) + self.dst(x)
def dst(self, x):
date = datetime.datetime(x.year, 3, 8)
self.dston = date + datetime.timedelta(days=6-date.weekday())
date = datetime.datetime(x.year, 11, 1)
self.dstoff = date + datetime.timedelta(days=6-date.weekday())
if self.dston <= x.replace(tzinfo=None) < self.dstoff:
return datetime.timedelta(hours=1)
else:
return datetime.timedelta(0)
def tzname(self, x):
return 'Time'
def timeStamp():
return datetime.datetime.now(tz=Time()).strftime('%Y-%m-%d %H:%M:%S')
From this, you could do something like
while . . .:
start = timeStamp()
blinkOnce()
end = timeStamp()
if start - end < 2:
pass
else:
break
Of course you would adjust the second code segment to whatever conditions you want to be met, but the end is just some pseudocode that you could edit accordingly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.