访问视频的每一帧并对其进行处理

accessing each frame of video and processing it

本文关键字:处理 一帧 视频 访问      更新时间:2023-10-16

我正在尝试编写一个程序,该程序使用带有CPP OPENCV将视频文件的每一帧存储为图像。我已经通过ffmpegmplayer实现了这一目标。我想使用 OPENCV .谁能帮忙?除了IMWRITE()之外,还有其他功能可以将图像存储到文件中吗?

OPENCV是否有任何功能可以获取设备特定端口上可用的视频实时流并实时处理? 即将每一帧流存储为图像?谁能帮我?

提前感谢..:)

保存所有带有递增编号文件名的图像,这对我有用:

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