189 8069 5689

使用Opencv怎么将视频转换为图像序列-创新互联

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

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名与空间、网站空间、营销软件、网站建设、海兴网站维护、网站推广。

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

基于C++版本

#include 

#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 

#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怎么将视频转换为图像序列的文章就介绍到这了,更多相关内容请搜索创新互联建站以前的文章或继续浏览下面的相关文章希望大家以后多多支持创新互联建站!

另外有需要云服务器可以了解下创新互联建站www.cdcxhl.com,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、建站服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网站标题:使用Opencv怎么将视频转换为图像序列-创新互联
网页地址:http://cdxtjz.cn/article/ddgdgp.html

其他资讯