Hello,

I'm hoping that there is somebody out there who is familiar with OpenCV, as I have a very simple problem.

I have a linear equation Ax = B which I want to solve. This is done with the OpenCV function solve(A, B, x). (A fourth argument can be used to specify the method for solving.) However, I am not getting the correct results.

For example, consider this code for a very simple equation:

Code:
Mat A(2, 2, CV_32F);
Mat B(2, 1, CV_32F);
Mat x(2, 1, CV_32F);

A.data[0] = 2;
A.data[1] = 1;
A.data[2] = 1;
A.data[3] = 1;
B.data[0] = 4;
B.data[1] = 3;

solve(A, B, x);

cout << "x0 = " << (float)x.data[0] << ", x1 = " << (float)x.data[1] << endl;
This is solving the following equation:

{ 2 1 } { x0} = { 4 }
{ 1 1 } { x1} = { 3 }

And I get the solution: x0 = 182, x1 = 62.

This is clearly wrong. The correct solution should be: x0 = 1, x1 = 2.

I have tried all the different solver types as the fourth argument, and they all return the same result.

What am I doing wrong?

Thanks!