[英]OpenCV frame by frame video stitching
我试图拼接来自两个不同角度设置的不同相机的输入。 我应该怎么做才能将摄像机的输出(每一帧一帧一帧)合并为一帧?
当我将输入作为以前录制的视频(“InputVideo1.mp4”和“InputVideo2.mp4”,如下所述)时,视频输入生成的帧会拼接。 但是,当我启用相机作为输入时,OpenCV Stitcher 返回枚举“ERR_NEED_MORE_IMGS = 1”。
// Create a VideoCapture object and open the input file
//VideoCapture vCap("InputVideo1.mp4");
//VideoCapture vCap1("InputVideo2.mp4");
// If the input is the web camera, pass 0 instead of the video file name
VideoCapture vCap(0);
VideoCapture vCap1(1);
// Check if the camera opened successfully
if (!vCap.isOpened()) {
cout << "Error opening video stream or file" << endl;
return -1;
}
if (!vCap1.isOpened()) {
cout << "Error opening video stream or file" << endl;
return -2;
}
while (1) {
Mat frame, frame1, finalFrame;
// Capture frame-by-frame
vCap >> frame;
vCap1 >> frame1;
// If the frame is empty, break immediately
if (frame.empty()) {
cout << "Frame is empty" << endl;
break;
}
if (frame1.empty()) {
cout << "Frame1 is empty" << endl;
break;
}
// Display the resulting frame
imshow("First frame", frame);
imshow("Second frame", frame1);
// Push each frame one by one into the final vector
vector<Mat> finalFrameImages;
finalFrameImages.push_back(frame);
finalFrameImages.push_back(frame1);
// Stitch all frames that are stored the final frame images vector set
Stitcher::Mode mode = Stitcher::PANORAMA;
Ptr<Stitcher> stitcher = Stitcher::create(mode);
Stitcher::Status status = stitcher->stitch(finalFrameImages, finalFrame);
if (status != Stitcher::OK) {
cout << "Can't stitch images" << endl;
return status;
}
imshow("Resulting frame", finalFrame);
}
Stitcher::Status 状态应该返回 0 但它返回 1。
可能是图片一样。 看看这张图: 现在我们看到在配准块中,该方法查看两个图像之间的特征并匹配它们以正确进行拼接。 建议您在拼接之前检查是否导入了好的图像,我看不出其他问题。 除此之外,请查看此链接
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.