Ask Your Question
0

imread all files in directory

asked 2016-09-20 03:11:33 -0600

atv gravatar image

updated 2017-08-02 16:30:59 -0600

How would i modify this example to allow using a asterisk * as a argument so it would process all files instead of just the one argument.

http://docs.opencv.org/2.4/doc/tutori...

For some reason it doesn't accept * as a argc==2 (even if it could it would still need some adapting of course) I was messing around with dirent but the opencv way seems a lot cleaner.

edit retag flag offensive close merge delete

Comments

what have you tried? show us your code!

Balaji R gravatar imageBalaji R ( 2016-09-20 03:14:25 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-09-20 03:38:39 -0600

berak gravatar image

imread() on its own can not do any asterisk magic. if you're using opencv3, there's cv::glob:

String pattern = "./*"; //all files in this directory. "*.png" would be valid, too !
vector<String> filenames;

glob(pattern, filenames, false);

for (size_t i=0; i<filenames.size(); i++)
{
    Mat img = imread(filenames[i]);
    // do something with img ..
}
edit flag offensive delete link more

Comments

Thanks all. I will have a look at cv::glob, as i am using opencv3. I was hoping it would expand/do pattern matching like *.jpg, cool!

So i guess i could do something like: if(argv[1]==*) go_into_glob_solution else do_a_imread_on_single_file

atv gravatar imageatv ( 2016-09-20 07:57:02 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-09-20 03:11:33 -0600

Seen: 817 times

Last updated: Sep 20 '16