希望你做得很好。
所以我的问题实际上比标题更复杂,但我会尽量保持简单。
我有这段代码在凸轮上运行(使用OpenCV ),它将检测一个人是否戴着口罩,就检测而言,它执行得非常好(我从YouTube:https://www.youtube.com/watch?v=Ax6P93r32KU&t=73s获得了代码)。
简而言之,我想让程序看看这个人(信心> 95%)是否戴着口罩,如果他戴着口罩,就会弹出一条消息,感谢他,然后程序就会关闭。
从理论上讲,我已经做到了所有这些,问题是,当人戴着口罩时,弹出消息将立即出现,甚至在摄像头赶上之前!或者,如果这个人没有戴口罩,然后开始戴口罩,那么当他戴着口罩时,弹出消息也会立即出现。
理想情况下,我想检查他是否戴了口罩2秒或3秒,然后弹出窗口就会出现。
我试着使用延迟,但它使相机变慢了很多,而且看不到发生了什么,我试着将戴口罩的信心附加到列表中,然后取列表的平均值,但仍然不起作用。
所以最理想的情况是:
戴口罩的人的置信度=M
如果M> 95%持续3秒:
print(message(thank you))
exit()希望你对如何解决这个问题有一个想法,如果我的解释不是很明显,我很抱歉。我可以为那些对我的问题感兴趣但不理解我的问题的人提供一个实况流(不和谐)。
发布于 2020-12-16 17:22:54
我可以通过创建一个空列表并设置t1 = time.time() (在while True循环之前)来解决这个问题。
mask_list=[]
t1 = time.time()在循环中,我将读取4秒的读数
mask_list.append(mask)
if time.time() - t1 > 4: # when 4 seconds passes
mask_avg = sum(mask_list) / len(mask_list)
if mask_avg*100 > 90: # when the average of wearing a mask is > 90%
# code for wearing a mask then exit()
else :
# code for NOT wearing a mask then exit()我不确定我是否被允许,但如果有人想看完整的代码,我会在GitHub上发布代码:https://github.com/Dalsallum/Login-System-With-Mask-Detection
发布于 2020-12-16 02:03:35
所以如果我理解正确的话,像这样的东西应该是有效的。让我知道发生了什么,或者如果你不明白什么。这段代码使用了多个线程,不会停止代码的视频部分。
import time
import threading
wearingMaskBool = False
def checkPerson3Seconds():
global wearingMaskBool
#lets check the person 6 times we will use multiple threads so the camera and the 3 second check code can run simpltaniously
for i in range(6)
if (M > 95%):
#adding one if mask is worn
wearingMask += 1
else:
#subtracting one if mask isnt worn
wearingMask -= 1
#wait half a second
time.sleep(0.5)
#checking if wearingMask == 6
if wearingMask == 6:
#execute code for person that is wearing mask
#example
# we can define the "wearingMaskBool" as a global and use it in out main script
wearingMaskBool = True
else:
#execute code for person that isnt wearing mask
#example
# we can define the "wearingMaskBool" as a global and use it in out main script
wearingMaskBool = False
#start thread aka staring the checkPerson3Seconds script
threading.Thread(target=checkPerson3Seconds(), daemon=True).start()
#after the script is ran if they are wearing a mask with a certainty of 95 percent of 3 seconds the the wearingMaskBool will be equal to true
#if it fell below 95% it will be equal to falsehttps://stackoverflow.com/questions/65310999
复制相似问题