Blame view

3rdparty/opencv_4_1/include/opencv2/dnn/layer.details.hpp 2.78 KB
09c2d08c   Hu Chunming   arm交付版
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
  // This file is part of OpenCV project.
  // It is subject to the license terms in the LICENSE file found in the top-level directory
  // of this distribution and at http://opencv.org/license.html.
  //
  #ifndef OPENCV_DNN_LAYER_DETAILS_HPP
  #define OPENCV_DNN_LAYER_DETAILS_HPP
  
  #include <opencv2/dnn/layer.hpp>
  
  namespace cv {
  namespace dnn {
  CV__DNN_INLINE_NS_BEGIN
  
  /** @brief Registers layer constructor in runtime.
  *   @param type string, containing type name of the layer.
  *   @param constructorFunc pointer to the function of type LayerRegister::Constructor, which creates the layer.
  *   @details This macros must be placed inside the function code.
  */
  #define CV_DNN_REGISTER_LAYER_FUNC(type, constructorFunc) \
      cv::dnn::LayerFactory::registerLayer(#type, constructorFunc);
  
  /** @brief Registers layer class in runtime.
   *  @param type string, containing type name of the layer.
   *  @param class C++ class, derived from Layer.
   *  @details This macros must be placed inside the function code.
   */
  #define CV_DNN_REGISTER_LAYER_CLASS(type, class) \
      cv::dnn::LayerFactory::registerLayer(#type, cv::dnn::details::_layerDynamicRegisterer<class>);
  
  /** @brief Registers layer constructor on module load time.
  *   @param type string, containing type name of the layer.
  *   @param constructorFunc pointer to the function of type LayerRegister::Constructor, which creates the layer.
  *   @details This macros must be placed outside the function code.
  */
  #define CV_DNN_REGISTER_LAYER_FUNC_STATIC(type, constructorFunc) \
  static cv::dnn::details::_LayerStaticRegisterer __LayerStaticRegisterer_##type(#type, constructorFunc);
  
  /** @brief Registers layer class on module load time.
   *  @param type string, containing type name of the layer.
   *  @param class C++ class, derived from Layer.
   *  @details This macros must be placed outside the function code.
   */
  #define CV_DNN_REGISTER_LAYER_CLASS_STATIC(type, class)                         \
  Ptr<Layer> __LayerStaticRegisterer_func_##type(LayerParams &params) \
      { return Ptr<Layer>(new class(params)); }                       \
  static cv::dnn::details::_LayerStaticRegisterer __LayerStaticRegisterer_##type(#type, __LayerStaticRegisterer_func_##type);
  
  namespace details {
  
  template<typename LayerClass>
  Ptr<Layer> _layerDynamicRegisterer(LayerParams &params)
  {
      return Ptr<Layer>(LayerClass::create(params));
  }
  
  //allows automatically register created layer on module load time
  class _LayerStaticRegisterer
  {
      String type;
  public:
  
      _LayerStaticRegisterer(const String &layerType, LayerFactory::Constructor layerConstructor)
      {
          this->type = layerType;
          LayerFactory::registerLayer(layerType, layerConstructor);
      }
  
      ~_LayerStaticRegisterer()
      {
          LayerFactory::unregisterLayer(type);
      }
  };
  
  } // namespace
  CV__DNN_INLINE_NS_END
  }} // namespace
  
  #endif