Skip to content

Commit e0265c6

Browse files
committed
Merge remote-tracking branch 'upstream/3.4' into merge-3.4
2 parents 28c064f + 19f1bac commit e0265c6

File tree

33 files changed

+3657
-315
lines changed

33 files changed

+3657
-315
lines changed

doc/opencv.bib

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,29 @@ @techreport{blanco2010tutorial
110110
year = {2010},
111111
url = {http://ingmec.ual.es/~jlblanco/papers/jlblanco2010geometry3D_techrep.pdf}
112112
}
113+
@inproceedings{Bolelli2017,
114+
title = {{Two More Strategies to Speed Up Connected Components Labeling Algorithms}},
115+
author = {Bolelli, Federico and Cancilla, Michele and Grana, Costantino},
116+
year = 2017,
117+
booktitle = {Image Analysis and Processing - ICIAP 2017},
118+
publisher = {Springer},
119+
volume = 10485,
120+
pages = {48--58},
121+
doi = {10.1007/978-3-319-68548-9_5},
122+
isbn = {978-3-319-68547-2}
123+
}
124+
@article{Bolelli2019,
125+
title = {{Spaghetti Labeling: Directed Acyclic Graphs for Block-Based Connected Components Labeling}},
126+
author = {Bolelli, Federico and Allegretti, Stefano and Baraldi, Lorenzo and Grana, Costantino},
127+
year = 2019,
128+
journal = {IEEE Transactions on Image Processing},
129+
publisher = {IEEE},
130+
volume = 29,
131+
number = 1,
132+
pages = {1999--2012},
133+
doi = {10.1109/TIP.2019.2946979},
134+
issn = {1057-7149}
135+
}
113136
@article{Borgefors86,
114137
author = {Borgefors, Gunilla},
115138
title = {Distance transformations in digital images},
@@ -420,6 +443,16 @@ @article{Gallego2014ACF
420443
volume = {51},
421444
pages = {378-384}
422445
}
446+
@article{Grana2010,
447+
title = {{Optimized Block-Based Connected Components Labeling With Decision Trees}},
448+
author = {Grana, Costantino and Borghesani, Daniele and Cucchiara, Rita},
449+
year = 2010,
450+
journal = {IEEE Transactions on Image Processing},
451+
volume = 19,
452+
number = 6,
453+
pages = {1596--1609},
454+
doi = {10.1109/TIP.2010.2044963}
455+
}
423456
@article{taubin1991,
424457
abstract = {The author addresses the problem of parametric representation and estimation of complex planar curves in 2-D surfaces in 3-D, and nonplanar space curves in 3-D. Curves and surfaces can be defined either parametrically or implicitly, with the latter representation used here. A planar curve is the set of zeros of a smooth function of two variables <e1>x</e1>-<e1>y</e1>, a surface is the set of zeros of a smooth function of three variables <e1>x</e1>-<e1>y</e1>-<e1>z</e1>, and a space curve is the intersection of two surfaces, which are the set of zeros of two linearly independent smooth functions of three variables <e1>x</e1>-<e1>y</e1>-<e1>z</e1> For example, the surface of a complex object in 3-D can be represented as a subset of a single implicit surface, with similar results for planar and space curves. It is shown how this unified representation can be used for object recognition, object position estimation, and segmentation of objects into meaningful subobjects, that is, the detection of `interest regions' that are more complex than high curvature regions and, hence, more useful as features for object recognition},
425458
author = {Taubin, Gabriel},

modules/core/include/opencv2/core/cvdef.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,9 @@ typedef union Cv64suf
390390
}
391391
Cv64suf;
392392

393+
#ifndef OPENCV_ABI_COMPATIBILITY
393394
#define OPENCV_ABI_COMPATIBILITY 400
395+
#endif
394396

395397
#ifdef __OPENCV_BUILD
396398
# define DISABLE_OPENCV_3_COMPATIBILITY

modules/core/include/opencv2/core/mat.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,19 @@ class CV_EXPORTS _InputArray
170170
STD_VECTOR = 3 << KIND_SHIFT,
171171
STD_VECTOR_VECTOR = 4 << KIND_SHIFT,
172172
STD_VECTOR_MAT = 5 << KIND_SHIFT,
173-
EXPR = 6 << KIND_SHIFT, //!< removed
173+
#if OPENCV_ABI_COMPATIBILITY < 500
174+
EXPR = 6 << KIND_SHIFT, //!< removed: https://github.com/opencv/opencv/pull/17046
175+
#endif
174176
OPENGL_BUFFER = 7 << KIND_SHIFT,
175177
CUDA_HOST_MEM = 8 << KIND_SHIFT,
176178
CUDA_GPU_MAT = 9 << KIND_SHIFT,
177179
UMAT =10 << KIND_SHIFT,
178180
STD_VECTOR_UMAT =11 << KIND_SHIFT,
179181
STD_BOOL_VECTOR =12 << KIND_SHIFT,
180182
STD_VECTOR_CUDA_GPU_MAT = 13 << KIND_SHIFT,
181-
STD_ARRAY =14 << KIND_SHIFT,
183+
#if OPENCV_ABI_COMPATIBILITY < 500
184+
STD_ARRAY =14 << KIND_SHIFT, //!< removed: https://github.com/opencv/opencv/issues/18897
185+
#endif
182186
STD_ARRAY_MAT =15 << KIND_SHIFT
183187
};
184188

modules/core/include/opencv2/core/mat.inl.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ _InputArray::_InputArray(const std::vector<_Tp>& vec)
111111

112112
template<typename _Tp, std::size_t _Nm> inline
113113
_InputArray::_InputArray(const std::array<_Tp, _Nm>& arr)
114-
{ init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_READ, arr.data(), Size(1, _Nm)); }
114+
{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_READ, arr.data(), Size(1, _Nm)); }
115115

116116
template<std::size_t _Nm> inline
117117
_InputArray::_InputArray(const std::array<Mat, _Nm>& arr)
@@ -169,7 +169,7 @@ template<typename _Tp, std::size_t _Nm> inline
169169
_InputArray _InputArray::rawIn(const std::array<_Tp, _Nm>& arr)
170170
{
171171
_InputArray v;
172-
v.flags = FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_READ;
172+
v.flags = FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_READ;
173173
v.obj = (void*)arr.data();
174174
v.sz = Size(1, _Nm);
175175
return v;
@@ -191,7 +191,7 @@ inline bool _InputArray::isUMatVector() const { return kind() == _InputArray::S
191191
inline bool _InputArray::isMatx() const { return kind() == _InputArray::MATX; }
192192
inline bool _InputArray::isVector() const { return kind() == _InputArray::STD_VECTOR ||
193193
kind() == _InputArray::STD_BOOL_VECTOR ||
194-
kind() == _InputArray::STD_ARRAY; }
194+
(kind() == _InputArray::MATX && (sz.width <= 1 || sz.height <= 1)); }
195195
inline bool _InputArray::isGpuMat() const { return kind() == _InputArray::CUDA_GPU_MAT; }
196196
inline bool _InputArray::isGpuMatVector() const { return kind() == _InputArray::STD_VECTOR_CUDA_GPU_MAT; }
197197

@@ -210,7 +210,7 @@ _OutputArray::_OutputArray(std::vector<_Tp>& vec)
210210

211211
template<typename _Tp, std::size_t _Nm> inline
212212
_OutputArray::_OutputArray(std::array<_Tp, _Nm>& arr)
213-
{ init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_WRITE, arr.data(), Size(1, _Nm)); }
213+
{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_WRITE, arr.data(), Size(1, _Nm)); }
214214

215215
template<std::size_t _Nm> inline
216216
_OutputArray::_OutputArray(std::array<Mat, _Nm>& arr)
@@ -242,7 +242,7 @@ _OutputArray::_OutputArray(const std::vector<_Tp>& vec)
242242

243243
template<typename _Tp, std::size_t _Nm> inline
244244
_OutputArray::_OutputArray(const std::array<_Tp, _Nm>& arr)
245-
{ init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_WRITE, arr.data(), Size(1, _Nm)); }
245+
{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_WRITE, arr.data(), Size(1, _Nm)); }
246246

247247
template<std::size_t _Nm> inline
248248
_OutputArray::_OutputArray(const std::array<Mat, _Nm>& arr)
@@ -315,7 +315,7 @@ template<typename _Tp, std::size_t _Nm> inline
315315
_OutputArray _OutputArray::rawOut(std::array<_Tp, _Nm>& arr)
316316
{
317317
_OutputArray v;
318-
v.flags = FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_WRITE;
318+
v.flags = FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_WRITE;
319319
v.obj = (void*)arr.data();
320320
v.sz = Size(1, _Nm);
321321
return v;
@@ -336,7 +336,7 @@ _InputOutputArray::_InputOutputArray(std::vector<_Tp>& vec)
336336

337337
template<typename _Tp, std::size_t _Nm> inline
338338
_InputOutputArray::_InputOutputArray(std::array<_Tp, _Nm>& arr)
339-
{ init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_RW, arr.data(), Size(1, _Nm)); }
339+
{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_RW, arr.data(), Size(1, _Nm)); }
340340

341341
template<std::size_t _Nm> inline
342342
_InputOutputArray::_InputOutputArray(std::array<Mat, _Nm>& arr)
@@ -368,7 +368,7 @@ _InputOutputArray::_InputOutputArray(const std::vector<_Tp>& vec)
368368

369369
template<typename _Tp, std::size_t _Nm> inline
370370
_InputOutputArray::_InputOutputArray(const std::array<_Tp, _Nm>& arr)
371-
{ init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_RW, arr.data(), Size(1, _Nm)); }
371+
{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_RW, arr.data(), Size(1, _Nm)); }
372372

373373
template<std::size_t _Nm> inline
374374
_InputOutputArray::_InputOutputArray(const std::array<Mat, _Nm>& arr)
@@ -443,7 +443,7 @@ template<typename _Tp, std::size_t _Nm> inline
443443
_InputOutputArray _InputOutputArray::rawInOut(std::array<_Tp, _Nm>& arr)
444444
{
445445
_InputOutputArray v;
446-
v.flags = FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_RW;
446+
v.flags = FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_RW;
447447
v.obj = (void*)arr.data();
448448
v.sz = Size(1, _Nm);
449449
return v;

modules/core/misc/java/test/MatTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,27 @@ public void testGetIntIntShortArray() {
455455
bytesNum = sm.get(1, 1, buff11);
456456
assertEquals(4, bytesNum);
457457
assertTrue(Arrays.equals(new short[] {340, 341, 0, 0}, buff11));
458+
459+
Mat m2 = new Mat(new int[]{ 5, 6, 8 }, CvType.CV_16S);
460+
short[] data = new short[(int)m2.total()];
461+
for (int i = 0; i < data.length; i++ ) {
462+
data[i] = (short)i;
463+
}
464+
m2.put(new int[] {0, 0, 0}, data);
465+
Mat matNonContinuous = m2.submat(new Range[]{new Range(1,4), new Range(2,5), new Range(3,6)});
466+
Mat matContinuous = matNonContinuous.clone();
467+
short[] outNonContinuous = new short[(int)matNonContinuous.total()];
468+
matNonContinuous.get(new int[] { 0, 0, 0 }, outNonContinuous);
469+
short[] outContinuous = new short[(int)matNonContinuous.total()];
470+
matContinuous.get(new int[] { 0, 0, 0 }, outContinuous);
471+
assertArrayEquals(outNonContinuous, outContinuous);
472+
Mat subMat2 = m2.submat(new Range[]{new Range(1,4), new Range(1,5), new Range(0,8)});
473+
Mat subMatClone2 = subMat2.clone();
474+
short[] outNonContinuous2 = new short[(int)subMat2.total()];
475+
subMat2.get(new int[] { 0, 1, 1 }, outNonContinuous2);
476+
short[] outContinuous2 = new short[(int)subMat2.total()];
477+
subMatClone2.get(new int[] { 0, 1, 1 }, outContinuous2);
478+
assertArrayEquals(outNonContinuous2, outContinuous2);
458479
}
459480

460481
public void testGetNativeObjAddr() {

modules/core/src/copy.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,13 +1325,12 @@ void copyMakeConstBorder_8u( const uchar* src, size_t srcstep, cv::Size srcroi,
13251325
memcpy( dstInner + srcroi.width, constBuf, right );
13261326
}
13271327

1328-
dst += dststep*top;
1329-
13301328
for( i = 0; i < top; i++ )
1331-
memcpy(dst + (i - top)*dststep, constBuf, dstroi.width);
1329+
memcpy(dst + i * dststep, constBuf, dstroi.width);
13321330

1331+
dst += (top + srcroi.height) * dststep;
13331332
for( i = 0; i < bottom; i++ )
1334-
memcpy(dst + (i + srcroi.height)*dststep, constBuf, dstroi.width);
1333+
memcpy(dst + i * dststep, constBuf, dstroi.width);
13351334
}
13361335

13371336
}

modules/core/src/matrix_wrap.cpp

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Mat _InputArray::getMat_(int i) const
3232
return m->getMat(accessFlags).row(i);
3333
}
3434

35-
if( k == MATX || k == STD_ARRAY )
35+
if (k == MATX)
3636
{
3737
CV_Assert( i < 0 );
3838
return Mat(sz, flags, obj);
@@ -172,7 +172,7 @@ void _InputArray::getMatVector(std::vector<Mat>& mv) const
172172
return;
173173
}
174174

175-
if( k == MATX || k == STD_ARRAY )
175+
if (k == MATX)
176176
{
177177
size_t n = sz.height, esz = CV_ELEM_SIZE(flags);
178178
mv.resize(n);
@@ -361,7 +361,10 @@ ogl::Buffer _InputArray::getOGlBuffer() const
361361
_InputArray::KindFlag _InputArray::kind() const
362362
{
363363
KindFlag k = flags & KIND_MASK;
364+
#if CV_VERSION_MAJOR < 5
364365
CV_DbgAssert(k != EXPR);
366+
CV_DbgAssert(k != STD_ARRAY);
367+
#endif
365368
return k;
366369
}
367370

@@ -391,7 +394,7 @@ Size _InputArray::size(int i) const
391394
return ((const UMat*)obj)->size();
392395
}
393396

394-
if( k == MATX || k == STD_ARRAY )
397+
if (k == MATX)
395398
{
396399
CV_Assert( i < 0 );
397400
return sz;
@@ -611,7 +614,7 @@ int _InputArray::dims(int i) const
611614
return ((const UMat*)obj)->dims;
612615
}
613616

614-
if( k == MATX || k == STD_ARRAY )
617+
if (k == MATX)
615618
{
616619
CV_Assert( i < 0 );
617620
return 2;
@@ -745,7 +748,7 @@ int _InputArray::type(int i) const
745748
if( k == UMAT )
746749
return ((const UMat*)obj)->type();
747750

748-
if( k == MATX || k == STD_VECTOR || k == STD_ARRAY || k == STD_VECTOR_VECTOR || k == STD_BOOL_VECTOR )
751+
if( k == MATX || k == STD_VECTOR || k == STD_VECTOR_VECTOR || k == STD_BOOL_VECTOR )
749752
return CV_MAT_TYPE(flags);
750753

751754
if( k == NONE )
@@ -831,7 +834,7 @@ bool _InputArray::empty() const
831834
if( k == UMAT )
832835
return ((const UMat*)obj)->empty();
833836

834-
if( k == MATX || k == STD_ARRAY )
837+
if (k == MATX)
835838
return false;
836839

837840
if( k == STD_VECTOR )
@@ -900,7 +903,7 @@ bool _InputArray::isContinuous(int i) const
900903
if( k == UMAT )
901904
return i < 0 ? ((const UMat*)obj)->isContinuous() : true;
902905

903-
if( k == MATX || k == STD_VECTOR || k == STD_ARRAY ||
906+
if( k == MATX || k == STD_VECTOR ||
904907
k == NONE || k == STD_VECTOR_VECTOR || k == STD_BOOL_VECTOR )
905908
return true;
906909

@@ -941,7 +944,7 @@ bool _InputArray::isSubmatrix(int i) const
941944
if( k == UMAT )
942945
return i < 0 ? ((const UMat*)obj)->isSubmatrix() : false;
943946

944-
if( k == MATX || k == STD_VECTOR || k == STD_ARRAY ||
947+
if( k == MATX || k == STD_VECTOR ||
945948
k == NONE || k == STD_VECTOR_VECTOR || k == STD_BOOL_VECTOR )
946949
return false;
947950

@@ -986,7 +989,7 @@ size_t _InputArray::offset(int i) const
986989
return ((const UMat*)obj)->offset;
987990
}
988991

989-
if( k == MATX || k == STD_VECTOR || k == STD_ARRAY ||
992+
if( k == MATX || k == STD_VECTOR ||
990993
k == NONE || k == STD_VECTOR_VECTOR || k == STD_BOOL_VECTOR )
991994
return 0;
992995

@@ -1045,7 +1048,7 @@ size_t _InputArray::step(int i) const
10451048
return ((const UMat*)obj)->step;
10461049
}
10471050

1048-
if( k == MATX || k == STD_VECTOR || k == STD_ARRAY ||
1051+
if( k == MATX || k == STD_VECTOR ||
10491052
k == NONE || k == STD_VECTOR_VECTOR || k == STD_BOOL_VECTOR )
10501053
return 0;
10511054

@@ -1091,7 +1094,7 @@ void _InputArray::copyTo(const _OutputArray& arr) const
10911094

10921095
if( k == NONE )
10931096
arr.release();
1094-
else if( k == MAT || k == MATX || k == STD_VECTOR || k == STD_ARRAY || k == STD_BOOL_VECTOR )
1097+
else if( k == MAT || k == MATX || k == STD_VECTOR || k == STD_BOOL_VECTOR )
10951098
{
10961099
Mat m = getMat();
10971100
m.copyTo(arr);
@@ -1112,7 +1115,7 @@ void _InputArray::copyTo(const _OutputArray& arr, const _InputArray & mask) cons
11121115

11131116
if( k == NONE )
11141117
arr.release();
1115-
else if( k == MAT || k == MATX || k == STD_VECTOR || k == STD_ARRAY || k == STD_BOOL_VECTOR )
1118+
else if( k == MAT || k == MATX || k == STD_VECTOR || k == STD_BOOL_VECTOR )
11161119
{
11171120
Mat m = getMat();
11181121
m.copyTo(arr, mask);
@@ -1300,16 +1303,27 @@ void _OutputArray::create(int d, const int* sizes, int mtype, int i,
13001303
CV_Assert( i < 0 );
13011304
int type0 = CV_MAT_TYPE(flags);
13021305
CV_Assert( mtype == type0 || (CV_MAT_CN(mtype) == 1 && ((1 << type0) & fixedDepthMask) != 0) );
1303-
CV_Assert( d == 2 && ((sizes[0] == sz.height && sizes[1] == sz.width) ||
1304-
(allowTransposed && sizes[0] == sz.width && sizes[1] == sz.height)));
1305-
return;
1306-
}
1307-
1308-
if( k == STD_ARRAY )
1309-
{
1310-
int type0 = CV_MAT_TYPE(flags);
1311-
CV_Assert( mtype == type0 || (CV_MAT_CN(mtype) == 1 && ((1 << type0) & fixedDepthMask) != 0) );
1312-
CV_Assert( d == 2 && sz.area() == sizes[0]*sizes[1]);
1306+
CV_CheckLE(d, 2, "");
1307+
Size requested_size(d == 2 ? sizes[1] : 1, d >= 1 ? sizes[0] : 1);
1308+
if (sz.width == 1 || sz.height == 1)
1309+
{
1310+
// NB: 1D arrays assume allowTransposed=true (see #4159)
1311+
int total_1d = std::max(sz.width, sz.height);
1312+
CV_Check(requested_size, std::max(requested_size.width, requested_size.height) == total_1d, "");
1313+
}
1314+
else
1315+
{
1316+
if (!allowTransposed)
1317+
{
1318+
CV_CheckEQ(requested_size, sz, "");
1319+
}
1320+
else
1321+
{
1322+
CV_Check(requested_size,
1323+
(requested_size == sz || (requested_size.height == sz.width && requested_size.width == sz.height)),
1324+
"");
1325+
}
1326+
}
13131327
return;
13141328
}
13151329

@@ -1771,7 +1785,7 @@ void _OutputArray::setTo(const _InputArray& arr, const _InputArray & mask) const
17711785

17721786
if( k == NONE )
17731787
;
1774-
else if( k == MAT || k == MATX || k == STD_VECTOR || k == STD_ARRAY )
1788+
else if (k == MAT || k == MATX || k == STD_VECTOR)
17751789
{
17761790
Mat m = getMat();
17771791
m.setTo(arr, mask);

modules/core/test/test_mat.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1988,7 +1988,6 @@ class TestInputArrayRangeChecking {
19881988
C(EXPR);
19891989
C(MATX);
19901990
C(STD_VECTOR);
1991-
C(STD_ARRAY);
19921991
C(NONE);
19931992
C(STD_VECTOR_VECTOR);
19941993
C(STD_BOOL_VECTOR);

0 commit comments

Comments
 (0)