macos OpenCV 上的人脸检测速度慢?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3763832/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 07:13:49  来源:igfitidea点击:

Slow face detection on OpenCV?

c++macosopencvface-detection

提问by Matthieu Napoli

I compiled and installed OpenCV(last version from the SVN) on Mac Os X(this is maybe the source of the problem).

我在Mac Os X上编译并安装了OpenCV(SVN 的最新版本)(这可能是问题的根源)。

The sample works, but the face detectionalgorithm 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.

该示例有效,但人脸检测算法对我来说似乎很慢。人脸的检测时间约为400 毫秒(我只使用了包含的示例)。那么 FPS 就相当低了。

On youtube and all, I see super-smooth video with real timeface detection (even on the iPhone) so I feel confuse. I remember it being even faster on my old Windows PC.

在 youtube 上,我看到实时人脸检测的超流畅视频(甚至在 iPhone 上),所以我感到困惑。我记得它在我的旧 Windows PC 上更快。

Is 400 ms a correct detection time ?

400 ms 是正确的检测时间吗?

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.

注意:我的 Macbook 不旧(2009 年)并且一切正常。我使用 iSight 网络摄像头(集成网络摄像头)。我的网络摄像头上只有一张脸(我的脸)。如果没有脸,它大约在同一时间。

回答by Krish

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.

输入图像的大小是多少。我猜是 640x480。通常,发布 YouTube 视频的人会将图像大小调整为 160x120。在 640x480 的全分辨率下,很难获得超过 2-3 fps。尝试发送 160x120 图像。你应该得到至少 10fps。

回答by William

Recently I had found a Simd Library, which has an implementationof 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.

最近我发现了一个Simd 库,它实现了 HAAR 和 LBP 级联分类器。它可以使用来自 OpenCV 的标准 HAAR 和 LBP 级联。此实现具有使用 SSE4.1、AVX2 和 NEON(ARM) 的 SIMD 优化,因此它的运行速度是原始 OpenCV 实现的 2-3 倍。

回答by Barney

Adding to the previous answers:

添加到以前的答案:

you can also speed things up by setting the Max and most importantly the Min size for detectMultiScale.

您还可以通过设置 Max 和最重要的 Min 大小来加快速度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.]

[另外,正如前面的答案所说,由于 Haar 检测器使用非常简单的特征(对于最多 6 个像素的关系;在较大的尺度上,您将矩形区域相加,就好像它只是一个像素一样) . 在标准的 mac/mbp2011 上,我可以获得大约 60fps,这已经足够了。]

For an even better speedup you could also eliminate non-changing areas, using say templateMatching.

为了获得更好的加速,您还可以使用模板匹配来消除不变的区域。

回答by saurabheights

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.

此外,OpenCv 支持使用 Canny 来丢弃没有机会找到 Face 的区域。

回答by 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:

我遇到了同样的问题,在具有 4GB RAM 的四核机器上,每次检测需要 500 毫秒,但是我注意到有一个 Scale 选项......得到这个:

./facedetect --scale=4

./facedetect --scale=4

I get detection rates of <20ms

我得到<20ms的检测率

Hope that helps,

希望有所帮助,

Keukpa

库帕

回答by Adam Freeman

Does anybody know why face detection in OpenCV 3.4.5 is so slow? I think it was a lot faster in version 3.4.3 I have not done any benchmarking but it seemed a lot faster.

有人知道为什么 OpenCV 3.4.5 中的人脸检测这么慢吗?我认为它在 3.4.3 版本中快了很多我没有做过任何基准测试,但它似乎快了很多。