garak - 1 year ago 152

C++ Question

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.

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

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++)
{
C=(A.row(i)-B.row(0));
D.push_back(C.row(0));
}
cout<<"A\n"<<A<<endl;
cout<<"B\n"<<B<<endl;
cout<<"C\n"<<C<<endl;
cout<<"D\n"<<D<<endl;
```

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