mirror of
https://github.com/opencv/opencv.git
synced 2024-11-24 11:10:21 +08:00
added vector<bool> support (http://code.opencv.org/issues/3826)
This commit is contained in:
parent
d8f360316d
commit
135fa85e8f
@ -163,7 +163,8 @@ public:
|
||||
CUDA_HOST_MEM = 8 << KIND_SHIFT,
|
||||
CUDA_GPU_MAT = 9 << KIND_SHIFT,
|
||||
UMAT =10 << KIND_SHIFT,
|
||||
STD_VECTOR_UMAT =11 << KIND_SHIFT
|
||||
STD_VECTOR_UMAT =11 << KIND_SHIFT,
|
||||
STD_BOOL_VECTOR =12 << KIND_SHIFT
|
||||
};
|
||||
|
||||
_InputArray();
|
||||
@ -173,6 +174,7 @@ public:
|
||||
_InputArray(const std::vector<Mat>& vec);
|
||||
template<typename _Tp> _InputArray(const Mat_<_Tp>& m);
|
||||
template<typename _Tp> _InputArray(const std::vector<_Tp>& vec);
|
||||
_InputArray(const std::vector<bool>& vec);
|
||||
template<typename _Tp> _InputArray(const std::vector<std::vector<_Tp> >& vec);
|
||||
template<typename _Tp> _InputArray(const std::vector<Mat_<_Tp> >& vec);
|
||||
template<typename _Tp> _InputArray(const _Tp* vec, int n);
|
||||
@ -284,6 +286,7 @@ public:
|
||||
_OutputArray(cuda::HostMem& cuda_mem);
|
||||
template<typename _Tp> _OutputArray(cudev::GpuMat_<_Tp>& m);
|
||||
template<typename _Tp> _OutputArray(std::vector<_Tp>& vec);
|
||||
_OutputArray(std::vector<bool>& vec);
|
||||
template<typename _Tp> _OutputArray(std::vector<std::vector<_Tp> >& vec);
|
||||
template<typename _Tp> _OutputArray(std::vector<Mat_<_Tp> >& vec);
|
||||
template<typename _Tp> _OutputArray(Mat_<_Tp>& m);
|
||||
@ -340,6 +343,7 @@ public:
|
||||
_InputOutputArray(cuda::HostMem& cuda_mem);
|
||||
template<typename _Tp> _InputOutputArray(cudev::GpuMat_<_Tp>& m);
|
||||
template<typename _Tp> _InputOutputArray(std::vector<_Tp>& vec);
|
||||
_InputOutputArray(std::vector<bool>& vec);
|
||||
template<typename _Tp> _InputOutputArray(std::vector<std::vector<_Tp> >& vec);
|
||||
template<typename _Tp> _InputOutputArray(std::vector<Mat_<_Tp> >& vec);
|
||||
template<typename _Tp> _InputOutputArray(Mat_<_Tp>& m);
|
||||
|
@ -77,6 +77,10 @@ template<typename _Tp> inline
|
||||
_InputArray::_InputArray(const std::vector<_Tp>& vec)
|
||||
{ init(FIXED_TYPE + STD_VECTOR + DataType<_Tp>::type + ACCESS_READ, &vec); }
|
||||
|
||||
inline
|
||||
_InputArray::_InputArray(const std::vector<bool>& vec)
|
||||
{ init(FIXED_TYPE + STD_BOOL_VECTOR + DataType<bool>::type + ACCESS_READ, &vec); }
|
||||
|
||||
template<typename _Tp> inline
|
||||
_InputArray::_InputArray(const std::vector<std::vector<_Tp> >& vec)
|
||||
{ init(FIXED_TYPE + STD_VECTOR_VECTOR + DataType<_Tp>::type + ACCESS_READ, &vec); }
|
||||
@ -140,6 +144,10 @@ template<typename _Tp> inline
|
||||
_OutputArray::_OutputArray(std::vector<_Tp>& vec)
|
||||
{ init(FIXED_TYPE + STD_VECTOR + DataType<_Tp>::type + ACCESS_WRITE, &vec); }
|
||||
|
||||
inline
|
||||
_OutputArray::_OutputArray(std::vector<bool>&)
|
||||
{ CV_Error(Error::StsUnsupportedFormat, "std::vector<bool> cannot be an output array\n"); }
|
||||
|
||||
template<typename _Tp> inline
|
||||
_OutputArray::_OutputArray(std::vector<std::vector<_Tp> >& vec)
|
||||
{ init(FIXED_TYPE + STD_VECTOR_VECTOR + DataType<_Tp>::type + ACCESS_WRITE, &vec); }
|
||||
@ -227,6 +235,9 @@ template<typename _Tp> inline
|
||||
_InputOutputArray::_InputOutputArray(std::vector<_Tp>& vec)
|
||||
{ init(FIXED_TYPE + STD_VECTOR + DataType<_Tp>::type + ACCESS_RW, &vec); }
|
||||
|
||||
inline _InputOutputArray::_InputOutputArray(std::vector<bool>&)
|
||||
{ CV_Error(Error::StsUnsupportedFormat, "std::vector<bool> cannot be an input/output array\n"); }
|
||||
|
||||
template<typename _Tp> inline
|
||||
_InputOutputArray::_InputOutputArray(std::vector<std::vector<_Tp> >& vec)
|
||||
{ init(FIXED_TYPE + STD_VECTOR_VECTOR + DataType<_Tp>::type + ACCESS_RW, &vec); }
|
||||
|
@ -1154,6 +1154,21 @@ Mat _InputArray::getMat_(int i) const
|
||||
return !v.empty() ? Mat(size(), t, (void*)&v[0]) : Mat();
|
||||
}
|
||||
|
||||
if( k == STD_BOOL_VECTOR )
|
||||
{
|
||||
CV_Assert( i < 0 );
|
||||
int t = CV_8U;
|
||||
const std::vector<bool>& v = *(const std::vector<bool>*)obj;
|
||||
int j, n = (int)v.size();
|
||||
if( n == 0 )
|
||||
return Mat();
|
||||
Mat m(1, n, t);
|
||||
uchar* dst = m.data;
|
||||
for( j = 0; j < n; j++ )
|
||||
dst[j] = (uchar)v[j];
|
||||
return m;
|
||||
}
|
||||
|
||||
if( k == NONE )
|
||||
return Mat();
|
||||
|
||||
@ -1481,6 +1496,13 @@ Size _InputArray::size(int i) const
|
||||
return szb == szi ? Size((int)szb, 1) : Size((int)(szb/CV_ELEM_SIZE(flags)), 1);
|
||||
}
|
||||
|
||||
if( k == STD_BOOL_VECTOR )
|
||||
{
|
||||
CV_Assert( i < 0 );
|
||||
const std::vector<bool>& v = *(const std::vector<bool>*)obj;
|
||||
return Size((int)v.size(), 1);
|
||||
}
|
||||
|
||||
if( k == NONE )
|
||||
return Size();
|
||||
|
||||
@ -1661,7 +1683,7 @@ int _InputArray::dims(int i) const
|
||||
return 2;
|
||||
}
|
||||
|
||||
if( k == STD_VECTOR )
|
||||
if( k == STD_VECTOR || k == STD_BOOL_VECTOR )
|
||||
{
|
||||
CV_Assert( i < 0 );
|
||||
return 2;
|
||||
@ -1773,7 +1795,7 @@ int _InputArray::type(int i) const
|
||||
if( k == EXPR )
|
||||
return ((const MatExpr*)obj)->type();
|
||||
|
||||
if( k == MATX || k == STD_VECTOR || k == STD_VECTOR_VECTOR )
|
||||
if( k == MATX || k == STD_VECTOR || k == STD_VECTOR_VECTOR || k == STD_BOOL_VECTOR )
|
||||
return CV_MAT_TYPE(flags);
|
||||
|
||||
if( k == NONE )
|
||||
@ -1848,6 +1870,12 @@ bool _InputArray::empty() const
|
||||
return v.empty();
|
||||
}
|
||||
|
||||
if( k == STD_BOOL_VECTOR )
|
||||
{
|
||||
const std::vector<bool>& v = *(const std::vector<bool>*)obj;
|
||||
return v.empty();
|
||||
}
|
||||
|
||||
if( k == NONE )
|
||||
return true;
|
||||
|
||||
@ -1892,7 +1920,8 @@ bool _InputArray::isContinuous(int i) const
|
||||
if( k == UMAT )
|
||||
return i < 0 ? ((const UMat*)obj)->isContinuous() : true;
|
||||
|
||||
if( k == EXPR || k == MATX || k == STD_VECTOR || k == NONE || k == STD_VECTOR_VECTOR)
|
||||
if( k == EXPR || k == MATX || k == STD_VECTOR ||
|
||||
k == NONE || k == STD_VECTOR_VECTOR || k == STD_BOOL_VECTOR )
|
||||
return true;
|
||||
|
||||
if( k == STD_VECTOR_MAT )
|
||||
@ -1923,7 +1952,8 @@ bool _InputArray::isSubmatrix(int i) const
|
||||
if( k == UMAT )
|
||||
return i < 0 ? ((const UMat*)obj)->isSubmatrix() : false;
|
||||
|
||||
if( k == EXPR || k == MATX || k == STD_VECTOR || k == NONE || k == STD_VECTOR_VECTOR)
|
||||
if( k == EXPR || k == MATX || k == STD_VECTOR ||
|
||||
k == NONE || k == STD_VECTOR_VECTOR || k == STD_BOOL_VECTOR )
|
||||
return false;
|
||||
|
||||
if( k == STD_VECTOR_MAT )
|
||||
@ -1961,7 +1991,8 @@ size_t _InputArray::offset(int i) const
|
||||
return ((const UMat*)obj)->offset;
|
||||
}
|
||||
|
||||
if( k == EXPR || k == MATX || k == STD_VECTOR || k == NONE || k == STD_VECTOR_VECTOR)
|
||||
if( k == EXPR || k == MATX || k == STD_VECTOR ||
|
||||
k == NONE || k == STD_VECTOR_VECTOR || k == STD_BOOL_VECTOR )
|
||||
return 0;
|
||||
|
||||
if( k == STD_VECTOR_MAT )
|
||||
@ -2008,7 +2039,8 @@ size_t _InputArray::step(int i) const
|
||||
return ((const UMat*)obj)->step;
|
||||
}
|
||||
|
||||
if( k == EXPR || k == MATX || k == STD_VECTOR || k == NONE || k == STD_VECTOR_VECTOR)
|
||||
if( k == EXPR || k == MATX || k == STD_VECTOR ||
|
||||
k == NONE || k == STD_VECTOR_VECTOR || k == STD_BOOL_VECTOR )
|
||||
return 0;
|
||||
|
||||
if( k == STD_VECTOR_MAT )
|
||||
@ -2043,7 +2075,7 @@ void _InputArray::copyTo(const _OutputArray& arr) const
|
||||
|
||||
if( k == NONE )
|
||||
arr.release();
|
||||
else if( k == MAT || k == MATX || k == STD_VECTOR )
|
||||
else if( k == MAT || k == MATX || k == STD_VECTOR || k == STD_BOOL_VECTOR )
|
||||
{
|
||||
Mat m = getMat();
|
||||
m.copyTo(arr);
|
||||
@ -2068,7 +2100,7 @@ void _InputArray::copyTo(const _OutputArray& arr, const _InputArray & mask) cons
|
||||
|
||||
if( k == NONE )
|
||||
arr.release();
|
||||
else if( k == MAT || k == MATX || k == STD_VECTOR )
|
||||
else if( k == MAT || k == MATX || k == STD_VECTOR || k == STD_BOOL_VECTOR )
|
||||
{
|
||||
Mat m = getMat();
|
||||
m.copyTo(arr, mask);
|
||||
|
@ -1801,3 +1801,18 @@ TEST(Core_FindNonZero, singular)
|
||||
findNonZero(img, pts2);
|
||||
ASSERT_TRUE(pts.empty() && pts2.empty());
|
||||
}
|
||||
|
||||
TEST(Core_BoolVector, support)
|
||||
{
|
||||
std::vector<bool> test;
|
||||
int i, n = 205;
|
||||
int nz = 0;
|
||||
test.resize(n);
|
||||
for( i = 0; i < n; i++ )
|
||||
{
|
||||
test[i] = theRNG().uniform(0, 2) != 0;
|
||||
nz += (int)test[i];
|
||||
}
|
||||
ASSERT_EQ( nz, countNonZero(test) );
|
||||
ASSERT_FLOAT_EQ((float)nz/n, (float)(mean(test)[0]));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user