zoukankan      html  css  js  c++  java
  • VideoCapture获取视频中的图像帧

    int main(void)
    {
        VideoCapture capture("F:\1.avi");//在嵌入式设备中这一句执行错误,挪到电脑上用VS没有错误,
        if (!capture.isOpened())
        {
            printf("fail to open 1.avi
    ");
        }

    //新版opencv中CV_CAP_PROP_FRAME_COUNT被改为CAP_PROP_FRAME_COUNT,记得修改,否则会编译错误
    long totalFrameNumber = capture.get(CV_CAP_PROP_FRAME_COUNT); printf("total frame number is:%f ", totalFrameNumber); long frameToStart = 1;
    //新版opencv中CV_CAP_PROP_POS_FRAMES被改为CAP_PROP_POS_FRAMES,记得修改,否则会编译错误 capture.
    set(CV_CAP_PROP_POS_FRAMES, frameToStart); long frameToStop = 1000;   //新版opencv中CV_CAP_PROP_FPS被改为CAP_PROP_FPS,记得修改,否则会编译错误 double rate = capture.get(CV_CAP_PROP_FPS); printf("rate is :%d ", rate); bool stop = false; Mat frame; int delay = 1000 / rate; long currentFrame = frameToStart; char path[20] = {}; int imageNum = 0; while (!stop) { if (!capture.read(frame)) { printf("get frame fail! "); return -1; } sprintf(path, "F:\%d.jpg", imageNum); imageNum++; //保存获取到的帧数据 imwrite(path, frame);
    if (currentFrame > frameToStop) { stop = true; } currentFrame++; } capture.release(); return 0; }


    作者:cumtchw
    出处:http://www.cnblogs.com/cumtchw/
    我的博客就是我的学习笔记,学习过程中看到好的博客也会转载过来,若有侵权,与我联系,我会及时删除。

  • 相关阅读:
    java基础数据
    Java环境搭建
    Mysql数据库基础
    php环境搭建
    1117bootstrap组件
    1117bootstrap
    1115表单验证
    1114JS实例4
    1113JS实例3
    1111JS实例2
  • 原文地址:https://www.cnblogs.com/cumtchw/p/11956844.html
Copyright © 2011-2022 走看看