video stitching problem
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;
}
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
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).
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 :
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?
I don't think so but you can duplicate first video use like this two video files
Yeah! I'm doing in this way. :( Is it running fine at your end?
Yes there is no problem with your code using my videos
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.
I don't think it's possible to download video here. may you find something on google yahoo bing...
@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.