Stitching on video

I have the following code:

    cv::VideoCapture f1("video1.mp4");
    cv::VideoCapture f2("video2.mp4");
    cv::Mat pano;
    vector<cv::Mat> currentFrames(2);

    auto stitcher = cv::Stitcher::create();
    while (true) {

        if (!f1.read(currentFrames[0])) break;
        if (!f2.read(currentFrames[1])) break;

        stitcher->stitch( currentFrames, pano);

        cv::imshow("Pano", pano);
        int key = cv::waitKey(1);
        if (key == 27) break;
    }

I would expect this code to create a panoramic image for each pair of frames. However, what I get is a static image (it doesn’t change during the entire video!!!) that corresponds to the first frame of each video. The image is static, it is as if the rest of the frames are ignored.

I am using version 4.5.4 … is it an issue or am I missing something?

if you imshow each currentFrame(s), do they show changing content?

No, if I show currentFrames[0] and currentFrames[1] the content is static too, but the problem come from Sticher not from videos. If I do:

        if (!f1.read(currentFrames[0])) break;
        if (!f2.read(currentFrames[1])) break;

        // changing content !!!!
        cv::imshow("f1", currentFrames[0]);
        cv::imshow("f2", currentFrames[1]);

        stitcher->stitch( currentFrames, pano);

        // Static content !!!!
        cv::imshow("f1", currentFrames[0]);
        cv::imshow("f2", currentFrames[1]);

        cv::imshow("Pano", pano);
        int key = cv::waitKey(1);
        if (key == 27) break;

The problems occur after stitcher->stitch( currentFrames, pano); I would assume that the first argument of stitcher->stitch() is a read-only input argument but it seems that it is not, it takes a reference and overwrite the images with some cache

In fact I “solved” the problem doing this:

while (true) {
        if (!f1.read(currentFrames[0])) break;
        if (!f2.read(currentFrames[1])) break;

        auto stitcher = cv::Stitcher::create();
        stitcher->stitch( currentFrames, pano);
 
        cv::imshow("Pano", pano);
        int key = cv::waitKey(1);
        if (key == 27) break;
}

But, this is very ugly solution hahahaha

Update: The problem does not occur in a docker container (Ubuntu 18.04 and OpenCV 4.5.3) and also not in my Jetson Nano (OpenCV 4.5.3), so I think it is an OpenCV bug related to Ubuntu 20.04 (where I have the problem)