# line extension beyond 2 points how to extrapolate

No prob with this:

cv::line(color_img, points[0], points[1], Scalar(255, 255, 255), 1, LINE_8, 0);


How can I extend the line beyond each point(s). A different OpenCV fx?

edit retag close merge delete

Sort by ยป oldest newest most voted

There is no function to extend a line in OpenCV. Fortunately this is a simple geometry problem.

The formula for your line is:

P = points[0]+i*(points[1]-points[0])


where i in [0...1]. To draw a line just make a loop and set every P to a desired color.

To extend a line beyond the endpoints, just increase the range of i. Negative values will extend beyond point[0], values greater than 1 beyond point[1].

more

Thanks for the answer. Wanted to further clarify implementation. Does P need to be an array of points?

e Point2d P;
for (int i = 0; i < 3; i++)
{
P = point[0] + i * (point[1] - point[0]);
cv::line(img_color, point[0], point[1], Scalar(255, 0, 0), 1, LINE_8, 0);

}nter code here


Obviously my cv::line needs some reference to P. What would be the programming step.

( 2020-11-11 13:56:51 -0500 )edit

Update: I get it now. Once I broke apart the range it made a lot more sense, programmatically as well.

( 2020-11-11 14:13:06 -0500 )edit

Official site

GitHub

Wiki

Documentation