如何绘制线而不是线段OpenCV 2.4.2 [英] How to draw line not line segment OpenCV 2.4.2

查看:477
本文介绍了如何绘制线而不是线段OpenCV 2.4.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题说明了一切

我知道函数Line(),该函数在两点之间绘制线段.

我还需要使用线段的两个点画一条线段.


[ZH:根据先前发布的问题答案进行编辑]

我使用了您的解决方案,它在水平线上的效果很好,但是在垂直线上仍然有问题.

例如,在下面的示例中,在具有600x600像素的图像上使用点[306,411]和[304,8](紫色)和绘制线(红色).你有小费吗?

解决方案

您将需要编写一个函数自己完成操作.建议您将线条以ax + by + c = 0的形式放置,然后与图像的4个边缘相交.请记住,如果您有[a b c]形式的线,发现其与另一条线的交点只是两者的叉积.图片的边缘将是

top_horizontal =    [0 1 0];
left_vertical   =   [1 0 0];
bottom_horizontal = [0 1 -image.rows];
right_vertical =    [1 0 -image.cols];

此外,如果您对点之间的距离有所了解,您还可以沿每个方向沿直线选择很远的点,我认为传递给Line()的点不必在图像上. /p>

Well the question says it all,

I know the function Line(), which draws line segment between two points.

I need to draw line NOT a line segment, also using the two points of the line segment.


[EN: Edit from what was previously posted as an answer for the question]

I used your solution and it performed good results in horizontal lines, but I still got problems in vertical lines.

For example, follows below an example using the points [306,411] and [304,8] (purple) and the draw line (red), on a image with 600x600 pixels. Do you have some tip?

解决方案

You will need to write a function to do that for yourself. I suggest you put your line in ax+by+c=0 form and then intersect it with the 4 edges of your image. Remember if you have a line in the form [a b c] finding its intersection with another line is simply the cross product of the two. The edges of your image would be

top_horizontal =    [0 1 0];
left_vertical   =   [1 0 0];
bottom_horizontal = [0 1 -image.rows];
right_vertical =    [1 0 -image.cols];

Also, if you know something about the distance between your points you could also just pick points very far along the line in each direction, I don't think the points handed to Line() need to be on the image.

这篇关于如何绘制线而不是线段OpenCV 2.4.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆