garak garak - 1 year ago 152
C++ Question

Subtract Matrices row-wise in OpenCV

Is there any built-in method in OpenCV (C++ API) to subtract two matrices row-wise.

I have the following matrices:

Mat A(10,2, CV_64F);
Mat B(1,2, CV_64F);
Mat C(10,2, CV_64F);

C = A - B;

// B is a 1 x 2 matrix, A is a 10 x 2 matrix, and C is a 10 x 2 matrix.

Each row in A has to be subtracted from B and stored as a row in C

Answer Source

I solved it the following way:

Mat A(10,2, CV_64F);
Mat B(1,2, CV_64F);
Mat C(0,2, CV_64F);
Mat D(0,2, CV_64F);

for(int i=0;i<A.rows;i++)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download