cv::merge execution time on CV_32S
Hello,
I used following code snippet to merge a few single channel images into a multichannel Mat:
vector<cv::Mat> images(numcomps);
for (int i = 0; i < numcomps; i++)
images[i] = cv::Mat(h, w, CV_32SC1, (image->comps + comps[i])->data);
cv::merge(images, imageMat);
On my machine this code execution time is about 500 ms (!!!), regardless of number of elements in vector<cv::Mat> images
(i.e. even if numcomps == 1). What can be the reasons behind such an overhead?
If I rewrite code as follows it reduces execution time to 2 ms:
cv::Mat result(h, w, CV_MAKETYPE(CV_32S, numcomps));
vector<cv::Mat> images(numcomps);
for (int i = 0; i < numcomps; i++)
{
int from_to[] = { 0,i };
images[i] = cv::Mat(h, w, CV_32SC1, (image->comps + comps[i])->data);
cv::mixChannels(&images[i], 1, &result, 1, from_to, 1);
}
imageMat = result;
I'm using OpenCV 3.1.0 built with CUDA 7.5 (Ubuntu 14.04, Intel® Core™ i3-4170 CPU @ 3.70GHz × 4, GeForce GTX 960/PCIe/SSE2 ).
Cheers, Kate
How did you measure this? In OpenCV 3 on first function call, OpenCL code will be initialized if existing, even if you use
Mat
instead ofUMat
. The execution time should be OK on the next calls.In your first code snippet, I think
merge(InputArrayOfArrays _mv, OutputArray _dst)
is called, which contains OpenCL code.Your second code snippet calls
mixChannels( const Mat* src, size_t nsrcs, Mat* dst, size_t ndsts, const int* fromTo, size_t npairs )
which do not contain OpenCL codetry
#include<opencv2/core/ocl.hpp>
andcv::ocl::setUseOpenCL(false)
before calling functions.thank you, that helped!