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\
ew\\%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\
ew\\%05d.jpg", imgIndex ); cvSaveImage( imageSaveName, frame ); delete[] imageSaveName; imgIndex++; } cout << "total frames: " << imgIndex << endl; cvDestroyWindow( "VideoImage" ); cvReleaseCapture( &capture ); cvReleaseImage( &frame ); }
테스트 데 이 터 는 OpenCV 자체 비디오:Megamind.avi,opencv\sources\samples\cpp\tutorialcode\\HighGUI\\video-input-psnr-ssim\\video 경로 에서 총 270 프레임 의 그림 을 찾 습 니 다.실행 결과 부분 캡 처 는 다음 과 같 습 니 다.

이상 의 Opencv 영상 이 이미지 시퀀스 로 전환 되 는 실현 은 바로 작은 편집 이 여러분 에 게 공유 하 는 모든 내용 입 니 다.여러분 께 참고 가 되 고 저희 도 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기