+ Net net;
+ std::ifstream cfgStream(cfgFile.c_str());
+ if(!cfgStream.is_open()) {
+ CV_Error(cv::Error::StsParseError, "Failed to parse NetParameter file: " + std::string(cfgFile));
+ return net;
+ }
+ DarknetImporter darknetImporter;
+ if (darknetModel != String()) {
+ std::ifstream darknetModelStream(darknetModel.c_str());
+ if(!darknetModelStream.is_open()){
+ CV_Error(cv::Error::StsParseError, "Failed to parse NetParameter file: " + std::string(darknetModel));
+ return net;
+ }
+ darknetImporter = DarknetImporter(cfgStream, darknetModelStream);
+ } else {
+ darknetImporter = DarknetImporter(cfgStream);
+ }
+ darknetImporter.populateNet(net);
+ return net;
+}
+
+Net readNetFromDarknet(const FileNode &cfgFile, const FileNode &darknetModel /*= FileNode()*/)
+{
+ DarknetImporter darknetImporter;
+ if(darknetModel.empty()){
+ std::istringstream cfgStream((std::string)cfgFile);
+ darknetImporter = DarknetImporter(cfgStream);
+ }else{
+ std::istringstream cfgStream((std::string)cfgFile);
+ std::istringstream darknetModelStream((std::string)darknetModel);
+ darknetImporter = DarknetImporter(cfgStream, darknetModelStream);
+ }