[Python] Stitching Images with Two Different Camera Positions

Discussão em 'Python' iniciado por Stack, Fevereiro 25, 2025.

  1. Stack

    Stack Membro Participativo

    It may not be possible to do what I want, but I thought I would throw the question out there just in case.

    I am attempting to stitch the following two images together that are taken from two different camera position.

    [​IMG]

    They are taken at the exact same time, and as you can see, they have different perspectives. I recognize that I could accomplish this by taking two photos at different angles from the same camera position, but in this instance I am specifically looking for a solution using different camera positions.

    When I stitch them with this code:

    images = []
    image1 = cv2.imread('./VideosToStitch/video2.png')
    images.append(image1)
    image2 = cv2.imread('./VideosToStitch/video1.png')
    images.append(image2)

    stitcher = cv2.Stitcher.create()
    status, stitched = stitcher.stitch(images,cv2.Stitcher_PANORAMA)

    cv2.imwrite('./VideosToStitch/stitched.png', stitched)


    I get this:

    [​IMG]

    The two blue lines look good, but as you can see the red line is broken. I thought perhaps I could apply a perspective transformation on the images first and then stitch them, but when I apply the warp perspective, I get this:

    image1 = cv2.imread('./VideosToStitch/video1.png')

    tl = (907,0)
    bl = (0,1280)
    tr = (1047,0)
    br = (1920,1280)

    pts1 = np.float32([tl,bl,tr,br])
    pts2 = np.float32([[0,0],[0,1280],[1920,0],[1920,1280]])

    matrix = cv2.getPerspectiveTransform(pts1,pts2)
    transformedFrame = cv2.warpPerspective(image1, matrix,(1920,1280), flags=3)


    [​IMG]

    Here you can see the red and blue lines are now straight, but I have lost all the detail on the ice surface. This could work if it is possible to apply the transformation in the horizontal axis only, and not the vertical axis. Or, alternatively, I could stitch them so the resulting image is curved, and then straighten it.

    Thoughts?

    To add illustration to Christoph Rackwitz comments below, here is the result if I adjust the perspective so the ice surface lines align both horizontally and vertically. As you see, the players which are perpendicular to the surface will never align.

    [​IMG]

    Continue reading...

Compartilhe esta Página