OpenCV 和 Python 中直线的反射

发布于 2025-01-14 11:12:38 字数 385 浏览 0 评论 0原文

我正在尝试计算 OpenCV 中一条线在表面上的反射。

我使用一个弹丸进行跟踪,它正在绘制线 2 和边框。

我“只是”想画一条反弹角度的线,正如您在我的绘图中看到的那样。

Skizze 1

我得到了一个计算三个给定点的角度的代码,但在我的示例中,第 2 行不是静态的。它会移动,因为它是由移动的射弹牵引的。因此,为了计算这个,我需要边界和 2 号线的交点。我有点费劲去得到它。.

有没有一种简单的方法来解决这个问题?

谢谢。

I am trying to calculate the reflection of a line on a surface in OpenCV.

I work with a projectile im tracking which is drawing line 2 and a border.

I "just" want to draw a line of the bounce angle as you can see in my drawing.

Skizze 1

I got a code that calculate the angle of three given points but in my example line 2 is not static. It will move because its drawn by a moving projectile. So to calculate this i need the intersection point of the border and Line 2. Im kinda struggeling to get that..

Is there an easy way to solve this ?

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

長街聽風 2025-01-21 11:12:38

根据您的评论:

射弹坐标 (P0)

(center_x, center_y)

撞击点 (P1)

(predicted2[0], predicted2[1])

边界极值 (A, B)

(Ax, Ay), (Bx, By)

我假设 P1 属于该段AB。

应将 P0 投影在经过 A、B 的直线上。称此点为 PP。然后您应该计算

arctan(distance(PP,P1)/distance(P0,PP))

This 等于 alpha,您可以用它来计算反射段,具体取决于它的长度。

我建议使用 shapely 库:

https://shapely.readthedocs.io/en/稳定/manual.html

From your comment:

Projectile coordinates (P0)

(center_x, center_y)

Impact point (P1)

(predicted2[0], predicted2[1])

Border extremes (A, B)

(Ax, Ay), (Bx, By)

I assume that P1 belongs to the segment AB.

You should project P0 in the straight line passing by A, B. Call this point PP. You should then compute

arctan(distance(PP,P1)/distance(P0,PP))

This is equal to alpha, that you can use to compute the reflection segment, depending on how long it is.

I suggest to use the shapely library:

https://shapely.readthedocs.io/en/stable/manual.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文