video stitching problem

asked 2015-11-25 04:53:23 -0500

updated 2015-11-25 09:06:43 -0500

I'm trying to do video stitching but when I try this code then I get the message that "Could not initialize capturing for camera2"

warning: Error opening file < /build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:578 >

#include <iostream>
#include <fstream>
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/stitching.hpp"

using namespace std;
using namespace cv;

bool try_use_gpu = false;
vector<Mat> imgs;
string result_name = "result.jpg";

void printUsage();
int parseCmdArgs(int argc, char** argv);

int main(int argc, char* argv[])
{

        Mat fr1, fr2, copy1, copy2, pano;
        bool try_use_gpu = false;
        vector<Mat> imgs;
        VideoCapture cap1, cap2;

        string filename1 = "C:/Users/user/Desktop/lkt/build/Debug/me.avi";  

        cap1.open(filename1);

        if (!cap1.isOpened())
        {
            cout << "Could not initialize capturing for camera1...\n";
            return 0;
        }

        string filename2 = "C:/Users/user/Desktop/lkt/build/Debug/mee.avi";


        cap2.open(filename2);

        if (!cap2.isOpened())
        {
            cout << "Could not initialize capturing for camera2...\n";
            return 0;
        }

        //while (true)
        for (;;)
        {
            cap1 >> fr1;
            cap2 >> fr2;
            fr1.copyTo(copy1);
            fr2.copyTo(copy2);

            imgs.push_back(copy1);
            imgs.push_back(copy2);

            Stitcher stitcher = Stitcher::createDefault(1);
            Stitcher::Status status = stitcher.stitch(imgs, pano);

            if (status != Stitcher::OK)
            {
                cout << "Can't stitch images, error code = " << int(status) << endl;
                return -1;
            }

            imwrite(result_name, pano);
            imshow("Pano", pano);
            waitKey();

        }

return 0;
}
edit retag flag offensive close merge delete

Comments

Have you try to swap first and second video? Line is your error message is not loaded in my code.

You can set cap2.open(filename1); It works in my program with filename1. In that case stitching is simple but it will check your program

LBerger gravatar imageLBerger ( 2015-11-25 09:43:54 -0500 )edit

This works but now it says that "Can't stitch images, error code = 1". Can this stitching class be used for videos instead of images? like a single video has frames and they can be considered as a series of images and I've made a loop for stitching frame by frame (one video with second video).

Ayesha Siddique gravatar imageAyesha Siddique ( 2015-11-25 23:18:54 -0500 )edit

About first problem with error message ""Could not initialize capturing for camera2" there is a problem with this video I think. New error message "Can't stitch images, error code = 1". may be image are black. You can check image :

imgs.push_back(copy1);
imgs.push_back(copy2);
imshow("Video 1", copy1); // New line to insert
imshow("Video 2", copy1);// New line to insert
waitKey();// New line to insert
Stitcher stitcher = Stitcher::createDefault(1);
LBerger gravatar imageLBerger ( 2015-11-26 07:10:44 -0500 )edit

It is displaying the frames proerly and they are not blank. I'm using single video for both of the video inputs. Can it cause any problem?

Ayesha Siddique gravatar imageAyesha Siddique ( 2015-11-26 09:09:04 -0500 )edit
1

I don't think so but you can duplicate first video use like this two video files

LBerger gravatar imageLBerger ( 2015-11-26 09:18:43 -0500 )edit

Yeah! I'm doing in this way. :( Is it running fine at your end?

Ayesha Siddique gravatar imageAyesha Siddique ( 2015-11-26 23:13:17 -0500 )edit
1

Yes there is no problem with your code using my videos

LBerger gravatar imageLBerger ( 2015-11-27 06:54:55 -0500 )edit

can i upload my video over here? and how can I do so? may be there is some problem with it because I'm running the same code and this time, it should run now.

Ayesha Siddique gravatar imageAyesha Siddique ( 2015-11-27 13:38:47 -0500 )edit

I don't think it's possible to download video here. may you find something on google yahoo bing...

LBerger gravatar imageLBerger ( 2015-11-27 13:49:32 -0500 )edit

@LBerger Thankyou. Can you guide me here link text so that I can proceed further and learn OpenCV. Some code related to storing of feature trajectories is also provided on internet for OpenCV but I need to do it with lkdemo as its OpenCV's own file so it will have good results too that's why I need to practice it and learn OpenCV in this way.

Ayesha Siddique gravatar imageAyesha Siddique ( 2015-11-28 07:16:40 -0500 )edit