为什么cv :: resize这么慢? [英] Why is cv::resize so slow?

查看:1389
本文介绍了为什么cv :: resize这么慢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在对实时视频Feed进行边缘检测:

I'm doing some edge detection on a live video feed:

- (void)processImage:(Mat&)image;
{
        cv::resize(image, smallImage, cv::Size(288,352), 0, 0, CV_INTER_CUBIC);
        edgeDetection(smallImage);
        cv::resize(smallImage, image, image.size(), 0, 0, CV_INTER_LINEAR);
}

edgeDetection 做一些相当重的提升,并且运行在相当低的帧速率,视频帧尺寸为1280x720。添加调整大小调用显着会降低帧速率,这与我的期望相反。这只是因为调整大小操作很慢,或者因为我做错了什么?

edgeDetection does some fairly heavy lifting, and was running at quite a low framerate with the video frame size of 1280x720. Adding in the resize calls dramatically decreased the framerate, quite the reverse of what I was expecting. Is this just because a resize operation is slow, or becuase I'm doing something wrong?

smallImage 被声明因此在标题中:

smallImage is declared in the header thus:

@interface CameraController : UIViewController
<CvVideoCameraDelegate>
{
    Mat smallImage;
}

没有初始化它,它运作正常。

There is no initialisation of it, and it works ok.

推荐答案

调整图像大小很慢,而且每个处理过的帧都要做两次。有几种方法可以某种方式改进您的解决方案,但您必须提供有关您要解决的问题的更多详细信息。

Resizing an image is slow, and you are doing it twice for each processed frame. There are several ways to somehow improve your solution but you have to provide more details about the problem you are trying to solve.

首先,在检测边缘之前调整图像大小这将导致用更少的信息进行边缘检测,从而导致检测到更少的边缘 - 或者至少会使它更难以检测到它们。

To begin with, resizing an image before detecting edges will result in feeding the edge detection with less information so it will result in less edges being detected - or at least it will make it harder to detect them.

同样调整大小如果我的内存没有失败,那么使用的算法会影响它的速度, CV_INTER_LINEAR是cv :: resize的最快 - 你正在使用CV_INTER_CUBIC进行第一次调整大小。

Also the resizing algorithm used affects its speed, CV_INTER_LINEAR is the fastest for cv::resize if my memory does not fail - and you are using CV_INTER_CUBIC for the first resize.

调整图像大小的一个替代是处理原始图像的较小区域。为此,您应该查看opencv图像 ROI(感兴趣的区域)。这很容易做到,你在这个网站上有很多关于这些的问题。缺点是您只会检测区域中的边缘而不是整个图像,这可能会很好,具体取决于问题。

One alternative to resize an image is to instead process a smaller region of the original image. To that you should take a look at opencv image ROI's (region of interest). It is quite easy to do, you have lots of questions in this site regarding those. The downside is that you will be only detecting edges in a region and not for the whole image, that might be fine, depending on the problem.

如果你真的想要调整图像大小,opencv开发人员通常使用 pyrDown pyrUp 函数来处理较小的图像,而不是调整大小。我认为这是因为它更快,但你可以测试它是肯定的。 此链接中有关pyrDown和pyrUp的更多信息。

If you really want to resize the images, opencv developers usually use the pyrDown and pyrUp functions when they want to process smaller images, instead of resize. I think it is because it is faster, but you can test it to be sure. More information about pyrDown and pyrUp in this link.

关于cv :: resize算法,以下是列表:

INTER_NEAREST - a nearest-neighbor interpolation
INTER_LINEAR - a bilinear interpolation (used by default)
INTER_AREA - resampling using pixel area relation. It may be a preferred method for image decimation, as it gives moire’-free results. But when the image is zoomed, it is similar to the INTER_NEAREST method.
INTER_CUBIC - a bicubic interpolation over 4x4 pixel neighborhood
INTER_LANCZOS4 - a Lanczos interpolation over 8x8 pixel neighborhood

无法确定 INTER_LINEAR 是否最快,但确实比 INTER_CUBIC 更快。

Can't say for sure if INTER_LINEAR is the fastest of them all but it is for sure faster than INTER_CUBIC.

这篇关于为什么cv :: resize这么慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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