C++ 访问视频的每一帧并对其进行处理
我正在尝试编写一个程序,使用带有CPP的C++ 访问视频的每一帧并对其进行处理,c++,opencv,live-streaming,C++,Opencv,Live Streaming,我正在尝试编写一个程序,使用带有CPP的OPENCV将视频文件的每一帧存储为图像。我通过ffmpeg和mplayer实现了这一点。我想使用OPENCV获取它。有人能帮忙吗?除了IMWRITE(),是否还有其他函数将图像存储到文件中 OPENCV中是否有任何功能可以获取设备特定端口上的实时视频流并实时处理?i、 是否将流的每一帧存储为图像? 有人能帮我吗 提前感谢..:)保存所有带有递增编号文件名的图像,这对我很有用: const char* videofilename = "StopMoti20
OPENCV
将视频文件的每一帧存储为图像。我通过ffmpeg
和mplayer
实现了这一点。我想使用OPENCV
获取它。有人能帮忙吗?除了IMWRITE()
,是否还有其他函数将图像存储到文件中
OPENCV
中是否有任何功能可以获取设备特定端口上的实时视频流并实时处理?i、 是否将流的每一帧存储为图像?
有人能帮我吗
提前感谢..:)保存所有带有递增编号文件名的图像,这对我很有用:
const char* videofilename = "StopMoti2001.mpeg";
cv::VideoCapture cap(videofilename); // open a video file
if(!cap.isOpened()) // check if succeeded
{
std::cout << "file " << videofilename << " not found or could not be opened" << std::endl;
return;
}
cv::namedWindow("output");
unsigned long counter = 0;
cv::Mat frame;
// read frames until end of video:
while(cap.read(frame))
{
// display frame
cv::imshow("output", frame); cv::waitKey(25); // remove this line if you don't need the live output
// adjust the filename by incrementing a counter
std::stringstream filename (std::stringstream::in | std::stringstream::out);
filename << "image" << counter++ << ".jpg";
std::cout << "writing " << filename.str().c_str() << " to disk" << std::endl;
// save frame to file: image0.jpg, image1.jpg, and so on...
cv::imwrite(filename.str().c_str(),frame);
}
const char*videofilename=“StopMoti2001.mpeg”;
cv::VideoCapture cap(videofilename);//打开一个视频文件
if(!cap.isOpened())//检查是否成功
{
std::cout保存所有带有递增编号文件名的图像,这对我很有用:
const char* videofilename = "StopMoti2001.mpeg";
cv::VideoCapture cap(videofilename); // open a video file
if(!cap.isOpened()) // check if succeeded
{
std::cout << "file " << videofilename << " not found or could not be opened" << std::endl;
return;
}
cv::namedWindow("output");
unsigned long counter = 0;
cv::Mat frame;
// read frames until end of video:
while(cap.read(frame))
{
// display frame
cv::imshow("output", frame); cv::waitKey(25); // remove this line if you don't need the live output
// adjust the filename by incrementing a counter
std::stringstream filename (std::stringstream::in | std::stringstream::out);
filename << "image" << counter++ << ".jpg";
std::cout << "writing " << filename.str().c_str() << " to disk" << std::endl;
// save frame to file: image0.jpg, image1.jpg, and so on...
cv::imwrite(filename.str().c_str(),frame);
}
const char*videofilename=“StopMoti2001.mpeg”;
cv::VideoCapture cap(videofilename);//打开一个视频文件
if(!cap.isOpened())//检查是否成功
{
std::cout保存所有带有递增编号文件名的图像,这对我很有用:
const char* videofilename = "StopMoti2001.mpeg";
cv::VideoCapture cap(videofilename); // open a video file
if(!cap.isOpened()) // check if succeeded
{
std::cout << "file " << videofilename << " not found or could not be opened" << std::endl;
return;
}
cv::namedWindow("output");
unsigned long counter = 0;
cv::Mat frame;
// read frames until end of video:
while(cap.read(frame))
{
// display frame
cv::imshow("output", frame); cv::waitKey(25); // remove this line if you don't need the live output
// adjust the filename by incrementing a counter
std::stringstream filename (std::stringstream::in | std::stringstream::out);
filename << "image" << counter++ << ".jpg";
std::cout << "writing " << filename.str().c_str() << " to disk" << std::endl;
// save frame to file: image0.jpg, image1.jpg, and so on...
cv::imwrite(filename.str().c_str(),frame);
}
const char*videofilename=“StopMoti2001.mpeg”;
cv::VideoCapture cap(videofilename);//打开一个视频文件
if(!cap.isOpened())//检查是否成功
{
std::cout保存所有带有递增编号文件名的图像,这对我很有用:
const char* videofilename = "StopMoti2001.mpeg";
cv::VideoCapture cap(videofilename); // open a video file
if(!cap.isOpened()) // check if succeeded
{
std::cout << "file " << videofilename << " not found or could not be opened" << std::endl;
return;
}
cv::namedWindow("output");
unsigned long counter = 0;
cv::Mat frame;
// read frames until end of video:
while(cap.read(frame))
{
// display frame
cv::imshow("output", frame); cv::waitKey(25); // remove this line if you don't need the live output
// adjust the filename by incrementing a counter
std::stringstream filename (std::stringstream::in | std::stringstream::out);
filename << "image" << counter++ << ".jpg";
std::cout << "writing " << filename.str().c_str() << " to disk" << std::endl;
// save frame to file: image0.jpg, image1.jpg, and so on...
cv::imwrite(filename.str().c_str(),frame);
}
const char*videofilename=“StopMoti2001.mpeg”;
cv::VideoCapture cap(videofilename);//打开一个视频文件
if(!cap.isOpened())//检查是否成功
{
std::cout为什么cv::imwrite
不适合您?它只复制了最后一帧。我想将所有帧保存为image1.jpg,image2.jpg…为什么cv::imwrite
不适合您?它只复制了最后一帧。我想将所有帧保存为image1.jpg,image2.jpg…为什么cv::imwrite
不适合您?它只复制了ast帧。我想将所有帧保存为image1.jpg,image2.jpg…为什么cv::imwrite
不适合您?它只复制了最后一帧。我想将所有帧保存为image1.jpg,image2.jpg…谢谢..我尝试了该程序,但我遇到了一个分割错误(内核转储)错误是否显示了任何图像或写入了任何文件?for(;;)
不太好,因为对于视频文件(不同于现场摄像机),文件的某个地方会有一个结尾;)你能把你的代码片段贴在你使用的只保存了最后一张图像的地方吗?我会根据你的需要修改它。我刚刚使用了imwrite(“文件名”,frame)你能试着运行更新后的代码并告诉我你得到了什么控制台输出吗?谢谢。我尝试了这个程序,但我得到了一个分割错误(内核转储)错误。是否显示了任何图像或写入了任何文件?(;;)
的不太好,因为视频文件(不同于实时摄像机)文件的某个地方会有一个结尾;)你能把你的代码片段放在只保存了最后一张图像的地方吗?我会根据你的需要修改它。我刚刚用了imwrite(“文件名”,frame)你能试着运行更新后的代码并告诉我你得到了什么控制台输出吗?谢谢。我尝试了这个程序,但我得到了一个分割错误(内核转储)错误。是否显示了任何图像或写入了任何文件?(;;)
的不太好,因为视频文件(不同于实时摄像机)文件的某个地方会有一个结尾;)你能把你的代码片段放在只保存了最后一张图像的地方吗?我会根据你的需要修改它。我刚刚用了imwrite(“文件名”,frame)你能试着运行更新后的代码并告诉我你得到了什么控制台输出吗?谢谢。我尝试了这个程序,但我得到了一个分割错误(内核转储)错误。是否显示了任何图像或写入了任何文件?(;;)
的不太好,因为视频文件(不同于实时摄像机)文件的某个地方会有一个结尾;)你能把你的代码片段放在只保存了最后一张图像的地方吗?我会根据你的需要修改它。我刚刚用了imwrite(“文件名”,框架),你能试着运行更新的代码并告诉我你得到了什么控制台输出吗?