如何模拟使用人脸检测模拟空格键? [英] How Can I Simulate The Simulate The Space Bar Using Face Detection?

查看:81
本文介绍了如何模拟使用人脸检测模拟空格键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个程序来检测我的脸并在网络摄像头框架中跟踪我的脸。现在,假设我正在观看视频并且我的面部检测程序正在后台运行,因此当没有检测到面部时,程序应暂停VLC媒体播放器并仅在检测到我的面部时播放它。因为,检测到的面部存储在一个向量中,我试图写一个if语句,如

if(faces.size()== 0){keybd_event(VK_SPACE,0,0, 0);但问题是它一直持续按空格键,我希望它只按一次然后退出循环。此外,它应该在按空格键一次检测到我的脸时自动按空格键。我怎样才能做到这一点?我真的很困惑。

I have written a program that detects my face and tracks my face in the webcam frame. Now, say i am watching a video and my face detection program is running in the background, so when no face is detected the program should pause the VLC media player and play it only when it detects my face. Since, the faces that is detected is stored in a vector, i have tried to write an if statement like
if(faces.size()==0) {keybd_event(VK_SPACE,0,0,0); but the problem is it keeps pressing the space bar continously and i want it to press it just once and then exit the loop. Also, it should automatically press the space bar when it detects my face by pressing the space bar once. How can i do this? I am really confused.

推荐答案

只需设置一个标志,告诉你视频暂停(或不是)



所以请使用类似



Just set a flag telling you that the video is paused (or not)

So use something like

if (!videoIsPaused && !faceRecognised)
{
  PauseVideo();
  videoIsPaused = true;
}
if (videoIsPaused && faceRecognised)
{
  UnPauseVideo();
  videoIsPaused = false;
}


这篇关于如何模拟使用人脸检测模拟空格键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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