从矢量存储和检索IplImages?

时间:2012-07-31 19:49:25

标签: c++ opencv

我想将IplImage(从视频文件抓取)存储到矢量中,然后从此iplimage矢量播放。

#include <iostream>
#include "highgui.h"
using namespace std;

int main()
{
    CvCapture* capture=cvCreateFileCapture("D:\\Video\\Hands tracking.avi");
    vector<IplImage*> imagesNames[2];

    //playing video
    while(1)
   {
       IplImage* img=cvQueryFrame(capture);
       cvShowImage("Video Opencv example nd testing purpose",img);

       imagesNames[0].push_back(img);

       char c = cvWaitKey(30);
       if(c==27) break;
   }

  cvDestroyWindow( "Video Opencv example nd testing purpose" );
  cvReleaseCapture(&capture);

// play back grabbed IplImages
  for(unsigned i=0; imagesNames[0].size();i++)
  {
    cvShowImage("PlayBack from IplImages vector",imagesNames[0][i]);

    char c = cvWaitKey(30);

    if(c==27) break;
   }
return 0;
}

但上述程序的播放部分无效并在运行时显示错误。

1 个答案:

答案 0 :(得分:0)

#include <iostream>
#include "highgui.h"
using namespace std;

int main()

{

    CvCapture* capture=cvCreateFileCapture("D:\\Video\\Hands tracking.avi");
    vector<IplImage*> imagesNames;

    //playing video
    while(1)
   {
       IplImage* img=cvQueryFrame(capture);
       cvShowImage("Video Opencv example nd testing purpose",img);

       imagesNames.push_back(img);

      char c = cvWaitKey(30);
      if(c==27)
       break;

   }

  cvDestroyWindow( "Video Opencv example nd testing purpose" );
  cvReleaseCapture(&capture);

// play back grabbed IplImages
 for(unsigned i=0; i < imagesNames.size();i++)
 {

    cvShowImage("PlayBack from IplImages vector",imagesNames[i]);

    char c = cvWaitKey(30);

    if(c==27)
    break;

}
return 0;


}