# Stitching on video

**URL:** <https://forum.opencv.org/t/stitching-on-video/5870>\
**Category:** C++\
**Tags:** stitching\
**Created:** [October 27, 2021, 3:55am UTC](https://forum.opencv.org/t/stitching-on-video/5870 "2021-10-27T03:55:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rccr](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/rccr/32/3593_2.png) [@rccr](https://forum.opencv.org/u/rccr)\
**Post date:** [October 27, 2021, 3:55am UTC](https://forum.opencv.org/t/stitching-on-video/5870/1 "2021-10-27T03:55:47Z")

</div>

I have the following code:

```auto
    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?

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [October 27, 2021, 8:07am UTC](https://forum.opencv.org/t/stitching-on-video/5870/2 "2021-10-27T08:07:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rccr](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/rccr/32/3593_2.png) [@rccr](https://forum.opencv.org/u/rccr)\
**Post date:** [October 27, 2021, 1:08pm UTC](https://forum.opencv.org/t/stitching-on-video/5870/3 "2021-10-27T13:08:07Z")

</div>

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:

```auto
        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:

```auto
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

---

<div class="post-metadata">

**Author:** ![rccr](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/rccr/32/3593_2.png) [@rccr](https://forum.opencv.org/u/rccr)\
**Post date:** [October 31, 2021, 3:19am UTC](https://forum.opencv.org/t/stitching-on-video/5870/4 "2021-10-31T03:19:09Z")

</div>

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)
