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

Add high level API (Merge pull request #14780)

* Add high level API

* Fix Model

* Add DetectionModel

* Add ClassificationModel

* Fix classify

* Add python test

* Fix pytest

* Fix comments to review

* Fix detect

* Fix docs

* Modify DetectionOutput postprocessing

* Fix test

* Extract ref boxes

* Fix draw rect

* fix test

* Add rect wrap

* Fix wrap

* Fix detect

* Fix Rect wrap

* Fix OCL_FP16

* Fix MyriadX

* Fix nms

* Fix NMS

* Fix coords
This commit is contained in:
Lubov Batanina
2019-07-30 23:07:37 +03:00
committed by Maksim Shabunin
parent f482050f9a
commit 778f42ad34
5 changed files with 685 additions and 17 deletions
+149
View File
@@ -992,6 +992,155 @@ CV__DNN_INLINE_NS_BEGIN
CV_OUT std::vector<int>& indices,
const float eta = 1.f, const int top_k = 0);
/** @brief This class is presented high-level API for neural networks.
*
* Model allows to set params for preprocessing input image.
* Model creates net from file with trained weights and config,
* sets preprocessing input and runs forward pass.
*/
class CV_EXPORTS_W Model : public Net
{
public:
/**
* @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.
* @param[in] model Binary file contains trained weights.
* @param[in] config Text file contains network configuration.
*/
CV_WRAP Model(const String& model, const String& config = "");
/**
* @brief Create model from deep learning network.
* @param[in] network Net object.
*/
CV_WRAP Model(const Net& network);
/** @brief Set input size for frame.
* @param[in] size New input size.
* @note If shape of the new blob less than 0, then frame size not change.
*/
Model& setInputSize(const Size& size);
/** @brief Set input size for frame.
* @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.
*/
Model& setInputSize(int width, int height);
/** @brief Set mean value for frame.
* @param[in] mean Scalar with mean values which are subtracted from channels.
*/
Model& setInputMean(const Scalar& mean);
/** @brief Set scalefactor value for frame.
* @param[in] scale Multiplier for frame values.
*/
Model& setInputScale(double scale);
/** @brief Set flag crop for frame.
* @param[in] crop Flag which indicates whether image will be cropped after resize or not.
*/
Model& setInputCrop(bool crop);
/** @brief Set flag swapRB for frame.
* @param[in] swapRB Flag which indicates that swap first and last channels.
*/
Model& setInputSwapRB(bool swapRB);
/** @brief Set preprocessing parameters for frame.
* @param[in] size New input size.
* @param[in] mean Scalar with mean values which are subtracted from channels.
* @param[in] scale Multiplier for frame values.
* @param[in] swapRB Flag which indicates that swap first and last channels.
* @param[in] crop Flag which indicates whether image will be cropped after resize or not.
* blob(n, c, y, x) = scale * resize( frame(y, x, c) ) - mean(c) )
*/
CV_WRAP void setInputParams(double scale = 1.0, const Size& size = Size(),
const Scalar& mean = Scalar(), bool swapRB = false, bool crop = false);
/** @brief Given the @p input frame, create input blob, run net and return the output @p blobs.
* @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);
protected:
struct Impl;
Ptr<Impl> impl;
};
/** @brief This class represents high-level API for classification models.
*
* ClassificationModel allows to set params for preprocessing input image.
* ClassificationModel creates net from file with trained weights and config,
* sets preprocessing input, runs forward pass and return top-1 prediction.
*/
class CV_EXPORTS_W ClassificationModel : public Model
{
public:
/**
* @brief Create classification model from network represented in one of the supported formats.
* An order of @p model and @p config arguments does not matter.
* @param[in] model Binary file contains trained weights.
* @param[in] config Text file contains network configuration.
*/
CV_WRAP ClassificationModel(const String& model, const String& config = "");
/**
* @brief Create model from deep learning network.
* @param[in] network Net object.
*/
CV_WRAP ClassificationModel(const Net& network);
/** @brief Given the @p input frame, create input blob, run net and return top-1 prediction.
* @param[in] frame The input image.
*/
std::pair<int, float> classify(InputArray frame);
/** @overload */
CV_WRAP void classify(InputArray frame, CV_OUT int& classId, CV_OUT float& conf);
};
/** @brief This class represents high-level API for object detection networks.
*
* DetectionModel allows to set params for preprocessing input image.
* DetectionModel creates net from file with trained weights and config,
* sets preprocessing input, runs forward pass and return result detections.
* For DetectionModel SSD, Faster R-CNN, YOLO topologies are supported.
*/
class CV_EXPORTS_W DetectionModel : public Model
{
public:
/**
* @brief Create detection model from network represented in one of the supported formats.
* An order of @p model and @p config arguments does not matter.
* @param[in] model Binary file contains trained weights.
* @param[in] config Text file contains network configuration.
*/
CV_WRAP DetectionModel(const String& model, const String& config = "");
/**
* @brief Create model from deep learning network.
* @param[in] network Net object.
*/
CV_WRAP DetectionModel(const Net& network);
/** @brief Given the @p input frame, create input blob, run net and return result detections.
* @param[in] frame The input image.
* @param[out] classIds Class indexes in result detection.
* @param[out] confidences A set of corresponding confidences.
* @param[out] boxes A set of bounding boxes.
* @param[in] confThreshold A threshold used to filter boxes by confidences.
* @param[in] nmsThreshold A threshold used in non maximum suppression.
*/
CV_WRAP void detect(InputArray frame, CV_OUT std::vector<int>& classIds,
CV_OUT std::vector<float>& confidences, CV_OUT std::vector<Rect>& boxes,
float confThreshold = 0.5f, float nmsThreshold = 0.0f);
};
//! @}
CV__DNN_INLINE_NS_END
}