Skip to content

Commit

Permalink
Merge pull request #21429 from alalek:dnn_api_explicit_const_3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
alalek committed Jan 21, 2022
2 parents e612770 + b304730 commit f811ba8
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 93 deletions.
14 changes: 7 additions & 7 deletions modules/dnn/include/opencv2/dnn/dict.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN
struct CV_EXPORTS_W DictValue
{
DictValue(const DictValue &r);
DictValue(bool i) : type(Param::INT), pi(new AutoBuffer<int64,1>) { (*pi)[0] = i ? 1 : 0; } //!< Constructs integer scalar
DictValue(int64 i = 0) : type(Param::INT), pi(new AutoBuffer<int64,1>) { (*pi)[0] = i; } //!< Constructs integer scalar
CV_WRAP DictValue(int i) : type(Param::INT), pi(new AutoBuffer<int64,1>) { (*pi)[0] = i; } //!< Constructs integer scalar
DictValue(unsigned p) : type(Param::INT), pi(new AutoBuffer<int64,1>) { (*pi)[0] = p; } //!< Constructs integer scalar
CV_WRAP DictValue(double p) : type(Param::REAL), pd(new AutoBuffer<double,1>) { (*pd)[0] = p; } //!< Constructs floating point scalar
CV_WRAP DictValue(const String &s) : type(Param::STRING), ps(new AutoBuffer<String,1>) { (*ps)[0] = s; } //!< Constructs string scalar
DictValue(const char *s) : type(Param::STRING), ps(new AutoBuffer<String,1>) { (*ps)[0] = s; } //!< @overload
explicit DictValue(bool i) : type(Param::INT), pi(new AutoBuffer<int64,1>) { (*pi)[0] = i ? 1 : 0; } //!< Constructs integer scalar
explicit DictValue(int64 i = 0) : type(Param::INT), pi(new AutoBuffer<int64,1>) { (*pi)[0] = i; } //!< Constructs integer scalar
CV_WRAP explicit DictValue(int i) : type(Param::INT), pi(new AutoBuffer<int64,1>) { (*pi)[0] = i; } //!< Constructs integer scalar
explicit DictValue(unsigned p) : type(Param::INT), pi(new AutoBuffer<int64,1>) { (*pi)[0] = p; } //!< Constructs integer scalar
CV_WRAP explicit DictValue(double p) : type(Param::REAL), pd(new AutoBuffer<double,1>) { (*pd)[0] = p; } //!< Constructs floating point scalar
CV_WRAP explicit DictValue(const String &s) : type(Param::STRING), ps(new AutoBuffer<String,1>) { (*ps)[0] = s; } //!< Constructs string scalar
explicit DictValue(const char *s) : type(Param::STRING), ps(new AutoBuffer<String,1>) { (*ps)[0] = s; } //!< @overload

template<typename TypeIter>
static DictValue arrayInt(TypeIter begin, int size); //!< Constructs integer array
Expand Down
33 changes: 23 additions & 10 deletions modules/dnn/include/opencv2/dnn/dnn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN
class BackendNode
{
public:
BackendNode(int backendId);
explicit BackendNode(int backendId);

virtual ~BackendNode(); //!< Virtual destructor to make polymorphism.

Expand Down Expand Up @@ -259,18 +259,18 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN
* Each layer input and output can be labeled to easily identify them using "%<layer_name%>[.output_name]" notation.
* This method maps label of input blob to its index into input vector.
*/
virtual int inputNameToIndex(String inputName);
virtual int inputNameToIndex(String inputName); // FIXIT const
/** @brief Returns index of output blob in output array.
* @see inputNameToIndex()
*/
CV_WRAP virtual int outputNameToIndex(const String& outputName);
CV_WRAP virtual int outputNameToIndex(const String& outputName); // FIXIT const

/**
* @brief Ask layer if it support specific backend for doing computations.
* @param[in] backendId computation backend identifier.
* @see Backend
*/
virtual bool supportBackend(int backendId);
virtual bool supportBackend(int backendId); // FIXIT const

/**
* @brief Returns Halide backend node.
Expand Down Expand Up @@ -442,18 +442,29 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN
/** @brief Converts string name of the layer to the integer identifier.
* @returns id of the layer, or -1 if the layer wasn't found.
*/
CV_WRAP int getLayerId(const String &layer);
CV_WRAP int getLayerId(const String &layer) const;

CV_WRAP std::vector<String> getLayerNames() const;

/** @brief Container for strings and integers. */
/** @brief Container for strings and integers.
*
* @deprecated Use getLayerId() with int result.
*/
typedef DictValue LayerId;

/** @brief Returns pointer to layer with specified id or name which the network use. */
CV_WRAP Ptr<Layer> getLayer(LayerId layerId);
CV_WRAP Ptr<Layer> getLayer(int layerId) const;
/** @overload
* @deprecated Use int getLayerId(const String &layer)
*/
CV_WRAP inline Ptr<Layer> getLayer(const String& layerName) const { return getLayer(getLayerId(layerName)); }
/** @overload
* @deprecated to be removed
*/
CV_WRAP Ptr<Layer> getLayer(const LayerId& layerId) const;

/** @brief Returns pointers to input layers of specific layer. */
std::vector<Ptr<Layer> > getLayerInputs(LayerId layerId); // FIXIT: CV_WRAP
std::vector<Ptr<Layer> > getLayerInputs(int layerId) const; // FIXIT: CV_WRAP

/** @brief Connects output of the first layer to input of the second layer.
* @param outPin descriptor of the first layer output.
Expand Down Expand Up @@ -587,14 +598,16 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN
* @note If shape of the new blob differs from the previous shape,
* then the following forward pass may fail.
*/
CV_WRAP void setParam(LayerId layer, int numParam, const Mat &blob);
CV_WRAP void setParam(int layer, int numParam, const Mat &blob);
CV_WRAP inline void setParam(const String& layerName, int numParam, const Mat &blob) { return setParam(getLayerId(layerName), numParam, blob); }

/** @brief Returns parameter blob of the layer.
* @param layer name or id of the layer.
* @param numParam index of the layer parameter in the Layer::blobs array.
* @see Layer::blobs
*/
CV_WRAP Mat getParam(LayerId layer, int numParam = 0);
CV_WRAP Mat getParam(int layer, int numParam = 0) const;
CV_WRAP inline Mat getParam(const String& layerName, int numParam = 0) const { return getParam(getLayerId(layerName), numParam); }

/** @brief Returns indexes of layers with unconnected outputs.
*/
Expand Down

0 comments on commit f811ba8

Please sign in to comment.