0

I have a folder which contain 100 or more sub folders and each of them contain many images.(Caltech Database)

I have problem with how to read them from the different folders ?

I want to store them as a single matrix with stacking columms of each image.

1 Answer 1

3

Use Boost Filesystem for C++. You can load all files in a directory and pass the file location to OpenCV in a string.

    string folder = "../images/";
    vector<string> imageFileLocations;
    namespace fs = boost::filesystem;
    vec v;
    copy(fs::directory_iterator(folder), fs::directory_iterator(), back_inserter(v));
    sort(v.begin(), v.end());
    for (vec::const_iterator it(v.begin()); it != v.end(); ++it) {
        if (fs::is_regular_file(*it)) {
            string location = it->string();
            imageFileLocations.push_back(location);
        }
    }

You'll have to add something recursive to be able to go into other folders. You can do that by checking if the iteraotr is at a file or a folder. See the Boost website for examples.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks,I have used back_inserter to do the recursive thing.It works well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.