VideoCapture获取视频中的图像帧

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

//新版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\n", 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\n", 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!\n"); return -1; } sprintf(path, "F:\\%d.jpg", imageNum); imageNum++; //保存获取到的帧数据 imwrite(path, frame);
if (currentFrame > frameToStop) { stop = true; } currentFrame++; } capture.release(); return 0; }


 

posted @ 2019-11-29 11:47  cumtchw  阅读(1517)  评论(0编辑  收藏  举报