I am passing a string representing a path to a folder as a parameter to a constructor.
Folder name, the files in it and their names can vary but the extensions of two files is always the same:
*.caffemodel
and *.prototxt
.
How can I refer to these two files in the specified directory using their extension without having to scan the entire folder to get their complete names?
As an example here is the code of my class:
#include "NeuralClassifier.hpp"
NeuralClassifier::NeuralClassifier(std::string path)
{
std::string modelName = path + "/*.caffemodel";
std::string protoName = path + "/*.prototxt";
cv::dnn::Net net;
try {
net = dnn::readNetFromCaffe(protoName, modelName);
}
catch (cv::Exception& e) {
std::cerr << "Exception: " << e.what() << std::endl;
if (net.empty())
{
std::cerr << "Can't load network by using the following files: " << std::endl;
std::cerr << "prototxt: " << protoName << std::endl;
std::cerr << "caffemodel: " << modelName << std::endl;
std::cerr << "bvlc_googlenet.caffemodel can be downloaded here:" << std::endl;
std::cerr << "http://dl.caffe.berkeleyvision.org/bvlc_googlenet.caffemodel" << std::endl;
exit(-1);
}
}
}