First time here? Check out the FAQ!

Ask Your Question
0

line extension beyond 2 points how to extrapolate

asked Nov 11 '0

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?

Preview: (hide)

1 answer

Sort by » oldest newest most voted
0

answered Nov 11 '0

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

Preview: (hide)

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 (Nov 11 '0)edit

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

superfly gravatar imagesuperfly (Nov 11 '0)edit

Question Tools

1 follower

Stats

Asked: Nov 11 '0

Seen: 2,041 times

Last updated: Nov 11 '20