Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The answer depends on how you represent the line objects.

As you may have found out yourself, OpenCV does not come with a standard representation for 2D lines, whether it is finite (line segment), semi-finite (ray), or infinite (line equation).

Due to historical reasons, each algorithm that uses line objects adopt whatever was more convenient, or rather more "historical", representation.

Most of the time, when the finite line segment representation is used, the point pair (two cv::Point_<T> objects) are used to denote the two endpoints.

In some other usage, the line equation a * x + b * y + c == 0 would be far more convenient; unfortunately OpenCV does not provide native support for it.

To answer your question, when the point-pair representation is used, the cosine formula can be used.

http://mathworld.wolfram.com/Line-LineAngle.html

As an unrelated but useful note, you can find a lot of mathematically relevant answers on the Wolfram MathWorld website. It only requires high-school geometry and calculus to be able to search for answers there.