读取文件夹中的所有图像
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main() {
//用void glob(String pattern, std::vector<String>& result, bool recursive = false);当recursive为false时,仅仅遍历指定文件夹内符合模式的文件,当recursive为true时,会同时遍历指定文件夹的子文件夹
//pattern要绝对路径 其它测试有问题
std::string src_path = "E:\\vs2017\\avdecoder\\avdecoder\\";
std::vector<cv::String> fn;
cv::glob(src_path + "*.jpg", fn, true);
vector<Mat> images;
size_t count = fn.size();
for (int i = 0; i < count; i++) {
images.push_back(imread(fn[i]));
cout << src_path << i << ".jpg" << endl;
imshow("关键帧", images[i]);
waitKey(2000);
}
return 1;
}
依次读取文件夹中的视频序列
int main(int argc, char** argv)
{
string first_file = "E://vs2017//avdecoder//avdecoder//%d.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(2000);
}
return 0;
}