C++ allocate and copy matrix take too much time

asked 2020-11-04 10:45:54 -0600

vdhers gravatar image

updated 2020-11-04 11:26:41 -0600

Good morning,

When I copy a part of a cv::Mat of size 5000X46357 and type=CV_32F to a cv::Mat of size 100X46357 and type=CV_32F, it take 3ms. To reduce this time, I initialize the cv::Mat of size 100X46357 to ones, but this take 7ms and it doesn't reduce the time of copy. Is it normal that cv::Mat::ones take this time?

I have also a problem with this matrix when I pass it in a function after the copy, if I don't initialize it with ones, the function take 9.5ms but if I initialize with ones, the function take 2.5ms; is it normal that the initialization of the matrix outside the function affect the time of the function?

My final problem is that I do a matrix operation who take 0.014ms and when I affect this operation to a matrix, it take 4.7ms. The result matrix has a size of 2X46357 and type=CV_32F .

So, is it normal that allocation and give data to a matrix take too much time?

I Work on Windows 10 Pro 1909 X64, AMD Ryzen Threadripper 1900X8-core cpu, NVidia titan V gpu, with opencv X64 version 4.1.1 , I work on visual studio 2017 and I compile on mode Release X64.

Here a part of code:

Copy of matrix image description

Matrix operation and assignment image description

Thank you for your respond.

edit retag flag offensive close merge delete

Comments

hw ? os ? compiler ? opencv version ?

can you add some resp. code snippets, so ppl can try to reproduce your findings ?

berak gravatar imageberak ( 2020-11-04 10:59:26 -0600 )edit