VideoCapture 不会打开视频

VideoCapture will not open the video

我正在尝试打开一个视频并将其写入一个位置:

#include <opencv2/opencv.hpp>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "iostream"

using namespace cv;
using namespace std;

int main()
{
    string videoName = "KorExp3.avi";
    VideoCapture video(videoName);

    Mat frame;

    video >> frame;

    VideoWriter w("D:/w.avi", CV_FOURCC('M', 'P', '4', '2'), 30, frame.size(), true);
    while (true) {
        video >> frame;
        imshow("frame", frame);
        w << frame;
    }
    w.release();

    waitKey(0);
    return 0;
}

在调试模式下,将鼠标悬停在 video 上时显示:

Information not available, no symbols loaded for opencv_world340d.dll

我已将此 dll 文件和视频文件复制到 .exe 的相同位置,但仍然发生同样的事情。我也尝试了视频的绝对路径 string videoName = "D:\KorExp3.avi"; 但没有成功。

如何使用 openCV 捕获视频并将其写入某个位置?

你生成(编译)带有调试符号的 OpenCV 吗?? 这是使用 OpenCV 录制视频文件的示例(简单)代码... 我在 Linux 上使用 Qt(5.5.1 及更高版本),但这并不重要... 它适用于每个 OS...

void MainWindow::on_Rec_Click()
{
        QString szNome = QString("%1/%2-%3-M.mp4").arg(szPath).arg(szCamIndex).arg(obAgora.toString("yyyyMMddHHmmss"));
        qDebug() << szNome;

        char    szCPath[2048];
        strcpy(szCPath, szNome.toStdString().c_str());
        qDebug() << "Path: " << szCPath; 
        MakePath(szCPath, inIndice+1); // If the path does not exist...
        SaveEventToDB(szNome, inIndice+1, obAgora, 0); // Register event in DB
        qDebug() << m_Capture[inIndice - 1] << " / " << inIndice;
        cv::Size S = cv::Size((int) m_Capture[inIndice]->get(CV_CAP_PROP_FRAME_WIDTH),    // Acquire input size
                              (int) m_Capture[inIndice]->get(CV_CAP_PROP_FRAME_HEIGHT));

        qDebug() << S.width << " / " << S.height;

        int ex = cv::VideoWriter::fourcc('M','P','4','2');
        qDebug() << ex;

        double dlFrameRate = m_Capture[inIndice]->get(CV_CAP_PROP_FPS);
        qDebug() << dlFrameRate;

        m_Output = new cv::VideoWriter(szNome.toStdString(), ex, dlFrameRate, S, true);
        qDebug() << "Object cv::VideoWriter created.";

        m_OutputFile = szNome;
        m_inTimerID = startTimer(1000 / dlFrameRate);
}

void MainWindow::timerEvent(QTimerEvent *event)
{
    if(m_inActualView != 0) {
        cv::Mat image;
        *m_Capture[m_inActualView] >> image;

        if(m_Output) {
            if(m_Output->isOpened()) {
                *m_Output << image;
            }
        }
        cv::flip( image,image, 0);

        // Show the image
        m_Ui->openCVViewer->showImage( image );
    }
}

我把视频的目录,而不是移动到项目位置,错误解决:

string videoName = "D:\KorExp3.avi";
while (true) {
    video >> frame;
...