How to Find Dot Product of Two Lines (Opencv)

anjaryes picture anjaryes · Dec 12, 2013 · Viewed 9.3k times · Source

I'm working on a program that require me to find the angle between two lines. I have found all of the points coordinates of the lines, referenced into the 0,0 points, but i dont understand how to implement the dot product in Opencv to find the angle.

I use visual C++ using opencv library. I also found out that i can use cv::Mat::dot function to get dot product, but i can't find any good example. I can not understand the explanation in this link.

Can anyone give me a good example? so i can understand how to use that function to find dot product of two lines. Thank you.

Answer

Hannes Ovrén picture Hannes Ovrén · Dec 12, 2013

If you have two vectors representing your lines, and call them a and b (of type cv::Mat) then the dot product is calculated as

double p = a.dot(b);

Edit Example code, by comments from author.

float a[2] = {1.0, 2.0};
float b[2] = {3.0, 4.0};

cv::Mat AA(1,2,CV_32FC1,a);
cv::Mat BB(1,2,CV_32FC1,b);

cout << AA << endl;
cout << BB << endl;
cout << AA.dot(BB) << " should be equal to 11" << endl;