我在一个名为1.jpg,3.jpg,4.jpg,6.jpg,8.jpg,10.jpg,15. jpg,.100.jpg,102.jpg,103.jpg,113.jpg等.
我使用dirent.h来迭代这些文件,但是dirent.h从10.jpg开始,它传递的下一个文件突然是100.jpg,然后是102.jpg,为什么它会跳过一些图像?
int main (int argc, const char* argv[] )
{
cv::Mat image;
DIR *dir;
struct dirent *ent;
if ((dir = opendir ("C:\\Users\\Faraz\\Desktop\\Project\\detecting_false_positives_stuff\\face_images\\faces\\")) != NULL) {
ent = readdir (dir);
printf ("%s\n", ent->d_name);
ent = readdir (dir);
printf ("%s\n", ent->d_name);
while ((ent = readdir (dir)) != NULL) {
printf ("%s\n", ent->d_name);
std::string fullPath = std::string("C:\\Users\\Faraz\\Desktop\\Project\\detecting_false_positives_stuff\\face_images\\faces\\") + ent->d_name;
cout<<fullPath;
image = cv::imread(fullPath);
...
}
closedir (dir);
}
return 1;}
发布于 2014-02-14 20:07:08
如果您想要对文件进行排序,那么您必须自己进行排序,readdir不会为您这样做的。也请参阅此:Does readdir() guarantee an order?
https://stackoverflow.com/questions/21788527
复制相似问题