使用Opencv怎么将视频转换为图像序列

发布时间:2021-02-22 18:02:10 作者:戴恩恩
来源:亿速云 阅读:231

这篇文章主要介绍了使用Opencv怎么将视频转换为图像序列,此处通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考价值,需要的朋友可以参考下:

基于OpenCV的视频转为图像序列方法:

基于C++版本

#include <iostream>

#include "cv.h"
#include "opencv2/opencv.hpp"

using namespace std;
using namespace cv;

void main()
{
  VideoCapture cap("C:\\Users\\Leo\\Desktop\\Megamind.avi");
  if ( !cap.isOpened() )
  {
    return ;
  }

  int imgIndex(0);
  for ( ; ; )
  {
    Mat frame;
    cap >> frame;
    if ( frame.empty() )
    {
      break;
    }

    char* imageSaveName = new char[64];
    sprintf( imageSaveName, "C:\\Users\\Leo\\Desktop\\new\\%05d.jpg", imgIndex );
    imwrite( imageSaveName, frame );
    delete[] imageSaveName;
    imgIndex++;
  }
  cout << "total frames: " << imgIndex << endl;
}

基于C版本

#include <iostream>

#include "cv.h"
#include "opencv2/opencv.hpp"

using namespace std;
using namespace cv;

void main()
{
  // video read
  CvCapture *capture = cvCreateFileCapture("C:\\Users\\Leo\\Desktop\\Megamind.avi");
  IplImage *frame;

  int imgIndex(0);
  while(1)
  {
    frame = cvQueryFrame(capture);
    if ( !frame )
    {
      break;
    }

    char* imageSaveName = new char[64];
    sprintf( imageSaveName, "C:\\Users\\Leo\\Desktop\\new\\%05d.jpg", imgIndex );
    cvSaveImage( imageSaveName, frame );
    delete[] imageSaveName;
    imgIndex++;
  }
  cout << "total frames: " << imgIndex << endl;
  cvDestroyWindow( "VideoImage" );
  cvReleaseCapture( &capture );
  cvReleaseImage( &frame );
}

到此这篇关于使用Opencv怎么将视频转换为图像序列的文章就介绍到这了,更多相关内容请搜索亿速云以前的文章或继续浏览下面的相关文章希望大家以后多多支持亿速云!

推荐阅读:
  1. 使用opencv怎么为图像添加边界
  2. 使用opencv将视频帧转成图片输出

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

opencv

上一篇:使用JavaScript怎么对数字、字符串、布尔值三者进行转换

下一篇:使用react-router怎么实现一个跳转传值功能

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》