Skip to content

Commit da09603

Browse files
committed
dnn: added "hidden" experimental namespace
Main purpose of this namespace is to avoid using of incompatible binaries that will cause applications crashes. This additional namespace will not impact "Source code API". This change allows to maintain ABI checks (with easy filtering out).
1 parent 20f603a commit da09603

File tree

13 files changed

+81
-53
lines changed

13 files changed

+81
-53
lines changed

modules/dnn/include/opencv2/dnn/all_layers.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@
4343
#define OPENCV_DNN_DNN_ALL_LAYERS_HPP
4444
#include <opencv2/dnn.hpp>
4545

46-
namespace cv
47-
{
48-
namespace dnn
49-
{
46+
namespace cv {
47+
namespace dnn {
48+
CV__DNN_EXPERIMENTAL_NS_BEGIN
5049
//! @addtogroup dnn
5150
//! @{
5251

@@ -459,7 +458,7 @@ namespace dnn
459458

460459
//! @}
461460
//! @}
462-
461+
CV__DNN_EXPERIMENTAL_NS_END
463462
}
464463
}
465464
#endif

modules/dnn/include/opencv2/dnn/dict.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,9 @@
4646
#include <map>
4747
#include <ostream>
4848

49-
namespace cv
50-
{
51-
namespace dnn
52-
{
49+
namespace cv {
50+
namespace dnn {
51+
CV__DNN_EXPERIMENTAL_NS_BEGIN
5352
//! @addtogroup dnn
5453
//! @{
5554

@@ -140,6 +139,7 @@ class CV_EXPORTS Dict
140139
};
141140

142141
//! @}
142+
CV__DNN_EXPERIMENTAL_NS_END
143143
}
144144
}
145145

modules/dnn/include/opencv2/dnn/dnn.hpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,23 @@
4444

4545
#include <vector>
4646
#include <opencv2/core.hpp>
47+
48+
#if !defined CV_DOXYGEN && !defined CV_DNN_DONT_ADD_EXPERIMENTAL_NS
49+
#define CV__DNN_EXPERIMENTAL_NS_USE using namespace experimental_dnn_v1;
50+
#define CV__DNN_EXPERIMENTAL_NS_BEGIN namespace experimental_dnn_v1 {
51+
#define CV__DNN_EXPERIMENTAL_NS_END }
52+
#else
53+
#define CV__DNN_EXPERIMENTAL_NS_USE
54+
#define CV__DNN_EXPERIMENTAL_NS_BEGIN
55+
#define CV__DNN_EXPERIMENTAL_NS_END
56+
#endif
57+
4758
#include <opencv2/dnn/dict.hpp>
4859

49-
namespace cv
50-
{
51-
namespace dnn //! This namespace is used for dnn module functionlaity.
52-
{
60+
namespace cv {
61+
namespace dnn {
62+
CV__DNN_EXPERIMENTAL_NS_USE
63+
CV__DNN_EXPERIMENTAL_NS_BEGIN
5364
//! @addtogroup dnn
5465
//! @{
5566

@@ -658,6 +669,7 @@ namespace dnn //! This namespace is used for dnn module functionlaity.
658669
Size size = Size(), const Scalar& mean = Scalar(), bool swapRB=true);
659670

660671
//! @}
672+
CV__DNN_EXPERIMENTAL_NS_END
661673
}
662674
}
663675

modules/dnn/include/opencv2/dnn/dnn.inl.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@
4444

4545
#include <opencv2/dnn.hpp>
4646

47-
namespace cv
48-
{
49-
namespace dnn
50-
{
47+
namespace cv {
48+
namespace dnn {
49+
CV__DNN_EXPERIMENTAL_NS_BEGIN
5150

5251
template<typename TypeIter>
5352
DictValue DictValue::arrayInt(TypeIter begin, int size)
@@ -351,6 +350,7 @@ inline std::ostream &operator<<(std::ostream &stream, const Dict &dict)
351350
return stream;
352351
}
353352

353+
CV__DNN_EXPERIMENTAL_NS_END
354354
}
355355
}
356356

modules/dnn/include/opencv2/dnn/layer.details.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77

88
#include <opencv2/dnn/layer.hpp>
99

10-
namespace cv
11-
{
12-
namespace dnn
13-
{
10+
namespace cv {
11+
namespace dnn {
12+
CV__DNN_EXPERIMENTAL_NS_BEGIN
1413

1514
/** @brief Registers layer constructor in runtime.
1615
* @param type string, containing type name of the layer.
@@ -72,6 +71,8 @@ class _LayerStaticRegisterer
7271
}
7372
};
7473

75-
}}} //namespace
74+
} // namespace
75+
CV__DNN_EXPERIMENTAL_NS_END
76+
}} // namespace
7677

7778
#endif

modules/dnn/include/opencv2/dnn/layer.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@
4343
#define OPENCV_DNN_LAYER_HPP
4444
#include <opencv2/dnn.hpp>
4545

46-
namespace cv
47-
{
48-
namespace dnn
49-
{
46+
namespace cv {
47+
namespace dnn {
48+
CV__DNN_EXPERIMENTAL_NS_BEGIN
5049
//! @addtogroup dnn
5150
//! @{
5251
//!
@@ -80,7 +79,7 @@ class CV_EXPORTS LayerFactory
8079

8180
//! @}
8281
//! @}
83-
82+
CV__DNN_EXPERIMENTAL_NS_END
8483
}
8584
}
8685
#endif

modules/dnn/include/opencv2/dnn/shape_utils.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848

4949
namespace cv {
5050
namespace dnn {
51+
CV__DNN_EXPERIMENTAL_NS_BEGIN
5152

5253
//Useful shortcut
5354
inline std::ostream &operator<< (std::ostream &s, cv::Range &r)
@@ -190,6 +191,7 @@ inline int clamp(int ax, const MatShape& shape)
190191
return clamp(ax, (int)shape.size());
191192
}
192193

194+
CV__DNN_EXPERIMENTAL_NS_END
193195
}
194196
}
195197
#endif

modules/dnn/src/caffe/caffe_importer.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
//M*/
4141

4242
#include "../precomp.hpp"
43-
using namespace cv;
44-
using namespace cv::dnn;
4543

4644
#if HAVE_PROTOBUF
4745
#include "caffe.pb.h"
@@ -54,7 +52,13 @@ using namespace cv::dnn;
5452
#include <google/protobuf/text_format.h>
5553
#include <google/protobuf/io/zero_copy_stream_impl.h>
5654
#include "caffe_io.hpp"
55+
#endif
5756

57+
namespace cv {
58+
namespace dnn {
59+
CV__DNN_EXPERIMENTAL_NS_BEGIN
60+
61+
#ifdef HAVE_PROTOBUF
5862
using ::google::protobuf::RepeatedField;
5963
using ::google::protobuf::RepeatedPtrField;
6064
using ::google::protobuf::Message;
@@ -357,26 +361,29 @@ class CaffeImporter : public Importer
357361

358362
}
359363

360-
Ptr<Importer> cv::dnn::createCaffeImporter(const String &prototxt, const String &caffeModel)
364+
Ptr<Importer> createCaffeImporter(const String &prototxt, const String &caffeModel)
361365
{
362366
return Ptr<Importer>(new CaffeImporter(prototxt.c_str(), caffeModel.c_str()));
363367
}
364368

365369
#else //HAVE_PROTOBUF
366370

367-
Ptr<Importer> cv::dnn::createCaffeImporter(const String&, const String&)
371+
Ptr<Importer> createCaffeImporter(const String&, const String&)
368372
{
369373
CV_Error(cv::Error::StsNotImplemented, "libprotobuf required to import data from Caffe models");
370374
return Ptr<Importer>();
371375
}
372376

373377
#endif //HAVE_PROTOBUF
374378

375-
Net cv::dnn::readNetFromCaffe(const String &prototxt, const String &caffeModel /*= String()*/)
379+
Net readNetFromCaffe(const String &prototxt, const String &caffeModel /*= String()*/)
376380
{
377381
Ptr<Importer> caffeImporter = createCaffeImporter(prototxt, caffeModel);
378382
Net net;
379383
if (caffeImporter)
380384
caffeImporter->populateNet(net);
381385
return net;
382386
}
387+
388+
CV__DNN_EXPERIMENTAL_NS_END
389+
}} // namespace

modules/dnn/src/dnn.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@
5050
#include <opencv2/dnn/shape_utils.hpp>
5151
#include <opencv2/imgproc.hpp>
5252

53-
using namespace cv;
54-
using namespace cv::dnn;
53+
namespace cv {
54+
namespace dnn {
55+
CV__DNN_EXPERIMENTAL_NS_BEGIN
5556

5657
using std::vector;
5758
using std::map;
@@ -74,11 +75,6 @@ namespace
7475
};
7576
}
7677

77-
namespace cv
78-
{
79-
namespace dnn
80-
{
81-
8278
template<typename T>
8379
static String toString(const T &v)
8480
{
@@ -2030,5 +2026,5 @@ BackendWrapper::BackendWrapper(const Ptr<BackendWrapper>& base, const MatShape&
20302026

20312027
BackendWrapper::~BackendWrapper() {}
20322028

2033-
}
2034-
}
2029+
CV__DNN_EXPERIMENTAL_NS_END
2030+
}} // namespace

modules/dnn/src/init.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,9 @@
4242
#include "precomp.hpp"
4343
#include <opencv2/dnn/layer.details.hpp>
4444

45-
namespace cv
46-
{
47-
namespace dnn
48-
{
45+
namespace cv {
46+
namespace dnn {
47+
CV__DNN_EXPERIMENTAL_NS_BEGIN
4948

5049
static Mutex* __initialization_mutex = NULL;
5150
Mutex& getInitializationMutex()
@@ -98,4 +97,5 @@ void initializeLayerFactory()
9897
CV_DNN_REGISTER_LAYER_CLASS(Scale, ScaleLayer);
9998
}
10099

101-
}} //namespace
100+
CV__DNN_EXPERIMENTAL_NS_END
101+
}} // namespace

0 commit comments

Comments
 (0)