在做目标跟踪实验时,需要和其他主流方法作比较,这时就需要读入视频或一些图像序列。下面介绍一种利用VideoCapture类读取图像序列的方法:
如要读入以下图片序列
代码如下:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
string first_file = "images//frame_%04d.jpg";
VideoCapture sequence(first_file);
if (!sequence.isOpened())
{
cerr << "Failed to open the image sequence!\n" << endl;
return 1;
}
Mat image;
namedWindow("Image sequence", 1);
for(;;)
{
sequence >> image;
if(image.empty())
{
cout << "End of Sequence" << endl;
break;
}
imshow("Image sequence", image);
waitKey(30);
}
return 0;
}