Ask Your Question
0

Work with operations pixel by pixel and loops

asked 2018-04-06 20:37:41 -0600

julian403 gravatar image

Hello All.

I heard in this forum before that it isnt recomended work or make an operation pixel by pixel and its more convenient use a function defined in opencv headers and librarys. But that opencv's functions have to work pixel by pixel or there is another way?

For example in this post.

http://answers.opencv.org/question/18...

I needed to copy a half image and first I did it with a for().

Why is not recomended use a loop?

Thanks in advance. its a theorical question.

edit retag flag offensive close merge delete

Comments

copy half an image :use a rect :

        Mat mat = (Mat_<uchar>(2, 4) << 5, 6, 0, 4, 0, 1, 9, 9);
        Mat mat2;
        cout << "mat =" << mat <<  endl;
        mat(Rect(0, 0, 4, 1)).copyTo(mat2);
        cout << "mat2 =" << mat2 << endl;

results :

mat =[  5,   6,   0,   4;
   0,   1,   9,   9]
mat2 =[  5,   6,   0,   4]

Many functions are optimized with a parallel loop or opencl but not all functions. Sometimes pixel loop are faster than opencv function. If you find this case write a post then somebody will make a Pull request to improve function or better do PR yourself you are welcome

LBerger gravatar imageLBerger ( 2018-04-07 03:31:22 -0600 )edit

Thanks for the reply. I will check the opencv function but for some proccess I like to use my own loops. Its more easy and faster for me than go to documentation and check the function parameters and Id like to perform pthreads by myselft. Thanks a lot.

julian403 gravatar imagejulian403 ( 2018-04-07 18:41:56 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-04-07 00:41:13 -0600

moHe gravatar image

In my personal view, there are a lot of parallel computations at the bottom, if you use built-in function in opencv. For instance, numpy is used in opencv-python. Which is quite faster than operation pixel by pixel. You can simply compare the time of copying an image pixel by pixel and that by opencv.

edit flag offensive delete link more

Comments

thanks for the reply.

julian403 gravatar imagejulian403 ( 2018-04-07 18:42:06 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-04-06 20:37:41 -0600

Seen: 241 times

Last updated: Apr 07 '18