# Result from Euc Distance Calculation

Hello, I'm calculating the euc line and the degree for 2 points. Most of the results are OK but sometimes there are results showed like this.

-1.#IND,-1.#IND

May I know what does this means?

The formula for the ecludian distance and the degree (atan) as below.

Point2f a = mc; Point2f b = mc; double res = cv::norm(a-b);

double deg = atan((b.y-a.y)/(b.x-a.x)) * 180 / PI;

thanks

edit retag close merge delete

Does the a and b points have the same x? If so, there is a division by 0, so just do an if there

based on the output from the program.

 if((mc.size() == 2)&&flagsave==0)
{
centroid =2;
Point2f a = mc;
Point2f b = mc;
double res = cv::norm(a-b);
std::cout << "Res" <<res << std::endl;
std::cout << "a" <<a << std::endl;
std::cout << "b" <<b << std::endl;

double deg = atan((b.y-a.y)/(b.x-a.x)) * 180 / PI;
std::cout << "(b.x-a.x)" <<(b.x-a.x) << std::endl;
std::cout << "(b.y-a.y)" <<(b.y-a.y) << std::endl;
std::cout << "deg" <<deg<< std::endl;
}


Results - it does not say it is 0. consistent with -1.#IND. What is that?

 Res-1.#IND
a[-1.#IND, -1.#IND]
b[65.0653, 30.9768]
(b.x-a.x)-1.#IND
(b.y-a.y)-1.#IND
deg-1.#IND

1

-1.#IND is a kind of infinite, like in division by 0 or something like that

Have you tried to do a res = cv::norm(a, b)? Anyway, the problem is in a, it has already infinite values. How did you compute the mc?

mc is the centroid point by using this vector<point2f> mc( contours.size() );

for( int i = 0; i < contours.size(); i++ ) { mc[i] = Point2f( mu[i].m10/mu[i].m00 , mu[i].m01/mu[i].m00 ); circle( draw, mc[i], 4, Scalar(0,0,255), -1, 8, 0 );//waitKey(0); }

I get the blob area binary image and calculate the centroid of the white blob area.

So, you are doing a division by mu[i].m00 There may be the cause of the -1.#IND. Check for the cause there ;)

@thdrksdfthmn u are correct. I details out the value and found out this.

m10/mu[i].m0 = 00

Is it anyway that I can solve on this matter?

Your moments are computed on a binary image, so you need to look in that image, what are the problems, why is it 0? Does the image have any white regions? If you find why is that 0, then you shall treat that case special. Bu what version of OpenCV are you using? Could this be a bug, from theory: m00, could be 0 only if all the points have at least one coordinate 0?

I found out that, the output seeing a very small white region at (0,0) which is proven inside the image where I draw a line from another centroid which is quite weird. I'm using 2.4.11 opencv version. Is it a bug or something else?

I do not think it is a bug (but it may be treated by someone as a special case). I would say that you r problem is in the image, why do you have that white top-left corner region (one pixel, or something like that)? I would suggest you to find why do you get in this case and fix the problem there

Sort by » oldest newest most voted

ok noted.. thanks for all the explaination. :)

more

Official site

GitHub

Wiki

Documentation