Why is cv :: resize so slow?

I am doing some edge detection in a live video:

- (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 makes a rather heavy lift and works with a fairly low frame rate with a video size of 1280x720. Adding resize to calls sharply reduced the frame rate, quite the opposite of what I expected. Is it just because the resize operation is slow, or because I'm doing something wrong?

smallImage declared in the header, thus:

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

No initialization, and it works fine.

+6
source share
1 answer

Resizing the image is slow, and you do it twice for each processed frame. There are several ways to improve your solution somehow, but you need to provide more detailed information about the problem you are trying to solve.

To begin with, resizing the image before detecting the edges will result in detection of edges with less information, which will result in fewer edges being detected β€” or at least making them difficult to detect.

The resizing algorithm used also affects its speed, CV_INTER_LINEAR is the fastest for cv :: resize if my memory does not crash, and you use CV_INTER_CUBIC for the first resize.

One alternative to resize an image is to instead process a smaller area of ​​the original image. To do this, you should take a look at opencv image ROI (area of ​​interest) . It is quite easy to do, you have a lot of questions on this site. The downside is that you will only detect edges in the area, and not for the whole image, which may be good, depending on the problem.

If you really want to resize images, opencv developers usually use the pyrDown and pyrUp functions when they want to process smaller images rather than resizing them. I think this is because it is faster, but you can check it to be sure. Additional information about pyrDown and feast in this link.

About cv :: resize algorithms, here is the list:

 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 

This is not to say that if INTER_LINEAR is the fastest of all, but it is sure faster than INTER_CUBIC .

+14
source

All Articles