gpt4 book ai didi

c++ - VideoCapture 不会打开视频

转载 作者:行者123 更新时间:2023-11-28 04:10:26 26 4
gpt4 key购买 nike

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

#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;
}

在 Debug模式下,将鼠标悬停在 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 及更高版本),但这并不重要......它适用于所有操作系统...

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 );
}
}

关于c++ - VideoCapture 不会打开视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57926676/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com