OpenCV批量讀圖

opencv實現批量讀圖像序列,以函數的形式實現如下:

<pre name="code" class="cpp">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);


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章