OpenCV 上的人脸检测速度慢?
我在 Mac Os X 上编译并安装了OpenCV(SVN 的最新版本)(这可能是问题的根源)。
该示例有效,但人脸检测算法对我来说似乎很慢。人脸的检测时间约为400ms(我只是使用了包含的示例)。 FPS 相当低。
在 YouTube 等网站上,我看到带有实时人脸检测功能的超流畅视频(即使是在 iPhone 上),所以我感到很困惑。我记得在我的旧 Windows PC 上速度更快。
400 毫秒是正确的检测时间吗?
注意:我的 Macbook 并不旧(2009 年),一切都运行良好。我使用 iSight 网络摄像头(集成网络摄像头)。网络摄像头上只有一张脸(我的脸)。如果没有脸的话,也差不多是同一时间。
I compiled and installed OpenCV (last version from the SVN) on Mac Os X (this is maybe the source of the problem).
The sample works, but the face detection algorithm seems slow to me. The detection time for a face is around 400ms (I just used the example included). The FPS is then quite low.
On youtube and all, I see super-smooth video with real time face detection (even on the iPhone) so I feel confuse. I remember it being even faster on my old Windows PC.
Is 400 ms a correct detection time ?
Note : my Macbook is not old (2009) and everything runs fine on it. I use the iSight webcam (integrated webcam). I have just one face (my face) on the webcam. And it is around the same time if there is no face.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
输入图像的大小是多少。我猜是 640x480。一般来说,发布 YouTube 视频的人会将图像大小调整为 160x120。在 640x480 的全分辨率下,很难获得超过 2-3 fps 的速度。尝试发送 160x120 的图像。您应该获得至少 10 fps。
What is the size of the input image. I am guessing 640x480. Generally people who post YouTube videos resize the image to 160x120. IN full resolution of 640x480 it is very difficult to get more than 2-3 fps. Try to send 160x120 image. You should be getting at least 10fps.
添加到前面的答案:
您还可以通过设置
detectMultiScale
的最大尺寸和最重要的是最小尺寸来加快速度。[此外,正如前面的答案所说,大量缩小是有序的,因为 Haar 检测器使用非常简单的特征(对于最多 6 个像素的关系;在更大的尺度上,您添加类似矩形的区域,就好像它只是一个像素一样) 。在标准 mac/mbp2011 上,我可以获得大约 60fps,这已经足够了。]
为了获得更好的加速,您还可以使用 templateMatching 消除未更改的区域。
Adding to the previous answers:
you can also speed things up by setting the Max and most importantly the Min size for
detectMultiScale
.[Also, as the previous answers say, heavy scaling-down is in order as Haar detector uses very simple features (for the relations of upto 6 pixels; on larger scales you add up rectangle-like areas as if it was just one pixel). On standard mac/mbp2011 I could get around 60fps that is more than enough.]
For an even better speedup you could also eliminate non-changing areas, using say templateMatching.
最近我发现了一个 Simd 库,它有一个 Simd 库。 com/ermig1979/Simd/blob/master/src/Simd/SimdDetection.hpp" rel="nofollow noreferrer">HAAR 和 LBP 级联分类器的实现。它可以使用 OpenCV 中的标准 HAAR 和 LBP 级联。该实现使用 SSE4.1、AVX2 和 NEON(ARM) 进行了 SIMD 优化,因此其运行速度比原始 OpenCV 实现快 2-3 倍。
Recently I had found a Simd Library, which has an implementation of HAAR and LBP cascade classifiers. It can use standard HAAR and LBP casscades from OpenCV. This implementation has SIMD optimizations with using of SSE4.1, AVX2 and NEON(ARM), so it works in 2-3 times faster then original OpenCV implementation.
我遇到了同样的问题,在具有 4GB RAM 的四核机器上每次检测需要 500 毫秒,但是我注意到有一个 Scale 选项....将其设置为:
./facedetect --scale=4
我得到检测率<20ms
希望有帮助,
Keukpa
I was having the same problem, on a Quad Core machine with 4GB RAM was 500ms per detection, however I've noticed there is a Scale option....getting this to:
./facedetect --scale=4
I get detection rates of <20ms
Hope that helps,
Keukpa
在图像上运行时,您应该缩小到一定的限制。如果是视频,除了人脸检测之外,您还可以尝试跟踪。您可以每隔几帧进行面部检测,并跟踪帧之间面部的位置。
此外,OpenCv 支持使用 Canny 丢弃没有机会找到人脸的区域。
When running on image, you should downscale to certain limits. In case of videos, along with Face detection, you can also try tracking. You can do face detection every alternate frames and track the position of face in between frames.
Also, OpenCv supports use of Canny to discard regions where chances of finding Face is none.
我将视频序列中的帧大小调整了 10 倍,效果非常好。另外,为了加快处理速度,请在每个
x
帧中使用人脸检测器,然后在x-1
帧中使用人脸跟踪器之间(为了避免漂移)。查看此链接: 跟踪与检测
也许还有示例代码帮助某人(这是一个简单的检测不是跟踪或识别):
这是ANDROID示例,但它与其他平台的opencv非常相似,语言”
和“proc”功能类似 - 我从OpenCV4Android人脸检测示例中找到并升级了它:
我使用的CPU:Snapdragon 720G
另外,我还从相关论坛发现LBP 比 HAAR 快得多,我不确定这一点以及性能和质量,但我认为提到这一点也很好。
I resized the frame in video sequence with the factor of 10 and it works great. Also for faster process Use Face Detector in each
x
frame and then use Face Tracker instead inx-1
frames between (To avoid drifting).checkout this link: Tracking vs Detecting
And also maybe a sample code helps someone (Its a Simple Detecting not Tracking or Recogniton):
THIS IS ANDROID EXAMPLE but it is pretty much alike in opencv for other platforms and languages"
And "proc" function something like this - I found and upgrade this from OpenCV4Android Face detection sample:
CPU I used: Snapdragon 720G
Also from a related forum, I found that LBP is much faster than HAAR. I am not sure about this and the performance and Quality but I thought it would be good to mention this point as well.