1

我正在尝试拼接来自两个不同角度的不同相机的输入。我应该怎么做才能将相机的输出(一帧一帧)合并到一个帧中?

当我将输入作为先前录制的视频(“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。

4

1 回答 1

1

可能图片是一样的。看一下这张图: 现在我们看到,在注册块中,该方法查看两个图像之间的特征并匹配它们以正确地进行拼接。建议您在拼接之前检查是否导入了好的图像,我看不到其他问题。除此之外,请查看此链接

于 2019-08-28T17:52:05.050 回答