[Python] OpenCV Intersection between Ellipses and and Line

Discussão em 'Python' iniciado por Stack, Outubro 4, 2024.

  1. Stack

    Stack Membro Participativo

    I am trying to find the intersection points from an ellipses with a line.

    I extract an ellipses from an image, and get the RotatedRect from fitEllipse. Now I paint several lines, and they (ideally) intersect with the ellipse. I need to find the intersection points.

    This is basically the raw image.

    [​IMG]

    I want to find those points.

    [​IMG]

    Here would be some test vectors.

    ` import cv2
    import numpy as np

    ellipse_center = np.array([439, 326])
    ellipse_axes = np.array([int(283/2), int(565/2)])
    ellipse_angle = np.radians(91)

    line_point1 = np.array([583, 450])
    line_point2 = np.array([292, 115])

    window_name = "Demo"
    cv2.namedWindow(window_name)
    canvas = np.zeros((600, 800, 3), dtype=np.uint8)

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

    cv2.ellipse(canvas, tuple(ellipse_center), tuple(ellipse_axes), np.degrees(ellipse_angle), 0, 360, (0, 0, 255), 2)
    cv2.line(canvas, (293,115), (584,450), (0,0,255), 2)
    cv2.line(canvas, (70,290), (404,279), (0,0,255), 2)
    cv2.line(canvas, (59,353), (411,285), (0,0,255), 2)
    cv2.line(canvas, (463,272), (755,220), (0,0,255), 2)


    # Show canvas
    cv2.imshow(window_name, canvas)

    # Exit if 'q' is pressed
    if cv2.waitKey(1) & 0xFF == ord('q'):
    break

    # Close OpenCV window
    cv2.destroyAllWindows()`

    Continue reading...

Compartilhe esta Página