Merge pull request #391 from rokm:dnn_fix

pull/353/merge
Alexander Alekhin 9 years ago
commit 2d1fc7a6cd
  1. 2
      modules/dnn/include/opencv2/dnn/layer.hpp
  2. 20
      modules/dnn/src/dnn.cpp

@ -77,7 +77,7 @@ private:
LayerFactory();
struct Impl;
static Ptr<Impl> impl;
static Ptr<Impl> impl();
};
/** @brief Registers layer constructor in runtime.

@ -561,34 +561,38 @@ struct LayerFactory::Impl : public std::map<String, LayerFactory::Constuctor>
{
};
//allocates on load and cleans on exit
Ptr<LayerFactory::Impl> LayerFactory::impl(new LayerFactory::Impl());
Ptr<LayerFactory::Impl> LayerFactory::impl ()
{
// allocate on first use
static Ptr<LayerFactory::Impl> impl_(new LayerFactory::Impl());
return impl_;
}
void LayerFactory::registerLayer(const String &_type, Constuctor constructor)
{
String type = _type.toLowerCase();
Impl::iterator it = impl->find(type);
Impl::iterator it = impl()->find(type);
if (it != impl->end() && it->second != constructor)
if (it != impl()->end() && it->second != constructor)
{
CV_Error(cv::Error::StsBadArg, "Layer \"" + type + "\" already was registered");
}
impl->insert(std::make_pair(type, constructor));
impl()->insert(std::make_pair(type, constructor));
}
void LayerFactory::unregisterLayer(const String &_type)
{
String type = _type.toLowerCase();
impl->erase(type);
impl()->erase(type);
}
Ptr<Layer> LayerFactory::createLayerInstance(const String &_type, LayerParams& params)
{
String type = _type.toLowerCase();
Impl::const_iterator it = LayerFactory::impl->find(type);
Impl::const_iterator it = LayerFactory::impl()->find(type);
if (it != impl->end())
if (it != impl()->end())
{
return it->second(params);
}

Loading…
Cancel
Save