what is the fastest way to run a method on all pixels in opencv (c++) -


I have several functions to do opencv on each pixel I am using a build like this:

 for  (int line = 0; line & lt; inputImage.rows; ++ line) {uchar * p = inputImage.ptr (line); (Int col = 0; col & lt; inputImage.cols * 3; cola + = 3) for {int blue = * (p + col); // Each Pixel B, G, R value, in return, considers CV_8 UC3 colorful image int green = * (p + col + 1); Int red = * (p + col + 2); // PROCESS PIXEL}}   

This is working, but I'm thinking that there is a fast way to do this? This solution does not use any similar resource of any SIMD or OpenCV.

What is the best way to run a method on all pixels of an image in OpenCV?

If Mat is constant, i.e. the matrix element interval at the end of each row You can always be referred to using the Mat :: isContinuous () , you can treat them as a long line, thus you can do something like this. Are:

  const uchar * ptr = inputImage.ptr & lt; Uchar & gt; (0); (Size_t i = 0; i & lt; input image. Ros * input image. ++ i) {int blue = pTR [3 * i]; Int green = ptr [3 * i + 1]; Int red = ptr [3 * i + 2]; // Process Pixel}   

As stated, this approach, if very simple, can increase the performance of a simple element-operation by 10-20 percent < / Strong>, especially if the image is small and the operation is quite easy.

PS: For greater need, you will need to make full use of the GPU to process every pixel in parallel.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

Matlab: Transfer variable from GUI to Base Workspace and new Variables (Static Workspace, Script, Creating new Variables) -