我正在尝试拼接来自两个不同角度的不同相机的输入。我应该怎么做才能将相机的输出(一帧一帧)合并到一个帧中?
当我将输入作为先前录制的视频(“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。