1 | initial version |
I had a similar need as you did, I solved the problem with boost filesystem library.
For file scanning with boost, it would look something like this:
int scanFiles( const path & directory, string filterFileType)
{
int fileCount=0;
if( exists( directory ) )
{
directory_iterator end ;
for( directory_iterator iter(directory) ; iter != end ; ++iter )
if ( (is_regular_file( *iter ) && iter->path().extension().string() == filterFileType))
{
cout << iter->path().filename().string() << endl ;
fileCount++;
}
}
return fileCount;
}
While scanning you can return or update global Mat variable and use it to do your stuff.
But I don't think that OpenCV can scan through files natively.
2 | No.2 Revision |
I had a similar need as you did, I solved the problem with boost filesystem library.
For file scanning with boost, it would look something like this:
int scanFiles( const path & directory, string filterFileType)
{
int fileCount=0;
if( exists( directory ) )
{
directory_iterator end ;
for( directory_iterator iter(directory) ; iter != end ; ++iter )
if ( (is_regular_file( *iter ) && iter->path().extension().string() == filterFileType))
{
cout << iter->path().filename().string() << endl ; //this is the one of scanned file names
fileCount++;
}
}
return fileCount;
}
Basically what that function does (at least in my app), returns the count of files with a specified extension. So scanFiles("labels", "png"); will return me the number of png files in directory labels.
While scanning you can return or update global Mat variable and use it to do your stuff.
But I don't think that OpenCV can scan through files natively.