Ask Your Question
0

line extension beyond 2 points how to extrapolate

asked 2020-11-11 09:54:01 -0600

superfly gravatar image

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 flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-11-11 11:45:33 -0600

kbarni gravatar image

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].

edit flag offensive delete link more

Comments

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.

superfly gravatar imagesuperfly ( 2020-11-11 13:56:51 -0600 )edit

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

superfly gravatar imagesuperfly ( 2020-11-11 14:13:06 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-11-11 09:54:01 -0600

Seen: 1,823 times

Last updated: Nov 11 '20