Найти точку пересечения линии и эллипса в OpenCVPython

Программы на Python
Anonymous
Найти точку пересечения линии и эллипса в OpenCV

Сообщение Anonymous »

Я пытаюсь найти точку пересечения линии и эллипса. Я могу найти точку вручную, как показано в коде, но как я могу найти ее автоматически. Кроме того, когда красная точка находится внутри эллипса, зеленая точка также должна проецироваться на эллипс при продлении линии. Как я могу это решить? Примеры кода приветствуются! Спасибо!
Изображение

Код: Выделить всё

import cv2
import numpy as np

# Parameters
ellipse_center = np.array([238, 239])
ellipse_axes = np.array([150, 100])  # Semi-major and semi-minor axes
ellipse_angle = np.radians(70)  # Angle of rotation (in radians)

line_point1 = ellipse_center  # Point on the line
line_point2 = np.array([341, 125])  # Another point on the line (moving point)

# Initialize OpenCV window
window_name = "Projecting Point on Rotated Ellipse"
cv2.namedWindow(window_name)
canvas = np.zeros((400, 400, 3), dtype=np.uint8)

while True:
# Clear canvas
canvas.fill(0)

# Draw the rotated ellipse
cv2.ellipse(canvas, tuple(ellipse_center), tuple(ellipse_axes), np.degrees(ellipse_angle), 0, 360, (255, 255, 255), 2)

# Draw the moving point
cv2.circle(canvas, (int(line_point2[0]), int(line_point2[1])), 5, (0, 0, 255), -1)

# Draw the center point of the ellipse
cv2.circle(canvas, tuple(ellipse_center), 5, (0, 255, 255), -1)

# Draw the line between moving point and the center of the ellipse
cv2.line(canvas, (int(line_point2[0]), int(line_point2[1])), tuple(ellipse_center), (0, 0, 255), 1)

intersection_points = (310, 159) # 

Подробнее здесь: [url]https://stackoverflow.com/questions/78320551/find-intersection-point-between-line-and-ellipse-in-opencv[/url]

Вернуться в «Python»