Skip to content

Commit e82e672

Browse files
committed
Merge remote-tracking branch 'upstream/3.4' into merge-3.4
2 parents 09b3dcb + 6fbf6f8 commit e82e672

File tree

26 files changed

+302
-330
lines changed

26 files changed

+302
-330
lines changed

doc/opencv.bib

-11
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,6 @@ @article{ChambolleEtAl
180180
volume = {9},
181181
publisher = {Walter de Gruyter}
182182
}
183-
@inproceedings{DD02,
184-
author = {Durand, Fr{\'e}do and Dorsey, Julie},
185-
title = {Fast bilateral filtering for the display of high-dynamic-range images},
186-
booktitle = {ACM Transactions on Graphics (TOG)},
187-
year = {2002},
188-
pages = {257--266},
189-
volume = {21},
190-
number = {3},
191-
publisher = {ACM},
192-
url = {https://www.researchgate.net/profile/Julie_Dorsey/publication/220184746_Fast_Bilateral_Filtering_for_the_Display_of_High_-_dynamic_-_range_Images/links/54566b000cf26d5090a95f96/Fast-Bilateral-Filtering-for-the-Display-of-High-dynamic-range-Images.pdf}
193-
}
194183
@inproceedings{DM03,
195184
author = {Drago, Fr{\'e}d{\'e}ric and Myszkowski, Karol and Annen, Thomas and Chiba, Norishige},
196185
title = {Adaptive logarithmic mapping for displaying high contrast scenes},

doc/py_tutorials/py_photo/py_hdr/py_hdr.markdown

+2-4
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,8 @@ we will later have to clip the data in order to avoid overflow.
8585

8686
@code{.py}
8787
# Tonemap HDR image
88-
tonemap1 = cv.createTonemapDurand(gamma=2.2)
88+
tonemap1 = cv.createTonemap(gamma=2.2)
8989
res_debevec = tonemap1.process(hdr_debevec.copy())
90-
tonemap2 = cv.createTonemapDurand(gamma=1.3)
91-
res_robertson = tonemap2.process(hdr_robertson.copy())
9290
@endcode
9391

9492
### 4. Merge exposures using Mertens fusion
@@ -173,5 +171,5 @@ Additional Resources
173171

174172
Exercises
175173
---------
176-
1. Try all tonemap algorithms: cv::TonemapDrago, cv::TonemapDurand, cv::TonemapMantiuk and cv::TonemapReinhard
174+
1. Try all tonemap algorithms: cv::TonemapDrago, cv::TonemapMantiuk and cv::TonemapReinhard
177175
2. Try changing the parameters in the HDR calibration and tonemap methods.

doc/tutorials/photo/hdr_imaging/hdr_imaging.markdown

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ Now it's time to look at the results. Note that HDR image can't be stored in one
171171
formats, so we save it to Radiance image (.hdr). Also all HDR imaging functions return results in
172172
[0, 1] range so we should multiply result by 255.
173173

174-
You can try other tonemap algorithms: cv::TonemapDrago, cv::TonemapDurand, cv::TonemapMantiuk and cv::TonemapReinhard
174+
You can try other tonemap algorithms: cv::TonemapDrago, cv::TonemapMantiuk and cv::TonemapReinhard
175175
You can also adjust the parameters in the HDR calibration and tonemap methods for your own photos.
176176

177177
Results

modules/core/src/arithm.cpp

+43-37
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,7 @@ struct InRange_SIMD
13331333
}
13341334
};
13351335

1336-
#if CV_SIMD128
1336+
#if CV_SIMD
13371337

13381338
template <>
13391339
struct InRange_SIMD<uchar>
@@ -1342,16 +1342,17 @@ struct InRange_SIMD<uchar>
13421342
uchar * dst, int len) const
13431343
{
13441344
int x = 0;
1345-
const int width = v_uint8x16::nlanes;
1345+
const int width = v_uint8::nlanes;
13461346

13471347
for (; x <= len - width; x += width)
13481348
{
1349-
v_uint8x16 values = v_load(src1 + x);
1350-
v_uint8x16 low = v_load(src2 + x);
1351-
v_uint8x16 high = v_load(src3 + x);
1349+
v_uint8 values = vx_load(src1 + x);
1350+
v_uint8 low = vx_load(src2 + x);
1351+
v_uint8 high = vx_load(src3 + x);
13521352

13531353
v_store(dst + x, (values >= low) & (high >= values));
13541354
}
1355+
vx_cleanup();
13551356
return x;
13561357
}
13571358
};
@@ -1363,16 +1364,17 @@ struct InRange_SIMD<schar>
13631364
uchar * dst, int len) const
13641365
{
13651366
int x = 0;
1366-
const int width = v_int8x16::nlanes;
1367+
const int width = v_int8::nlanes;
13671368

13681369
for (; x <= len - width; x += width)
13691370
{
1370-
v_int8x16 values = v_load(src1 + x);
1371-
v_int8x16 low = v_load(src2 + x);
1372-
v_int8x16 high = v_load(src3 + x);
1371+
v_int8 values = vx_load(src1 + x);
1372+
v_int8 low = vx_load(src2 + x);
1373+
v_int8 high = vx_load(src3 + x);
13731374

13741375
v_store((schar*)(dst + x), (values >= low) & (high >= values));
13751376
}
1377+
vx_cleanup();
13761378
return x;
13771379
}
13781380
};
@@ -1384,20 +1386,21 @@ struct InRange_SIMD<ushort>
13841386
uchar * dst, int len) const
13851387
{
13861388
int x = 0;
1387-
const int width = v_uint16x8::nlanes * 2;
1389+
const int width = v_uint16::nlanes * 2;
13881390

13891391
for (; x <= len - width; x += width)
13901392
{
1391-
v_uint16x8 values1 = v_load(src1 + x);
1392-
v_uint16x8 low1 = v_load(src2 + x);
1393-
v_uint16x8 high1 = v_load(src3 + x);
1393+
v_uint16 values1 = vx_load(src1 + x);
1394+
v_uint16 low1 = vx_load(src2 + x);
1395+
v_uint16 high1 = vx_load(src3 + x);
13941396

1395-
v_uint16x8 values2 = v_load(src1 + x + v_uint16x8::nlanes);
1396-
v_uint16x8 low2 = v_load(src2 + x + v_uint16x8::nlanes);
1397-
v_uint16x8 high2 = v_load(src3 + x + v_uint16x8::nlanes);
1397+
v_uint16 values2 = vx_load(src1 + x + v_uint16::nlanes);
1398+
v_uint16 low2 = vx_load(src2 + x + v_uint16::nlanes);
1399+
v_uint16 high2 = vx_load(src3 + x + v_uint16::nlanes);
13981400

13991401
v_store(dst + x, v_pack((values1 >= low1) & (high1 >= values1), (values2 >= low2) & (high2 >= values2)));
14001402
}
1403+
vx_cleanup();
14011404
return x;
14021405
}
14031406
};
@@ -1409,20 +1412,21 @@ struct InRange_SIMD<short>
14091412
uchar * dst, int len) const
14101413
{
14111414
int x = 0;
1412-
const int width = (int)v_int16x8::nlanes * 2;
1415+
const int width = (int)v_int16::nlanes * 2;
14131416

14141417
for (; x <= len - width; x += width)
14151418
{
1416-
v_int16x8 values1 = v_load(src1 + x);
1417-
v_int16x8 low1 = v_load(src2 + x);
1418-
v_int16x8 high1 = v_load(src3 + x);
1419+
v_int16 values1 = vx_load(src1 + x);
1420+
v_int16 low1 = vx_load(src2 + x);
1421+
v_int16 high1 = vx_load(src3 + x);
14191422

1420-
v_int16x8 values2 = v_load(src1 + x + v_int16x8::nlanes);
1421-
v_int16x8 low2 = v_load(src2 + x + v_int16x8::nlanes);
1422-
v_int16x8 high2 = v_load(src3 + x + v_int16x8::nlanes);
1423+
v_int16 values2 = vx_load(src1 + x + v_int16::nlanes);
1424+
v_int16 low2 = vx_load(src2 + x + v_int16::nlanes);
1425+
v_int16 high2 = vx_load(src3 + x + v_int16::nlanes);
14231426

14241427
v_store((schar*)(dst + x), v_pack((values1 >= low1) & (high1 >= values1), (values2 >= low2) & (high2 >= values2)));
14251428
}
1429+
vx_cleanup();
14261430
return x;
14271431
}
14281432
};
@@ -1434,20 +1438,21 @@ struct InRange_SIMD<int>
14341438
uchar * dst, int len) const
14351439
{
14361440
int x = 0;
1437-
const int width = (int)v_int32x4::nlanes * 2;
1441+
const int width = (int)v_int32::nlanes * 2;
14381442

14391443
for (; x <= len - width; x += width)
14401444
{
1441-
v_int32x4 values1 = v_load(src1 + x);
1442-
v_int32x4 low1 = v_load(src2 + x);
1443-
v_int32x4 high1 = v_load(src3 + x);
1445+
v_int32 values1 = vx_load(src1 + x);
1446+
v_int32 low1 = vx_load(src2 + x);
1447+
v_int32 high1 = vx_load(src3 + x);
14441448

1445-
v_int32x4 values2 = v_load(src1 + x + v_int32x4::nlanes);
1446-
v_int32x4 low2 = v_load(src2 + x + v_int32x4::nlanes);
1447-
v_int32x4 high2 = v_load(src3 + x + v_int32x4::nlanes);
1449+
v_int32 values2 = vx_load(src1 + x + v_int32::nlanes);
1450+
v_int32 low2 = vx_load(src2 + x + v_int32::nlanes);
1451+
v_int32 high2 = vx_load(src3 + x + v_int32::nlanes);
14481452

14491453
v_pack_store(dst + x, v_reinterpret_as_u16(v_pack((values1 >= low1) & (high1 >= values1), (values2 >= low2) & (high2 >= values2))));
14501454
}
1455+
vx_cleanup();
14511456
return x;
14521457
}
14531458
};
@@ -1459,20 +1464,21 @@ struct InRange_SIMD<float>
14591464
uchar * dst, int len) const
14601465
{
14611466
int x = 0;
1462-
const int width = (int)v_float32x4::nlanes * 2;
1467+
const int width = (int)v_float32::nlanes * 2;
14631468

14641469
for (; x <= len - width; x += width)
14651470
{
1466-
v_float32x4 values1 = v_load(src1 + x);
1467-
v_float32x4 low1 = v_load(src2 + x);
1468-
v_float32x4 high1 = v_load(src3 + x);
1471+
v_float32 values1 = vx_load(src1 + x);
1472+
v_float32 low1 = vx_load(src2 + x);
1473+
v_float32 high1 = vx_load(src3 + x);
14691474

1470-
v_float32x4 values2 = v_load(src1 + x + v_float32x4::nlanes);
1471-
v_float32x4 low2 = v_load(src2 + x + v_float32x4::nlanes);
1472-
v_float32x4 high2 = v_load(src3 + x + v_float32x4::nlanes);
1475+
v_float32 values2 = vx_load(src1 + x + v_float32::nlanes);
1476+
v_float32 low2 = vx_load(src2 + x + v_float32::nlanes);
1477+
v_float32 high2 = vx_load(src3 + x + v_float32::nlanes);
14731478

14741479
v_pack_store(dst + x, v_pack(v_reinterpret_as_u32((values1 >= low1) & (high1 >= values1)), v_reinterpret_as_u32((values2 >= low2) & (high2 >= values2))));
14751480
}
1481+
vx_cleanup();
14761482
return x;
14771483
}
14781484
};

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

+9
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ CV__DNN_INLINE_NS_BEGIN
7777
static Ptr<Layer> create(const LayerParams &params);
7878
};
7979

80+
/**
81+
* Constant layer produces the same data blob at an every forward pass.
82+
*/
83+
class CV_EXPORTS ConstLayer : public Layer
84+
{
85+
public:
86+
static Ptr<Layer> create(const LayerParams &params);
87+
};
88+
8089
//! LSTM recurrent layer
8190
class CV_EXPORTS LSTMLayer : public Layer
8291
{

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

+3
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ CV__DNN_INLINE_NS_BEGIN
8888
DNN_TARGET_FPGA
8989
};
9090

91+
CV_EXPORTS std::vector< std::pair<Backend, Target> > getAvailableBackends();
92+
CV_EXPORTS std::vector<Target> getAvailableTargets(Backend be);
93+
9194
/** @brief This class provides all data needed to initialize layer.
9295
*
9396
* It includes dictionary with scalar params (which can be read by using Dict interface),

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#define OPENCV_DNN_VERSION_HPP
77

88
/// Use with major OpenCV version only.
9-
#define OPENCV_DNN_API_VERSION 20181121
9+
#define OPENCV_DNN_API_VERSION 20181205
1010

1111
#if !defined CV_DOXYGEN && !defined CV_DNN_DONT_ADD_INLINE_NS
1212
#define CV__DNN_INLINE_NS __CV_CAT(dnn4_v, OPENCV_DNN_API_VERSION)

modules/dnn/perf/perf_net.cpp

-17
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,6 @@ class DNNTestNetwork : public ::perf::TestBaseWithParam< tuple<Backend, Target>
3131
void processNet(std::string weights, std::string proto, std::string halide_scheduler,
3232
const Mat& input, const std::string& outputLayer = "")
3333
{
34-
if (backend == DNN_BACKEND_OPENCV && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
35-
{
36-
#if defined(HAVE_OPENCL)
37-
if (!cv::ocl::useOpenCL())
38-
#endif
39-
{
40-
throw cvtest::SkipTestException("OpenCL is not available/disabled in OpenCV");
41-
}
42-
}
43-
if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD)
44-
{
45-
if (!checkIETarget(DNN_TARGET_MYRIAD))
46-
{
47-
throw SkipTestException("Myriad is not available/disabled in OpenCV");
48-
}
49-
}
50-
5134
randu(input, 0.0f, 1.0f);
5235

5336
weights = findDataFile(weights, false);

modules/dnn/src/dnn.cpp

+105
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,111 @@ using std::map;
8585
using std::make_pair;
8686
using std::set;
8787

88+
//==================================================================================================
89+
90+
class BackendRegistry
91+
{
92+
public:
93+
typedef std::vector< std::pair<Backend, Target> > BackendsList;
94+
const BackendsList & getBackends() const { return backends; }
95+
static BackendRegistry & getRegistry()
96+
{
97+
static BackendRegistry impl;
98+
return impl;
99+
}
100+
private:
101+
BackendRegistry()
102+
{
103+
#ifdef HAVE_HALIDE
104+
backends.push_back(std::make_pair(DNN_BACKEND_HALIDE, DNN_TARGET_CPU));
105+
# ifdef HAVE_OPENCL
106+
if (cv::ocl::useOpenCL())
107+
backends.push_back(std::make_pair(DNN_BACKEND_HALIDE, DNN_TARGET_OPENCL));
108+
# endif
109+
#endif // HAVE_HALIDE
110+
111+
#ifdef HAVE_INF_ENGINE
112+
if (checkIETarget(DNN_TARGET_CPU))
113+
backends.push_back(std::make_pair(DNN_BACKEND_INFERENCE_ENGINE, DNN_TARGET_CPU));
114+
if (checkIETarget(DNN_TARGET_MYRIAD))
115+
backends.push_back(std::make_pair(DNN_BACKEND_INFERENCE_ENGINE, DNN_TARGET_MYRIAD));
116+
if (checkIETarget(DNN_TARGET_FPGA))
117+
backends.push_back(std::make_pair(DNN_BACKEND_INFERENCE_ENGINE, DNN_TARGET_FPGA));
118+
# ifdef HAVE_OPENCL
119+
if (cv::ocl::useOpenCL() && ocl::Device::getDefault().isIntel())
120+
{
121+
if (checkIETarget(DNN_TARGET_OPENCL))
122+
backends.push_back(std::make_pair(DNN_BACKEND_INFERENCE_ENGINE, DNN_TARGET_OPENCL));
123+
if (checkIETarget(DNN_TARGET_OPENCL_FP16))
124+
backends.push_back(std::make_pair(DNN_BACKEND_INFERENCE_ENGINE, DNN_TARGET_OPENCL_FP16));
125+
}
126+
# endif
127+
#endif // HAVE_INF_ENGINE
128+
129+
#ifdef HAVE_OPENCL
130+
if (cv::ocl::useOpenCL())
131+
{
132+
backends.push_back(std::make_pair(DNN_BACKEND_OPENCV, DNN_TARGET_OPENCL));
133+
backends.push_back(std::make_pair(DNN_BACKEND_OPENCV, DNN_TARGET_OPENCL_FP16));
134+
}
135+
#endif
136+
137+
backends.push_back(std::make_pair(DNN_BACKEND_OPENCV, DNN_TARGET_CPU));
138+
139+
#ifdef HAVE_VULKAN
140+
backends.push_back(std::make_pair(DNN_BACKEND_VKCOM, DNN_TARGET_VULKAN)); // TODO Add device check
141+
#endif
142+
}
143+
static inline bool checkIETarget(int target)
144+
{
145+
#ifndef HAVE_INF_ENGINE
146+
return false;
147+
#else
148+
cv::dnn::Net net;
149+
cv::dnn::LayerParams lp;
150+
net.addLayerToPrev("testLayer", "Identity", lp);
151+
net.setPreferableBackend(cv::dnn::DNN_BACKEND_INFERENCE_ENGINE);
152+
net.setPreferableTarget(target);
153+
static int inpDims[] = {1, 2, 3, 4};
154+
net.setInput(cv::Mat(4, &inpDims[0], CV_32FC1, cv::Scalar(0)));
155+
try
156+
{
157+
net.forward();
158+
}
159+
catch(...)
160+
{
161+
return false;
162+
}
163+
return true;
164+
#endif
165+
}
166+
167+
BackendsList backends;
168+
};
169+
170+
171+
std::vector< std::pair<Backend, Target> > getAvailableBackends()
172+
{
173+
return BackendRegistry::getRegistry().getBackends();
174+
}
175+
176+
std::vector<Target> getAvailableTargets(Backend be)
177+
{
178+
if (be == DNN_BACKEND_DEFAULT)
179+
be = (Backend)PARAM_DNN_BACKEND_DEFAULT;
180+
181+
std::vector<Target> result;
182+
const BackendRegistry::BackendsList all_backends = getAvailableBackends();
183+
for(BackendRegistry::BackendsList::const_iterator i = all_backends.begin(); i != all_backends.end(); ++i )
184+
{
185+
if (i->first == be)
186+
result.push_back(i->second);
187+
}
188+
return result;
189+
}
190+
191+
//==================================================================================================
192+
88193
namespace
89194
{
90195
typedef std::vector<MatShape> ShapesVec;

modules/dnn/src/init.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ void initializeLayerFactory()
112112
CV_DNN_REGISTER_LAYER_CLASS(Dropout, BlankLayer);
113113
CV_DNN_REGISTER_LAYER_CLASS(Identity, BlankLayer);
114114
CV_DNN_REGISTER_LAYER_CLASS(Silence, BlankLayer);
115+
CV_DNN_REGISTER_LAYER_CLASS(Const, ConstLayer);
115116

116117
CV_DNN_REGISTER_LAYER_CLASS(Crop, CropLayer);
117118
CV_DNN_REGISTER_LAYER_CLASS(Eltwise, EltwiseLayer);

0 commit comments

Comments
 (0)