【问题标题】:accessing each frame of video and processing it访问每一帧视频并对其进行处理
【发布时间】:2014-01-10 18:50:08
【问题描述】:

我正在尝试编写一个程序,它将视频文件的每一帧存储为图像,使用 OPENCV 和 CPP。我通过ffmpegmplayer 实现了这一点。我想使用OPENCV 来获取它。任何人都可以帮忙吗?除了IMWRITE(),还有其他功能可以将图像存储到文件中吗?

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

提前谢谢..:)

【问题讨论】:

  • 为什么cv::imwrite 不适合你?
  • 它只复制了最后一帧。我想将所有帧保存为 image1.jpg,image2.jpg....

标签: c++ opencv live-streaming


【解决方案1】:

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

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

}

【讨论】:

  • 谢谢..我试过这个程序,但我得到一个分段错误(核心转储)错误
  • 是否显示任何图像或写入任何文件? for(;;) 不太好,因为对于视频文件(不同于实时摄像机),文件的结尾会在某处结束;)
  • 你能把你的代码 sn-p 贴在你使用cv::imwrite 的地方吗?它只保存了最后一张图片?我会尝试根据您的需要对其进行修改。
  • 我刚刚使用了 imwrite("filename", frame)
  • 你能尝试运行更新后的代码并告诉我你得到了什么控制台输出吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-04
  • 2011-03-29
  • 1970-01-01
  • 2012-12-31
  • 1970-01-01
相关资源
最近更新 更多