OpenCV 4.5.3(日本語機械翻訳)
全て クラス 名前空間 ファイル 関数 変数 型定義 列挙型 列挙値 フレンド グループ ページ
dnn/dnn.hpp
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
8 //
9 //
10 // License Agreement
11 // For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
15 //
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
18 //
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
21 //
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
25 //
26 // * The name of the copyright holders may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
28 //
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
39 //
40 //M*/
41
42 #ifndef OPENCV_DNN_DNN_HPP
43 #define OPENCV_DNN_DNN_HPP
44
45 #include <vector>
46 #include <opencv2/core.hpp>
47 #include "opencv2/core/async.hpp"
48
49 #include "../dnn/version.hpp"
50
51 #include <opencv2/dnn/dict.hpp>
52
53 namespace cv {
54 namespace dnn {
55CV__DNN_INLINE_NS_BEGIN
58
59 typedef std::vector<int> MatShape;
60
65 enum Backend
66 {
71 DNN_BACKEND_HALIDE,
74 DNN_BACKEND_OPENCV,
75 DNN_BACKEND_VKCOM,
76 DNN_BACKEND_CUDA,
77 #ifdef __OPENCV_BUILD
78 DNN_BACKEND_INFERENCE_ENGINE_NGRAPH = 1000000, // internal - use DNN_BACKEND_INFERENCE_ENGINE + setInferenceEngineBackendType()
79 DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019, // internal - use DNN_BACKEND_INFERENCE_ENGINE + setInferenceEngineBackendType()
80 #endif
81 };
82
87 enum Target
88 {
89 DNN_TARGET_CPU = 0,
90 DNN_TARGET_OPENCL,
91 DNN_TARGET_OPENCL_FP16,
92 DNN_TARGET_MYRIAD,
93 DNN_TARGET_VULKAN,
95 DNN_TARGET_CUDA,
96 DNN_TARGET_CUDA_FP16,
97 DNN_TARGET_HDDL
98 };
99
100 CV_EXPORTS std::vector< std::pair<Backend, Target> > getAvailableBackends();
101 CV_EXPORTS_W std::vector<Target> getAvailableTargets(dnn::Backend be);
102
113 CV_EXPORTS void enableModelDiagnostics(bool isDiagnosticsMode);
114
120 class CV_EXPORTS LayerParams : public Dict
121 {
122 public:
123 //TODO: Add ability to name blob params
124 std::vector<Mat> blobs;
125
126 String name;
127 String type;
128 };
129
134 {
135 public:
137
138 virtual ~BackendNode();
139
141 };
142
147 {
148 public:
150
159
170 BackendWrapper(const Ptr<BackendWrapper>& base, const MatShape& shape);
171
172 virtual ~BackendWrapper();
173
177 virtual void copyToHost() = 0;
178
182 virtual void setHostDirty() = 0;
183
186 };
187
188 class CV_EXPORTS ActivationLayer;
189
195 class CV_EXPORTS_W Layer : public Algorithm
196 {
197 public:
198
200 CV_PROP_RW std::vector<Mat> blobs;
201
210 CV_DEPRECATED_EXTERNAL
211 virtual void finalize(const std::vector<Mat*> &input, std::vector<Mat> &output);
212
220 CV_WRAP virtual void finalize(InputArrayOfArrays inputs, OutputArrayOfArrays outputs);
221
228 CV_DEPRECATED_EXTERNAL
229 virtual void forward(std::vector<Mat*> &input, std::vector<Mat> &output, std::vector<Mat> &internals);
230
236 virtual void forward(InputArrayOfArrays inputs, OutputArrayOfArrays outputs, OutputArrayOfArrays internals);
237
243 void forward_fallback(InputArrayOfArrays inputs, OutputArrayOfArrays outputs, OutputArrayOfArrays internals);
244
249 CV_DEPRECATED_EXTERNAL
250 void finalize(const std::vector<Mat> &inputs, CV_OUT std::vector<Mat> &outputs);
251
256 CV_DEPRECATED std::vector<Mat> finalize(const std::vector<Mat> &inputs);
257
261 CV_DEPRECATED CV_WRAP void run(const std::vector<Mat> &inputs, CV_OUT std::vector<Mat> &outputs,
262 CV_IN_OUT std::vector<Mat> &internals);
263
270 virtual int inputNameToIndex(String inputName);
274 CV_WRAP virtual int outputNameToIndex(const String& outputName);
275
281 virtual bool supportBackend(int backendId);
282
293 virtual Ptr<BackendNode> initHalide(const std::vector<Ptr<BackendWrapper> > &inputs);
294
295 virtual Ptr<BackendNode> initInfEngine(const std::vector<Ptr<BackendWrapper> > &inputs);
296
297 virtual Ptr<BackendNode> initNgraph(const std::vector<Ptr<BackendWrapper> > &inputs, const std::vector<Ptr<BackendNode> >& nodes);
298
299 virtual Ptr<BackendNode> initVkCom(const std::vector<Ptr<BackendWrapper> > &inputs);
300
309 void *context,
310 const std::vector<Ptr<BackendWrapper>>& inputs,
311 const std::vector<Ptr<BackendWrapper>>& outputs
312 );
313
326 const std::vector<Mat*> &inputs,
327 const std::vector<Mat> &outputs,
328 int targetId) const;
329
340
347 virtual bool setActivation(const Ptr<ActivationLayer>& layer);
348
354 virtual bool tryFuse(Ptr<Layer>& top);
355
369 virtual void getScaleShift(Mat& scale, Mat& shift) const;
370
374 virtual void unsetAttached();
375
376 virtual bool getMemoryShapes(const std::vector<MatShape> &inputs,
377 const int requiredOutputs,
378 std::vector<MatShape> &outputs,
379 std::vector<MatShape> &internals) const;
380
381 virtual int64 getFLOPS(const std::vector<MatShape> &inputs,
382 const std::vector<MatShape> &outputs) const {CV_UNUSED(inputs); CV_UNUSED(outputs); return 0;}
383
384 virtual bool updateMemoryShapes(const std::vector<MatShape> &inputs);
385
386 CV_PROP String name;
387 CV_PROP String type;
388 CV_PROP int preferableTarget;
389
390 Layer();
391 explicit Layer(const LayerParams &params);
392 void setParamsFrom(const LayerParams &params);
393 virtual ~Layer();
394 };
395
406 class CV_EXPORTS_W_SIMPLE Net
407 {
408 public:
409
410 CV_WRAP Net();
411 CV_WRAP ~Net();
412
419 CV_WRAP static Net readFromModelOptimizer(const String& xml, const String& bin);
420
426 CV_WRAP static
427 Net readFromModelOptimizer(const std::vector<uchar>& bufferModelConfig, const std::vector<uchar>& bufferWeights);
428
436 static
437 Net readFromModelOptimizer(const uchar* bufferModelConfigPtr, size_t bufferModelConfigSize,
438 const uchar* bufferWeightsPtr, size_t bufferWeightsSize);
439
441 CV_WRAP bool empty() const;
442
447 CV_WRAP String dump();
452 CV_WRAP void dumpToFile(const String& path);
459 int addLayer(const String &name, const String &type, LayerParams &params);
463 int addLayerToPrev(const String &name, const String &type, LayerParams &params);
464
468 CV_WRAP int getLayerId(const String &layer);
469
470 CV_WRAP std::vector<String> getLayerNames() const;
471
474
476 CV_WRAP Ptr<Layer> getLayer(LayerId layerId);
477
479 std::vector<Ptr<Layer> > getLayerInputs(LayerId layerId); // FIXIT: CV_WRAP
480
494 CV_WRAP void connect(String outPin, String inpPin);
495
502 void connect(int outLayerId, int outNum, int inpLayerId, int inpNum);
503
511 CV_WRAP void setInputsNames(const std::vector<String> &inputBlobNames);
512
515 CV_WRAP void setInputShape(const String &inputName, const MatShape& shape);
516
522 CV_WRAP Mat forward(const String& outputName = String());
523
531 CV_WRAP AsyncArray forwardAsync(const String& outputName = String());
532
538 CV_WRAP void forward(OutputArrayOfArrays outputBlobs, const String& outputName = String());
539
544 CV_WRAP void forward(OutputArrayOfArrays outputBlobs,
545 const std::vector<String>& outBlobNames);
546
551 CV_WRAP_AS(forwardAndRetrieve) void forward(CV_OUT std::vector<std::vector<Mat> >& outputBlobs,
552 const std::vector<String>& outBlobNames);
553
563 CV_WRAP void setHalideScheduler(const String& scheduler);
564
573 CV_WRAP void setPreferableBackend(int backendId);
574
592 CV_WRAP void setPreferableTarget(int targetId);
593
605 CV_WRAP void setInput(InputArray blob, const String& name = "",
606 double scalefactor = 1.0, const Scalar& mean = Scalar());
607
616 CV_WRAP void setParam(LayerId layer, int numParam, const Mat &blob);
617
623 CV_WRAP Mat getParam(LayerId layer, int numParam = 0);
624
627 CV_WRAP std::vector<int> getUnconnectedOutLayers() const;
628
631 CV_WRAP std::vector<String> getUnconnectedOutLayersNames() const;
632
642 CV_WRAP void getLayersShapes(const std::vector<MatShape>& netInputShapes,
643 CV_OUT std::vector<int>& layersIds,
644 CV_OUT std::vector<std::vector<MatShape> >& inLayersShapes,
645 CV_OUT std::vector<std::vector<MatShape> >& outLayersShapes) const;
646
648 CV_WRAP void getLayersShapes(const MatShape& netInputShape,
649 CV_OUT std::vector<int>& layersIds,
650 CV_OUT std::vector<std::vector<MatShape> >& inLayersShapes,
651 CV_OUT std::vector<std::vector<MatShape> >& outLayersShapes) const;
652
662 void getLayerShapes(const MatShape& netInputShape,
663 const int layerId,
664 CV_OUT std::vector<MatShape>& inLayerShapes,
665 CV_OUT std::vector<MatShape>& outLayerShapes) const; // FIXIT: CV_WRAP
666
668 void getLayerShapes(const std::vector<MatShape>& netInputShapes,
669 const int layerId,
670 CV_OUT std::vector<MatShape>& inLayerShapes,
671 CV_OUT std::vector<MatShape>& outLayerShapes) const; // FIXIT: CV_WRAP
672
677 CV_WRAP int64 getFLOPS(const std::vector<MatShape>& netInputShapes) const;
679 CV_WRAP int64 getFLOPS(const MatShape& netInputShape) const;
681 CV_WRAP int64 getFLOPS(const int layerId,
682 const std::vector<MatShape>& netInputShapes) const;
684 CV_WRAP int64 getFLOPS(const int layerId,
685 const MatShape& netInputShape) const;
686
690 CV_WRAP void getLayerTypes(CV_OUT std::vector<String>& layersTypes) const;
691
696 CV_WRAP int getLayersCount(const String& layerType) const;
697
704 void getMemoryConsumption(const std::vector<MatShape>& netInputShapes,
705 CV_OUT size_t& weights, CV_OUT size_t& blobs) const; // FIXIT: CV_WRAP
707 CV_WRAP void getMemoryConsumption(const MatShape& netInputShape,
708 CV_OUT size_t& weights, CV_OUT size_t& blobs) const;
710 CV_WRAP void getMemoryConsumption(const int layerId,
711 const std::vector<MatShape>& netInputShapes,
712 CV_OUT size_t& weights, CV_OUT size_t& blobs) const;
714 CV_WRAP void getMemoryConsumption(const int layerId,
715 const MatShape& netInputShape,
716 CV_OUT size_t& weights, CV_OUT size_t& blobs) const;
717
725 void getMemoryConsumption(const std::vector<MatShape>& netInputShapes,
726 CV_OUT std::vector<int>& layerIds,
727 CV_OUT std::vector<size_t>& weights,
728 CV_OUT std::vector<size_t>& blobs) const; // FIXIT: CV_WRAP
730 void getMemoryConsumption(const MatShape& netInputShape,
731 CV_OUT std::vector<int>& layerIds,
732 CV_OUT std::vector<size_t>& weights,
733 CV_OUT std::vector<size_t>& blobs) const; // FIXIT: CV_WRAP
734
738 CV_WRAP void enableFusion(bool fusion);
739
748 CV_WRAP int64 getPerfProfile(CV_OUT std::vector<double>& timings);
749
750 private:
751 struct Impl;
752 Ptr<Impl> impl;
753 };
754
761 CV_EXPORTS_W Net readNetFromDarknet(const String &cfgFile, const String &darknetModel = String());
762
768 CV_EXPORTS_W Net readNetFromDarknet(const std::vector<uchar>& bufferCfg,
769 const std::vector<uchar>& bufferModel = std::vector<uchar>());
770
778 CV_EXPORTS Net readNetFromDarknet(const char *bufferCfg, size_t lenCfg,
779 const char *bufferModel = NULL, size_t lenModel = 0);
780
786 CV_EXPORTS_W Net readNetFromCaffe(const String &prototxt, const String &caffeModel = String());
787
793 CV_EXPORTS_W Net readNetFromCaffe(const std::vector<uchar>& bufferProto,
794 const std::vector<uchar>& bufferModel = std::vector<uchar>());
795
805 CV_EXPORTS Net readNetFromCaffe(const char *bufferProto, size_t lenProto,
806 const char *bufferModel = NULL, size_t lenModel = 0);
807
815 CV_EXPORTS_W Net readNetFromTensorflow(const String &model, const String &config = String());
816
822 CV_EXPORTS_W Net readNetFromTensorflow(const std::vector<uchar>& bufferModel,
823 const std::vector<uchar>& bufferConfig = std::vector<uchar>());
824
833 CV_EXPORTS Net readNetFromTensorflow(const char *bufferModel, size_t lenModel,
834 const char *bufferConfig = NULL, size_t lenConfig = 0);
835
862 CV_EXPORTS_W Net readNetFromTorch(const String &model, bool isBinary = true, bool evaluate = true);
863
888 CV_EXPORTS_W Net readNet(const String& model, const String& config = "", const String& framework = "");
889
899 CV_EXPORTS_W Net readNet(const String& framework, const std::vector<uchar>& bufferModel,
900 const std::vector<uchar>& bufferConfig = std::vector<uchar>());
901
905 CV_EXPORTS_W Mat readTorchBlob(const String &filename, bool isBinary = true);
906
914 CV_EXPORTS_W
915 Net readNetFromModelOptimizer(const String &xml, const String &bin);
916
924 CV_EXPORTS_W
925 Net readNetFromModelOptimizer(const std::vector<uchar>& bufferModelConfig, const std::vector<uchar>& bufferWeights);
926
936 CV_EXPORTS
937 Net readNetFromModelOptimizer(const uchar* bufferModelConfigPtr, size_t bufferModelConfigSize,
938 const uchar* bufferWeightsPtr, size_t bufferWeightsSize);
939
944 CV_EXPORTS_W Net readNetFromONNX(const String &onnxFile);
945
953 CV_EXPORTS Net readNetFromONNX(const char* buffer, size_t sizeBuffer);
954
961 CV_EXPORTS_W Net readNetFromONNX(const std::vector<uchar>& buffer);
962
967 CV_EXPORTS_W Mat readTensorFromONNX(const String& path);
968
985 CV_EXPORTS_W Mat blobFromImage(InputArray image, double scalefactor=1.0, const Size& size = Size(),
986 const Scalar& mean = Scalar(), bool swapRB=false, bool crop=false,
987 int ddepth=CV_32F);
988
993 CV_EXPORTS void blobFromImage(InputArray image, OutputArray blob, double scalefactor=1.0,
994 const Size& size = Size(), const Scalar& mean = Scalar(),
995 bool swapRB=false, bool crop=false, int ddepth=CV_32F);
996
997
1015 CV_EXPORTS_W Mat blobFromImages(InputArrayOfArrays images, double scalefactor=1.0,
1016 Size size = Size(), const Scalar& mean = Scalar(), bool swapRB=false, bool crop=false,
1017 int ddepth=CV_32F);
1018
1023 CV_EXPORTS void blobFromImages(InputArrayOfArrays images, OutputArray blob,
1024 double scalefactor=1.0, Size size = Size(),
1025 const Scalar& mean = Scalar(), bool swapRB=false, bool crop=false,
1026 int ddepth=CV_32F);
1027
1036 CV_EXPORTS_W void imagesFromBlob(const cv::Mat& blob_, OutputArrayOfArrays images_);
1037
1051 CV_EXPORTS_W void shrinkCaffeModel(const String& src, const String& dst,
1052 const std::vector<String>& layersTypes = std::vector<String>());
1053
1060 CV_EXPORTS_W void writeTextGraph(const String& model, const String& output);
1061
1072 CV_EXPORTS void NMSBoxes(const std::vector<Rect>& bboxes, const std::vector<float>& scores,
1073 const float score_threshold, const float nms_threshold,
1074 CV_OUT std::vector<int>& indices,
1075 const float eta = 1.f, const int top_k = 0);
1076
1077 CV_EXPORTS_W void NMSBoxes(const std::vector<Rect2d>& bboxes, const std::vector<float>& scores,
1078 const float score_threshold, const float nms_threshold,
1079 CV_OUT std::vector<int>& indices,
1080 const float eta = 1.f, const int top_k = 0);
1081
1082 CV_EXPORTS_AS(NMSBoxesRotated) void NMSBoxes(const std::vector<RotatedRect>& bboxes, const std::vector<float>& scores,
1083 const float score_threshold, const float nms_threshold,
1084 CV_OUT std::vector<int>& indices,
1085 const float eta = 1.f, const int top_k = 0);
1086
1087
1094 class CV_EXPORTS_W_SIMPLE Model
1095 {
1096 public:
1097 CV_DEPRECATED_EXTERNAL // avoid using in C++ code, will be moved to "protected" (need to fix bindings first)
1098 Model();
1099
1100 Model(const Model&) = default;
1101 Model(Model&&) = default;
1102 Model& operator=(const Model&) = default;
1103 Model& operator=(Model&&) = default;
1104
1111 CV_WRAP Model(const String& model, const String& config = "");
1112
1117 CV_WRAP Model(const Net& network);
1118
1123 CV_WRAP Model& setInputSize(const Size& size);
1124
1129 CV_WRAP inline
1130 Model& setInputSize(int width, int height) { return setInputSize(Size(width, height)); }
1131
1135 CV_WRAP Model& setInputMean(const Scalar& mean);
1136
1140 CV_WRAP Model& setInputScale(double scale);
1141
1145 CV_WRAP Model& setInputCrop(bool crop);
1146
1150 CV_WRAP Model& setInputSwapRB(bool swapRB);
1151
1160 CV_WRAP void setInputParams(double scale = 1.0, const Size& size = Size(),
1161 const Scalar& mean = Scalar(), bool swapRB = false, bool crop = false);
1162
1167 CV_WRAP void predict(InputArray frame, OutputArrayOfArrays outs) const;
1168
1169
1170 // ============================== Net proxy methods ==============================
1171 // Never expose methods with network implementation details, like:
1172 // - addLayer, addLayerToPrev, connect, setInputsNames, setInputShape, setParam, getParam
1173 // - getLayer*, getUnconnectedOutLayers, getUnconnectedOutLayersNames, getLayersShapes
1174 // - forward* methods, setInput
1175
1177 CV_WRAP Model& setPreferableBackend(dnn::Backend backendId);
1179 CV_WRAP Model& setPreferableTarget(dnn::Target targetId);
1180
1181 CV_DEPRECATED_EXTERNAL
1182 operator Net&() const { return getNetwork_(); }
1183
1184 //protected: - internal/tests usage only
1185 Net& getNetwork_() const;
1186 inline Net& getNetwork_() { return const_cast< const Model*>(this)->getNetwork_(); }
1187
1188 struct Impl;
1189 inline Impl* getImpl() const { return impl.get(); }
1190 inline Impl& getImplRef() const { CV_DbgAssert(impl); return *impl.get(); }
1191 protected:
1192 Ptr<Impl> impl;
1193 };
1194
1201 class CV_EXPORTS_W_SIMPLE ClassificationModel : public Model
1202 {
1203 public:
1210 CV_WRAP ClassificationModel(const String& model, const String& config = "");
1211
1216 CV_WRAP ClassificationModel(const Net& network);
1217
1221 std::pair<int, float> classify(InputArray frame);
1222
1224 CV_WRAP void classify(InputArray frame, CV_OUT int& classId, CV_OUT float& conf);
1225 };
1226
1233 class CV_EXPORTS_W_SIMPLE KeypointsModel: public Model
1234 {
1235 public:
1242 CV_WRAP KeypointsModel(const String& model, const String& config = "");
1243
1248 CV_WRAP KeypointsModel(const Net& network);
1249
1256 CV_WRAP std::vector<Point2f> estimate(InputArray frame, float thresh=0.5);
1257 };
1258
1265 class CV_EXPORTS_W_SIMPLE SegmentationModel: public Model
1266 {
1267 public:
1274 CV_WRAP SegmentationModel(const String& model, const String& config = "");
1275
1280 CV_WRAP SegmentationModel(const Net& network);
1281
1286 CV_WRAP void segment(InputArray frame, OutputArray mask);
1287 };
1288
1296 class CV_EXPORTS_W_SIMPLE DetectionModel : public Model
1297 {
1298 public:
1305 CV_WRAP DetectionModel(const String& model, const String& config = "");
1306
1311 CV_WRAP DetectionModel(const Net& network);
1312
1313 CV_DEPRECATED_EXTERNAL // avoid using in C++ code (need to fix bindings first)
1315
1322 CV_WRAP DetectionModel& setNmsAcrossClasses(bool value);
1323
1328 CV_WRAP bool getNmsAcrossClasses();
1329
1338 CV_WRAP void detect(InputArray frame, CV_OUT std::vector<int>& classIds,
1339 CV_OUT std::vector<float>& confidences, CV_OUT std::vector<Rect>& boxes,
1340 float confThreshold = 0.5f, float nmsThreshold = 0.0f);
1341 };
1342
1343
1351 class CV_EXPORTS_W_SIMPLE TextRecognitionModel : public Model
1352{
1353 public:
1354 CV_DEPRECATED_EXTERNAL // avoid using in C++ code, will be moved to "protected" (need to fix bindings first)
1356
1362 CV_WRAP TextRecognitionModel(const Net& network);
1363
1370 CV_WRAP inline
1371 TextRecognitionModel(const std::string& model, const std::string& config = "")
1372 : TextRecognitionModel(readNet(model, config)) { /* nothing */ }
1373
1378 CV_WRAP
1379 TextRecognitionModel& setDecodeType(const std::string& decodeType);
1380
1385 CV_WRAP
1386 const std::string& getDecodeType() const;
1387
1392 CV_WRAP
1393 TextRecognitionModel& setVocabulary(const std::vector<std::string>& vocabulary);
1394
1399 CV_WRAP
1400 const std::vector<std::string>& getVocabulary() const;
1401
1407 CV_WRAP
1408 std::string recognize(InputArray frame) const;
1409
1416 CV_WRAP
1417 void recognize(InputArray frame, InputArrayOfArrays roiRects, CV_OUT std::vector<std::string>& results) const;
1418};
1419
1420
1423 class CV_EXPORTS_W_SIMPLE TextDetectionModel : public Model
1424{
1425 protected:
1426 CV_DEPRECATED_EXTERNAL // avoid using in C++ code, will be moved to "protected" (need to fix bindings first)
1428
1429 public:
1430
1449 CV_WRAP
1451 InputArray frame,
1452 CV_OUT std::vector< std::vector<Point> >& detections,
1453 CV_OUT std::vector<float>& confidences
1454 ) const;
1455
1457 CV_WRAP
1459 InputArray frame,
1460 CV_OUT std::vector< std::vector<Point> >& detections
1461 ) const;
1462
1475 CV_WRAP
1477 InputArray frame,
1478 CV_OUT std::vector<cv::RotatedRect>& detections,
1479 CV_OUT std::vector<float>& confidences
1480 ) const;
1481
1483 CV_WRAP
1485 InputArray frame,
1486 CV_OUT std::vector<cv::RotatedRect>& detections
1487 ) const;
1488};
1489
1496 class CV_EXPORTS_W_SIMPLE TextDetectionModel_EAST : public TextDetectionModel
1497{
1498 public:
1499 CV_DEPRECATED_EXTERNAL // avoid using in C++ code, will be moved to "protected" (need to fix bindings first)
1501
1506 CV_WRAP TextDetectionModel_EAST(const Net& network);
1507
1514 CV_WRAP inline
1515 TextDetectionModel_EAST(const std::string& model, const std::string& config = "")
1516 : TextDetectionModel_EAST(readNet(model, config)) { /* nothing */ }
1517
1522 CV_WRAP
1524
1528 CV_WRAP
1530
1535 CV_WRAP
1537
1541 CV_WRAP
1542 float getNMSThreshold() const;
1543};
1544
1557 class CV_EXPORTS_W_SIMPLE TextDetectionModel_DB : public TextDetectionModel
1558{
1559 public:
1560 CV_DEPRECATED_EXTERNAL // avoid using in C++ code, will be moved to "protected" (need to fix bindings first)
1562
1567 CV_WRAP TextDetectionModel_DB(const Net& network);
1568
1575 CV_WRAP inline
1576 TextDetectionModel_DB(const std::string& model, const std::string& config = "")
1577 : TextDetectionModel_DB(readNet(model, config)) { /* nothing */ }
1578
1579 CV_WRAP TextDetectionModel_DB& setBinaryThreshold(float binaryThreshold);
1580 CV_WRAP float getBinaryThreshold() const;
1581
1582 CV_WRAP TextDetectionModel_DB& setPolygonThreshold(float polygonThreshold);
1583 CV_WRAP float getPolygonThreshold() const;
1584
1585 CV_WRAP TextDetectionModel_DB& setUnclipRatio(double unclipRatio);
1586 CV_WRAP double getUnclipRatio() const;
1587
1588 CV_WRAP TextDetectionModel_DB& setMaxCandidates(int maxCandidates);
1589 CV_WRAP int getMaxCandidates() const;
1590};
1591
1593CV__DNN_INLINE_NS_END
1594}
1595}
1596
1597 #include <opencv2/dnn/layer.hpp>
1598 #include <opencv2/dnn/dnn.inl.hpp>
1599
1601 #include <opencv2/dnn/utils/inference_engine.hpp>
1602
1603 #endif /* OPENCV_DNN_DNN_HPP */
This type is very similar to InputArray except that it is used for input/output and output function p...
Definition: mat.hpp:295
This is a base class for all more or less complex algorithms in OpenCV
Definition: core.hpp:3091
Returns result of asynchronous operations
Definition: async.hpp:32
n-dimensional dense array class
Definition: mat.hpp:802
Template class for specifying the size of an image or rectangle.
Definition: core/types.hpp:316
Definition: all_layers.hpp:425
Derivatives of this class encapsulates functions of certain backends.
Definition: dnn/dnn.hpp:134
virtual ~BackendNode()
Virtual destructor to make polymorphism.
int backendId
Backend identifier.
Definition: dnn/dnn.hpp:140
Derivatives of this class wraps cv::Mat for different backends and targets.
Definition: dnn/dnn.hpp:147
virtual void copyToHost()=0
Transfer data to CPU host memory.
virtual ~BackendWrapper()
Virtual destructor to make polymorphism.
virtual void setHostDirty()=0
Indicate that an actual data is on CPU.
BackendWrapper(int targetId, const cv::Mat &m)
Wrap cv::Mat for specific backend and target.
int backendId
Backend identifier.
Definition: dnn/dnn.hpp:184
BackendWrapper(const Ptr< BackendWrapper > &base, const MatShape &shape)
Make wrapper for reused cv::Mat.
int targetId
Target identifier.
Definition: dnn/dnn.hpp:185
This class represents high-level API for classification models.
Definition: dnn/dnn.hpp:1202
std::pair< int, float > classify(InputArray frame)
Given the input frame, create input blob, run net and return top-1 prediction.
This class represents high-level API for object detection networks.
Definition: dnn/dnn.hpp:1297
This class implements name-value dictionary, values are instances of DictValue.
Definition: dict.hpp:115
This class represents high-level API for keypoints models
Definition: dnn/dnn.hpp:1234
This interface class allows to build new Layers - are building blocks of networks.
Definition: dnn/dnn.hpp:196
virtual bool supportBackend(int backendId)
Ask layer if it support specific backend for doing computations.
virtual CV_DEPRECATED_EXTERNAL void finalize(const std::vector< Mat * > &input, std::vector< Mat > &output)
Computes and sets internal parameters according to inputs, outputs and blobs.
virtual bool setActivation(const Ptr< ActivationLayer > &layer)
Tries to attach to the layer the subsequent activation layer, i.e. do the layer fusion in a partial c...
virtual void getScaleShift(Mat &scale, Mat &shift) const
Returns parameters of layers with channel-wise multiplication and addition.
virtual void applyHalideScheduler(Ptr< BackendNode > &node, const std::vector< Mat * > &inputs, const std::vector< Mat > &outputs, int targetId) const
Automatic Halide scheduling based on layer hyper-parameters.
virtual CV_DEPRECATED_EXTERNAL void forward(std::vector< Mat * > &input, std::vector< Mat > &output, std::vector< Mat > &internals)
Given the input blobs, computes the output blobs.
virtual Ptr< BackendNode > tryAttach(const Ptr< BackendNode > &node)
Implement layers fusing.
virtual int inputNameToIndex(String inputName)
Returns index of input blob into the input array.
virtual Ptr< BackendNode > initCUDA(void *context, const std::vector< Ptr< BackendWrapper > > &inputs, const std::vector< Ptr< BackendWrapper > > &outputs)
Returns a CUDA backend node
virtual void forward(InputArrayOfArrays inputs, OutputArrayOfArrays outputs, OutputArrayOfArrays internals)
Given the input blobs, computes the output blobs.
virtual Ptr< BackendNode > initHalide(const std::vector< Ptr< BackendWrapper > > &inputs)
Returns Halide backend node.
void setParamsFrom(const LayerParams &params)
Initializes only name, type and blobs fields.
void forward_fallback(InputArrayOfArrays inputs, OutputArrayOfArrays outputs, OutputArrayOfArrays internals)
Given the input blobs, computes the output blobs.
virtual void unsetAttached()
"Deattaches" all the layers, attached to particular layer.
virtual bool tryFuse(Ptr< Layer > &top)
Try to fuse current layer with a next one
Layer(const LayerParams &params)
Initializes only name, type and blobs fields.
CV_DEPRECATED_EXTERNAL void finalize(const std::vector< Mat > &inputs, CV_OUT std::vector< Mat > &outputs)
これはオーバーロードされたメンバ関数です。利便性のために用意されています。元の関数との違いは引き数のみです。
This class provides all data needed to initialize layer.
Definition: dnn/dnn.hpp:121
std::vector< Mat > blobs
List of learned parameters stored as blobs.
Definition: dnn/dnn.hpp:124
String type
Type name which was used for creating layer by layer factory (optional).
Definition: dnn/dnn.hpp:127
String name
Name of the layer instance (optional, can be used internal purposes).
Definition: dnn/dnn.hpp:126
This class is presented high-level API for neural networks.
Definition: dnn/dnn.hpp:1095
CV_WRAP Model & setInputSize(int width, int height)
Definition: dnn/dnn.hpp:1130
This class allows to create and manipulate comprehensive artificial neural networks.
Definition: dnn/dnn.hpp:407
void getMemoryConsumption(const MatShape &netInputShape, CV_OUT std::vector< int > &layerIds, CV_OUT std::vector< size_t > &weights, CV_OUT std::vector< size_t > &blobs) const
int addLayer(const String &name, const String &type, LayerParams &params)
Adds new layer to the net.
void connect(int outLayerId, int outNum, int inpLayerId, int inpNum)
Connects #outNum output of the first layer to #inNum input of the second layer.
void getLayerShapes(const MatShape &netInputShape, const int layerId, CV_OUT std::vector< MatShape > &inLayerShapes, CV_OUT std::vector< MatShape > &outLayerShapes) const
Returns input and output shapes for layer with specified id in loaded model; preliminary inferencing ...
void getMemoryConsumption(const std::vector< MatShape > &netInputShapes, CV_OUT size_t &weights, CV_OUT size_t &blobs) const
Computes bytes number which are required to store all weights and intermediate blobs for model.
DictValue LayerId
Container for strings and integers.
Definition: dnn/dnn.hpp:473
int addLayerToPrev(const String &name, const String &type, LayerParams &params)
Adds new layer and connects its first input to the first output of previously added layer.
void getMemoryConsumption(const std::vector< MatShape > &netInputShapes, CV_OUT std::vector< int > &layerIds, CV_OUT std::vector< size_t > &weights, CV_OUT std::vector< size_t > &blobs) const
Computes bytes number which are required to store all weights and intermediate blobs for each layer.
void getLayerShapes(const std::vector< MatShape > &netInputShapes, const int layerId, CV_OUT std::vector< MatShape > &inLayerShapes, CV_OUT std::vector< MatShape > &outLayerShapes) const
static CV_WRAP Net readFromModelOptimizer(const std::vector< uchar > &bufferModelConfig, const std::vector< uchar > &bufferWeights)
Create a network from Intel's Model Optimizer in-memory buffers with intermediate representation (IR)...
static Net readFromModelOptimizer(const uchar *bufferModelConfigPtr, size_t bufferModelConfigSize, const uchar *bufferWeightsPtr, size_t bufferWeightsSize)
Create a network from Intel's Model Optimizer in-memory buffers with intermediate representation (IR)...
std::vector< Ptr< Layer > > getLayerInputs(LayerId layerId)
Returns pointers to input layers of specific layer.
This class represents high-level API for segmentation models
Definition: dnn/dnn.hpp:1266
This class represents high-level API for text detection DL networks compatible with DB model.
Definition: dnn/dnn.hpp:1558
CV_WRAP TextDetectionModel_DB(const std::string &model, const std::string &config="")
Create text detection model from network represented in one of the supported formats....
Definition: dnn/dnn.hpp:1576
This class represents high-level API for text detection DL networks compatible with EAST model.
Definition: dnn/dnn.hpp:1497
CV_WRAP TextDetectionModel_EAST(const std::string &model, const std::string &config="")
Create text detection model from network represented in one of the supported formats....
Definition: dnn/dnn.hpp:1515
CV_WRAP float getConfidenceThreshold() const
Get the detection confidence threshold
CV_WRAP float getNMSThreshold() const
Get the detection confidence threshold
CV_WRAP TextDetectionModel_EAST & setNMSThreshold(float nmsThreshold)
Set the detection NMS filter threshold
CV_WRAP TextDetectionModel_EAST & setConfidenceThreshold(float confThreshold)
Set the detection confidence threshold
Base class for text detection networks
Definition: dnn/dnn.hpp:1424
CV_WRAP void detect(InputArray frame, CV_OUT std::vector< std::vector< Point > > &detections) const
CV_WRAP void detectTextRectangles(InputArray frame, CV_OUT std::vector< cv::RotatedRect > &detections, CV_OUT std::vector< float > &confidences) const
Performs detection
CV_WRAP void detect(InputArray frame, CV_OUT std::vector< std::vector< Point > > &detections, CV_OUT std::vector< float > &confidences) const
Performs detection
CV_WRAP void detectTextRectangles(InputArray frame, CV_OUT std::vector< cv::RotatedRect > &detections) const
This class represents high-level API for text recognition networks.
Definition: dnn/dnn.hpp:1352
CV_WRAP const std::vector< std::string > & getVocabulary() const
Get the vocabulary for recognition.
CV_WRAP std::string recognize(InputArray frame) const
Given the input frame, create input blob, run net and return recognition result
CV_WRAP const std::string & getDecodeType() const
Get the decoding method
CV_WRAP TextRecognitionModel & setVocabulary(const std::vector< std::string > &vocabulary)
Set the vocabulary for recognition.
CV_WRAP TextRecognitionModel(const std::string &model, const std::string &config="")
Create text recognition model from network represented in one of the supported formats Call setDecode...
Definition: dnn/dnn.hpp:1371
CV_WRAP void recognize(InputArray frame, InputArrayOfArrays roiRects, CV_OUT std::vector< std::string > &results) const
Given the input frame, create input blob, run net and return recognition result
CV_WRAP TextRecognitionModel & setDecodeType(const std::string &decodeType)
Set the decoding method of translating the network output into string
CV_EXPORTS_AS(calibrateCameraExtended) double calibrateCamera(InputArrayOfArrays objectPoints
Finds the camera intrinsic and extrinsic parameters from several views of a calibration pattern.
#define CV_DbgAssert(expr)
Definition: base.hpp:375
CV_EXPORTS void blobFromImages(InputArrayOfArrays images, OutputArray blob, double scalefactor=1.0, Size size=Size(), const Scalar &mean=Scalar(), bool swapRB=false, bool crop=false, int ddepth=CV_32F)
Creates 4-dimensional blob from series of images.
CV_EXPORTS_W Net readNetFromONNX(const std::vector< uchar > &buffer)
Reads a network model from ONNX in-memory buffer.
CV_EXPORTS_W Net readNetFromTorch(const String &model, bool isBinary=true, bool evaluate=true)
Reads a network model stored in Torch7 framework's format.
Backend
Enum of computation backends supported by layers.
Definition: dnn/dnn.hpp:66
CV_EXPORTS void NMSBoxes(const std::vector< Rect > &bboxes, const std::vector< float > &scores, const float score_threshold, const float nms_threshold, CV_OUT std::vector< int > &indices, const float eta=1.f, const int top_k=0)
Performs non maximum suppression given boxes and corresponding scores.
CV_EXPORTS_W Mat readTorchBlob(const String &filename, bool isBinary=true)
Loads blob which was serialized as torch.Tensor object of Torch7 framework.
CV_EXPORTS void blobFromImage(InputArray image, OutputArray blob, double scalefactor=1.0, const Size &size=Size(), const Scalar &mean=Scalar(), bool swapRB=false, bool crop=false, int ddepth=CV_32F)
Creates 4-dimensional blob from image.
CV_EXPORTS Net readNetFromModelOptimizer(const uchar *bufferModelConfigPtr, size_t bufferModelConfigSize, const uchar *bufferWeightsPtr, size_t bufferWeightsSize)
Load a network from Intel's Model Optimizer intermediate representation.
Target
Enum of target devices for computations.
Definition: dnn/dnn.hpp:88
CV_EXPORTS_W Mat readTensorFromONNX(const String &path)
Creates blob from .pb file.
CV_EXPORTS_W void imagesFromBlob(const cv::Mat &blob_, OutputArrayOfArrays images_)
Parse a 4D blob and output the images it contains as 2D arrays through a simpler data structure (std:...
CV_EXPORTS void enableModelDiagnostics(bool isDiagnosticsMode)
Enables detailed logging of the DNN model loading with CV DNN API.
CV_EXPORTS_W void writeTextGraph(const String &model, const String &output)
Create a text representation for a binary network stored in protocol buffer format.
CV_EXPORTS Net readNetFromCaffe(const char *bufferProto, size_t lenProto, const char *bufferModel=NULL, size_t lenModel=0)
Reads a network model stored in Caffe model in memory.
CV_EXPORTS_W void shrinkCaffeModel(const String &src, const String &dst, const std::vector< String > &layersTypes=std::vector< String >())
Convert all weights of Caffe network to half precision floating point.
CV_EXPORTS_W Net readNet(const String &framework, const std::vector< uchar > &bufferModel, const std::vector< uchar > &bufferConfig=std::vector< uchar >())
Read deep learning network represented in one of the supported formats.
CV_EXPORTS Net readNetFromDarknet(const char *bufferCfg, size_t lenCfg, const char *bufferModel=NULL, size_t lenModel=0)
Reads a network model stored in Darknet model files.
CV_EXPORTS Net readNetFromTensorflow(const char *bufferModel, size_t lenModel, const char *bufferConfig=NULL, size_t lenConfig=0)
Reads a network model stored in TensorFlow framework's format.
@ DNN_BACKEND_DEFAULT
Definition: dnn/dnn.hpp:70
@ DNN_BACKEND_INFERENCE_ENGINE
Definition: dnn/dnn.hpp:72
@ DNN_TARGET_FPGA
FPGA device with CPU fallbacks using Inference Engine's Heterogeneous plugin.
Definition: dnn/dnn.hpp:94
CV_EXPORTS CV_WRAP_AS(goodFeaturesToTrackWithQuality) void goodFeaturesToTrack(InputArray image
Same as above, but returns also quality measure of the detected corners.
cv
"black box" representation of the file storage associated with a file on disk.
Definition: aruco.hpp:75
Definition: cvstd_wrapper.hpp:74
This struct stores the scalar value (or array) of one of the following type: double,...
Definition: dict.hpp:61