Reputation: 14615
I have converted some code from old Opencv to the c++ version, and I get an error at matrix multiplication.
OpenCV Error: Sizes of input arguments do not match (The operation is neither
'array op array' (where arrays have the same size and the same number of channels),
nor 'array op scalar', nor 'scalar op array')
On the web, this error seems to be associated with having different number of channels - mine are all 1.
What I did find different though is a "step" - on one it is 24, on another is 32.
Where is this step ?
I created both input matrices using
cv::Mat YYY(3, 4, CV_64FC1); // step 32
cv::Mat XXX(3, 3, CV_64FC1); // step 24
Yet they seem to have different step ?
Could this be the culprit for the error in cv::multiply(XXX,YYY, DDD);
?
Is it not possible to perform operations (like a mask) between different types ?
Thank you
Upvotes: 2
Views: 146
Reputation: 11359
cv::multiply()
performs element-wise multiplication of two matrices. As the error states, your matrices are not the same size.
You may be looking for matrix multiplication, which is accomplished via the *
operator. Thus
cv::Mat DDD = XXX * YYY;
will compile and run correctly.
For the record, this has nothing (directly) to do with the step
field, which for your matrices is the number of columns times sizeof(double)
, since your matrices are of type CV_64FC1
. Things get more complicated if the matrices are not continuous, but that is not the case for you.
Upvotes: 2