头文件
#include <opencv2\opencv.hpp>
函数原型
void cv::glob(String pattern,std::vector<string>&result,bool recursive=false)
解释
String pattern
pattern = "/home/mytxt/DCIM/*.jpg";
std::vector< String > & result //必须为CV的String,即路径被存在string类型的vector中
bool recursive //可省去
//当recursive为false时,仅仅遍历指定文件夹内符合模式的文件,
//当recursive为true时,会同时遍历指定文件夹的子文件夹
void readimage()
{
std::string pattern_jpg;
std::vector<cv::String> image_files;
pattern_jpg = "/home/mytxt/DCIM/*.jpg";
cv::glob(pattern_jpg, image_files);
for(int ii=0;ii<image_files.size();ii++)
{
cout << image_files[ii] << endl;
namedWindow("dd");
Mat dd=imread(image_files[ii]);
imshow("dd",dd);
}
waitKeyEx(0);
}