How to improve OpenCV performance on iPhone?

I use AVFoundation to capture video with OpenCV for image processing on iPhone. However, I am considering using OpenGL shaders to perform calculations (convolution) on an image in grayscale 192x144.

My question is: does it make sense to use OpenGL, I mean: is it too ported to IplImage (is this possible?)? Or is there a way that will speed up the convolution?

EDIT

In OpenCV, I use

IplConvKernel* kernel = cvCreateStructuringElementEx(3, 3, 1, 1, CV_SHAPE_CROSS, NULL); 

with cvMorphologyEx .

+4
source share
2 answers

Even using NEON vector operations through something like an Accelerate view (which OpenCV doesn't currently use unless I miss something), it will be difficult to outperform shaders when running a simple 3x3 convolution kernel. For example, I can run the Sobel snap detection engine on a 640x480 2.5 ms video frame on an iPhone 4 using shaders, which is more than fast enough for real-time image processing. In addition, OpenGL ES shaders have significant processing advantages for display since you can store everything on the GPU side all the way and avoid costly data transfers for paint events.

If you need an easy way to do this, my open source GPUImage framework has very fast built-in convolutions, such as Sobel edge detection or the image sharpening core, and this allows you to easily create your own 3x3 convolution kernels. It wraps all of OpenGL ES for you, so you don’t need to know anything about it (unless you want to write your own custom effects, but even there you just need to know a little GLSL).

For example, to make only the X-component of the Sobel border detection kernel, you can configure your convolution filter with the following code:

 GPUImage3x3ConvolutionFilter *filter = [[GPUImage3x3ConvolutionFilter alloc] init]; [filter setConvolutionKernel:(GPUMatrix3x3){ {-1.0f, 0.0f, 1.0f}, {-2.0f, 0.0f, 2.0f}, {-1.0f, 0.0f, 1.0f} }]; 

Then you just need to attach it to the camera, image or video input and display, source data or video recorders, and the structure will handle the rest. For best performance, you can write your own custom implementation optimized for the specific kernel that you want to run, for example, I made for GPUImageSobelEdgeDetectionFilter.

+7
source

I could not find the relevant material on this issue, so I can’t say for sure whether an implementation using the shaders of this algorithm will have better performance with small images such as 192x144.

Since this is not a complicated implementation, if you have the time, I recommend that you do this and measure the performance gain of both implementations.

Please let us know your results if you decide to follow this path.

+1
source

Source: https://habr.com/ru/post/1410915/


All Articles