I read image file name using 'fs::directory_iterator' . How can i read this file by using imread in opencv c++
I wrote the following code to read the files from a directory and ' fs::path(p.path()).filename()' this function returns the filename..How can i use the imread function after that?
string path = "C:/Users/Sam/Images2/";
for (const auto & p : fs::directory_iterator(path))
{
cout << fs::path(p.path()).filename() << " " << " Image " << endl;
Mat img = imread((fs::path(p.path()).filename()), IMREAD_GRAYSCALE);
}
take a look at train_HOG.cpp i think you will find many answers for your recent questions
@sturkmen : i have done those steps. I can read the file name by using '(fs::path(p.path()).filename())' , but can't pass this function into imread() and i would like to proceed with 'namespace fs = std::experimental::filesystem' because it is a new method added in visual studio 2017 '
imho, if you use this, you have to concat the filename to the path again, to read something valid.