Multiplying a Mat against another Mat on a GPU
I can multiply a 1080X1920 pixel CV_32FC1 mat against another 3X3 Mat when using CPU based OpenCV, but when I convert the code to be Gpu Based, I get an error. Here is my CPU code
float matrix[3][3] = {{1.057311, -0.204043, 0.055648},
{ 0.041556, 1.875992, -0.969256},
{-0.498535,-1.537150, 3.240479}};
Mat matrixMat = Mat(3, 3, CV_32FC1, matrix).t();
Mat orig_img_linear = linearMat.reshape(1, 1080*1920);
Mat color_matrixed_linear = orig_img_linear * matrixMat;
Mat final_color_matrixed = color_matrixed_linear.reshape(3, 1080);
When I run the following Gpu code, I get an error:
cv::gpu::multiply(orig_img_linear, matrixMat, color_matrixed_linear);
OpenCV Error: Assertion failed (src2.type() == src1.type() && src2.size() == src1.size())
in multiply, file /Users/user/Downloads/opencv-2.4.11/modules/gpu/src/element_operations.cpp,
line 934 libc++abi.dylib: terminating with uncaught exception of type
cv::Exception:
/Users/user/Downloads/opencv-2.4.11/modules/gpu/src/element_operations.cpp:934:
error: (-215) src2.type() == src1.type() && src2.size() == src1.size() in function multiply
I assume from the error that the problem is that my two arrays' sizes are different. Is there a way to accomplish the CPU code with the GPU?
a * b
does matrix multiplication, whilemultiply(a,b)
does per element multiplication. can it be, you're confusing this ?Looking back on my code, gemm wants to multiply Mats which have the following types: CV_32FC1 , CV_64FC1 , CV_32FC2 , or CV_64FC2
My linear Mat is CV_32FC3, so I would think I need to need to split my RGB channels and multiply them individually. But that won't work. Any recommendations?
I wish to perform matrix multiplication similar to:
Any advice on how to accomplish this?
on the cpu, there's a transform function for this.
Yes, but I am trying to use this on the GPU