1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 00:03:03 +04:00

dnn: fix High-Level public API (cv::dnn::Model class)

- proxy selected Net methods only (don't derive from Net directly)
- default Model ctor is protected
This commit is contained in:
Alexander Alekhin
2020-10-31 14:08:13 +00:00
parent 691c3d1e3c
commit 23baf1a75e
4 changed files with 172 additions and 63 deletions
+33 -10
View File
@@ -1072,14 +1072,17 @@ CV__DNN_INLINE_NS_BEGIN
* Model creates net from file with trained weights and config,
* sets preprocessing input and runs forward pass.
*/
class CV_EXPORTS_W_SIMPLE Model : public Net
class CV_EXPORTS_W_SIMPLE Model
{
public:
/**
* @brief Default constructor.
*/
CV_DEPRECATED_EXTERNAL // avoid using in C++ code, will be moved to "protected" (need to fix bindings first)
Model();
Model(const Model&) = default;
Model(Model&&) = default;
Model& operator=(const Model&) = default;
Model& operator=(Model&&) = default;
/**
* @brief Create model from deep learning network represented in one of the supported formats.
* An order of @p model and @p config arguments does not matter.
@@ -1100,13 +1103,12 @@ CV__DNN_INLINE_NS_BEGIN
*/
CV_WRAP Model& setInputSize(const Size& size);
/** @brief Set input size for frame.
/** @overload
* @param[in] width New input width.
* @param[in] height New input height.
* @note If shape of the new blob less than 0,
* then frame size not change.
*/
CV_WRAP Model& setInputSize(int width, int height);
CV_WRAP inline
Model& setInputSize(int width, int height) { return setInputSize(Size(width, height)); }
/** @brief Set mean value for frame.
* @param[in] mean Scalar with mean values which are subtracted from channels.
@@ -1143,10 +1145,31 @@ CV__DNN_INLINE_NS_BEGIN
* @param[in] frame The input image.
* @param[out] outs Allocated output blobs, which will store results of the computation.
*/
CV_WRAP void predict(InputArray frame, OutputArrayOfArrays outs);
CV_WRAP void predict(InputArray frame, OutputArrayOfArrays outs) const;
// ============================== Net proxy methods ==============================
// Never expose methods with network implementation details, like:
// - addLayer, addLayerToPrev, connect, setInputsNames, setInputShape, setParam, getParam
// - getLayer*, getUnconnectedOutLayers, getUnconnectedOutLayersNames, getLayersShapes
// - forward* methods, setInput
/// @sa Net::setPreferableBackend
CV_WRAP Model& setPreferableBackend(dnn::Backend backendId);
/// @sa Net::setPreferableTarget
CV_WRAP Model& setPreferableTarget(dnn::Target targetId);
CV_DEPRECATED_EXTERNAL
operator Net&() const { return getNetwork_(); }
//protected: - internal/tests usage only
Net& getNetwork_() const;
inline Net& getNetwork_() { return const_cast<const Model*>(this)->getNetwork_(); }
protected:
struct Impl;
inline Impl* getImpl() const { return impl.get(); }
inline Impl& getImplRef() const { CV_DbgAssert(impl); return *impl.get(); }
protected:
Ptr<Impl> impl;
};
+1 -1
View File
@@ -6,7 +6,7 @@
#define OPENCV_DNN_VERSION_HPP
/// Use with major OpenCV version only.
#define OPENCV_DNN_API_VERSION 20200908
#define OPENCV_DNN_API_VERSION 20201117
#if !defined CV_DOXYGEN && !defined CV_STATIC_ANALYSIS && !defined CV_DNN_DONT_ADD_INLINE_NS
#define CV__DNN_INLINE_NS __CV_CAT(dnn4_v, OPENCV_DNN_API_VERSION)