Tibe Demeulemeester
Tibe Demeulemeester

Reputation: 1

Is there a way to cache the warping points generated by the plane warper in OpenStitching, thus avoiding recalculation for every frame?

I'm working on a Python script to process two video files, calibrate them, and merge them into a single panoramic view. Since both cameras remain stationary, my objective is to compute the seam mask and warping points just once for reuse. Currently, the panorama creation isn't achieving the desired 30 FPS due to the time-consuming nature of the plane warping method. Therefore, I'm seeking a solution to compute and save the points used in the plane warper to avoid recalculating them for each frame.

These are currently the 2 functions I am using.

The function getCamSeammask that stores the camera parameters and seammask in a variables so you don't have to recalculate them for every 2 frames.

def getCamSeammask (frameLeft, frameRight):
    global cameraMask

    images = Images.of([frameLeft, frameRight])
    medium_imgs = images.resize(Images.Resolution.MEDIUM)
    final_imgs = list(images.resize(Images.Resolution.FINAL))
    features = [FINDER.detect_features(img) for img in medium_imgs]
    matches = MATCHER.match_features(features)
    conf = MATCHER.get_confidence_matrix(matches)
    cameras = CAMERA_ESTIMATOR.estimate(features,matches)
    cameras = CAMERA_ADJUSTER.adjust(features,matches,cameras)
    cameras = WAVE_CORRECTOR.correct(cameras)
    WARPER.set_scale(cameras)
    final_sizes = images.get_scaled_img_sizes(Images.Resolution.FINAL)
    camera_aspect = images.get_ratio(Images.Resolution.MEDIUM, Images.Resolution.FINAL)
    warped_final_imgs = list(WARPER.warp_images(final_imgs, cameras, camera_aspect))
    warped_final_masks = list(WARPER.create_and_warp_masks(final_sizes, cameras, camera_aspect))
    final_corners, final_sizes = WARPER.warp_rois(final_sizes, cameras, camera_aspect)
    seamMask = SEAM_FINDER.find(warped_final_imgs, final_corners, warped_final_masks)
    cameraMask = (cameras, seamMask)

And the function getPanorama that creates the panorama.

def getPanorama(frameLeft, frameRight):
    cam = cameraMask[0]
    seammask = cameraMask[1]
    images = Images.of([frameLeft, frameRight])
    final_sizes = images.get_scaled_img_sizes(Images.Resolution.FINAL)
    camera_aspect = images.get_ratio(Images.Resolution.MEDIUM, Images.Resolution.FINAL)

    warped_final_imgs = list(WARPER.warp_images([frameLeft,frameRight], cam, camera_aspect))
    final_corners, final_sizes = WARPER.warp_rois(final_sizes, cam, camera_aspect)
    BLENDER.prepare(final_corners, final_sizes)

    for img, mask, corner in zip(warped_final_imgs, seammask, final_corners):
        BLENDER.feed(img, mask, corner)

    panorama,_ = BLENDER.blend()
    return panorama

I'm utilizing the OpenStitching library in Python, which is built on top of OpenCV.

Upvotes: 0

Views: 112

Answers (1)

Lukas Weber
Lukas Weber

Reputation: 721

I'm seeking a solution to compute and save the points used in the plane warper to avoid recalculating them for each frame

This was already asked and answered here and here

You could extend the approach to save the seam masks of the first video frame

Upvotes: 0

Related Questions