Search code examples
c++image-processingopencvjavacv

What is the meaning of following method in opencv?


I'm doing project on object detection using javacv in that I went through couple of code examples which use to detect rectangles and I found that all most all the code examples contains following method inside those classes.

Please can some one explain the meaning or the usage of this method.

double angle( CvPoint* pt1, CvPoint* pt2, CvPoint* pt0 )
{
    double dx1 = pt1->x - pt0->x;
    double dy1 = pt1->y - pt0->y;
    double dx2 = pt2->x - pt0->x;
    double dy2 = pt2->y - pt0->y;
    return (dx1*dx2 + dy1*dy2)/sqrt((dx1*dx1 + dy1*dy1)*(dx2*dx2 + dy2*dy2) + 1e-10);
} 

This is the source of that method.


Solution

  • As you can guess this calculates cosine of the angle of two vectors (pt1, pt0) , (pt2, pt0)

    The formula is like this: Cos(theta) = DotProduct(a,b) / (length(a) * length(b))

    enter image description here

    For the last part 1e-10, thats probably to avoid division by zero error on zero length vectors.