opencv批量读图像序列
opencv实现批量读图像序列,以函数的形式实现如下:
void readImageSequenceFiles(char* imgFilePath,vector <string> &imgNames)//用vector <string>做存贮文件名的容器 { imgNames.clear(); int i=0; char tmpDirSpec[MAX_PATH+1]; char tmpDirPath[40]; sprintf (tmpDirSpec, "%s/*", imgFilePath);//*任意文件名 正则表达式 WIN32_FIND_DATA f; HANDLE h = FindFirstFile(tmpDirSpec , &f); if(h != INVALID_HANDLE_VALUE) { FindNextFile(h, &f); //read .. FindNextFile(h, &f); //read . do { sprintf(tmpDirPath, "%s", imgFilePath); imgNames.push_back(f.cFileName); imgNames[i].insert(0,tmpDirPath); i++; } while(FindNextFile(h, &f)); } FindClose(h); }
主函数里这个调用就可:
char* filefolder="D:/image/chessboards/"; std::vector <string> imgname; readImageSequenceFiles(filefolder,imgname);