Hi, I am trying to calculate eigenvectors but I am getting huge eigenvalues. As result, I am getting vector component 0. It will be great if you suggest the way.
int main() { Mat img = Mat::zeros(500, 500, CV_8U); ellipse(img, RotatedRect(Point(250, 250), Size(300, 200), 30), 255, FILLED);
Moments m = moments(img, true);
Point p(m.m10 / m.m00, m.m01 / m.m00);
double u20 = ((m.m20 / m.m00) - (p.x * p.x));
double u02 = ((m.m02 / m.m00) - (p.y * p.y));
double u11 = ((m.m11 / m.m00) - (p.x * p.y));
double angle = 0.5 * atan((2 * u11) / ( u20 - u02));
double eigenValue1 = 0.5 * (u20 + u02) + 0.5 * sqrt((4 * u11 * u11) + (u20 - u02) * (u20 - u02));
double eigenValue2 = 0.5 * (u20 + u02) - 0.5 * sqrt((4 * u11 * u11) + (u20 - u02) * (u20 - u02));
double a[2][2] = {{ u20 - eigenValue1, u11 }, { u11, u02 - eigenValue1 } };
double b[2][1] = { { 0 }, { 0 } };
Mat A = Mat(2, 2, CV_32FC1, a);
Mat B = Mat(2, 1, CV_32FC1, b);
Mat v = A.inv() * B;
cout << "v= " << endl << " " << v << endl;
waitKey(0);
return 0;
}