Pergunta

I have several hundred images in a folder named: 1.jpg, 3.jpg, 4.jpg, 6.jpg, 8.jpg, 10.jpg, 15. jpg, .... 100.jpg, 102.jpg, 103.jpg, 113.jpg etc...

I am using dirent.h to iterate through the files, but somehow dirent.h starts at 10.jpg and the next file it delivers is suddenly 100.jpg and then 102.jpg, ... why does it skip some images?

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;

}

Foi útil?

Solução

You'll have to sort the files yourself if you want them in order, readdir won't do that for you. See this also: Does readdir() guarantee an order?

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top