Merge pull request #9457 from alalek:type_traits_issue_7599

pull/9417/head^2
Maksim Shabunin 7 years ago
commit 2ac57a2b1f
  1. 6
      cmake/OpenCVUtils.cmake
  2. 2
      doc/Doxyfile.in
  3. 6
      modules/calib3d/test/test_cameracalibration.cpp
  4. 4
      modules/core/CMakeLists.txt
  5. 25
      modules/core/include/opencv2/core/affine.hpp
  6. 2
      modules/core/include/opencv2/core/cvstd.inl.hpp
  7. 36
      modules/core/include/opencv2/core/eigen.hpp
  8. 9
      modules/core/include/opencv2/core/mat.hpp
  9. 251
      modules/core/include/opencv2/core/mat.inl.hpp
  10. 44
      modules/core/include/opencv2/core/matx.hpp
  11. 120
      modules/core/include/opencv2/core/persistence.hpp
  12. 71
      modules/core/include/opencv2/core/traits.hpp
  13. 137
      modules/core/include/opencv2/core/types.hpp
  14. 61
      modules/core/src/persistence.cpp
  15. 246
      modules/core/test/test_io.cpp
  16. 2
      modules/core/test/test_operations.cpp
  17. 8
      modules/cudaobjdetect/src/cascadeclassifier.cpp
  18. 22
      modules/dnn/include/opencv2/dnn/dnn.hpp
  19. 12
      modules/dnn/misc/java/src/cpp/dnn_converters.cpp
  20. 4
      modules/dnn/misc/java/src/cpp/dnn_converters.hpp
  21. 17
      modules/java/generator/src/cpp/listconverters.cpp
  22. 5
      modules/java/generator/src/cpp/listconverters.hpp
  23. 6
      modules/python/src2/cv2.cpp

@ -940,6 +940,12 @@ function(ocv_target_link_libraries target)
endif()
endfunction()
function(ocv_target_compile_definitions target)
_ocv_fix_target(target)
target_compile_definitions(${target} ${ARGN})
endfunction()
function(_ocv_append_target_includes target)
if(DEFINED OCV_TARGET_INCLUDE_DIRS_${target})
target_include_directories(${target} PRIVATE ${OCV_TARGET_INCLUDE_DIRS_${target}})

@ -107,7 +107,7 @@ RECURSIVE = YES
EXCLUDE =
EXCLUDE_SYMLINKS = NO
EXCLUDE_PATTERNS = *.inl.hpp *.impl.hpp *_detail.hpp */cudev/**/detail/*.hpp *.m
EXCLUDE_SYMBOLS = cv::DataType<*> int void
EXCLUDE_SYMBOLS = cv::DataType<*> cv::traits::* int void CV__*
EXAMPLE_PATH = @CMAKE_DOXYGEN_EXAMPLE_PATH@
EXAMPLE_PATTERNS = *
EXAMPLE_RECURSIVE = YES

@ -1911,9 +1911,9 @@ double CV_StereoCalibrationTest_C::calibrateStereoCamera( const vector<vector<Po
}
Mat npoints( 1, nimages, CV_32S ),
objPt( 1, total, DataType<Point3f>::type ),
imgPt( 1, total, DataType<Point2f>::type ),
imgPt2( 1, total, DataType<Point2f>::type );
objPt( 1, total, traits::Type<Point3f>::value ),
imgPt( 1, total, traits::Type<Point2f>::value ),
imgPt2( 1, total, traits::Type<Point2f>::value );
Point2f* imgPtData2 = imgPt2.ptr<Point2f>();
Point3f* objPtData = objPt.ptr<Point3f>();

@ -63,5 +63,9 @@ ocv_target_link_libraries(${the_module} LINK_PRIVATE
"${OPENCV_HAL_LINKER_LIBS}"
)
if(HAVE_CUDA)
ocv_target_compile_definitions(${the_module} PUBLIC OPENCV_TRAITS_ENABLE_DEPRECATED)
endif()
ocv_add_accuracy_tests()
ocv_add_perf_tests()

@ -153,15 +153,24 @@ namespace cv
typedef _Tp channel_type;
enum { generic_type = 0,
depth = DataType<channel_type>::depth,
channels = 16,
fmt = DataType<channel_type>::fmt + ((channels - 1) << 8),
type = CV_MAKETYPE(depth, channels)
fmt = traits::SafeFmt<channel_type>::fmt + ((channels - 1) << 8)
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
,depth = DataType<channel_type>::depth
,type = CV_MAKETYPE(depth, channels)
#endif
};
typedef Vec<channel_type, channels> vec_type;
};
namespace traits {
template<typename _Tp>
struct Depth< Affine3<_Tp> > { enum { value = Depth<_Tp>::value }; };
template<typename _Tp>
struct Type< Affine3<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 16) }; };
} // namespace
//! @} core
}
@ -202,7 +211,7 @@ cv::Affine3<T>::Affine3(const Vec3& _rvec, const Vec3& t)
template<typename T> inline
cv::Affine3<T>::Affine3(const cv::Mat& data, const Vec3& t)
{
CV_Assert(data.type() == cv::DataType<T>::type);
CV_Assert(data.type() == cv::traits::Type<T>::value);
if (data.cols == 4 && data.rows == 4)
{
@ -271,7 +280,7 @@ void cv::Affine3<T>::rotation(const Vec3& _rvec)
template<typename T> inline
void cv::Affine3<T>::rotation(const cv::Mat& data)
{
CV_Assert(data.type() == cv::DataType<T>::type);
CV_Assert(data.type() == cv::traits::Type<T>::value);
if (data.cols == 3 && data.rows == 3)
{
@ -485,21 +494,21 @@ cv::Vec3d cv::operator*(const cv::Affine3d& affine, const cv::Vec3d& v)
template<typename T> inline
cv::Affine3<T>::Affine3(const Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)>& affine)
{
cv::Mat(4, 4, cv::DataType<T>::type, affine.matrix().data()).copyTo(matrix);
cv::Mat(4, 4, cv::traits::Type<T>::value, affine.matrix().data()).copyTo(matrix);
}
template<typename T> inline
cv::Affine3<T>::Affine3(const Eigen::Transform<T, 3, Eigen::Affine>& affine)
{
Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)> a = affine;
cv::Mat(4, 4, cv::DataType<T>::type, a.matrix().data()).copyTo(matrix);
cv::Mat(4, 4, cv::traits::Type<T>::value, a.matrix().data()).copyTo(matrix);
}
template<typename T> inline
cv::Affine3<T>::operator Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)>() const
{
Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)> r;
cv::Mat hdr(4, 4, cv::DataType<T>::type, r.matrix().data());
cv::Mat hdr(4, 4, cv::traits::Type<T>::value, r.matrix().data());
cv::Mat(matrix, false).copyTo(hdr);
return r;
}

@ -233,7 +233,7 @@ template<typename _Tp, int n> static inline
std::ostream& operator << (std::ostream& out, const Vec<_Tp, n>& vec)
{
out << "[";
if(Vec<_Tp, n>::depth < CV_32F)
if (cv::traits::Depth<_Tp>::value <= CV_32S)
{
for (int i = 0; i < n - 1; ++i) {
out << (int)vec[i] << ", ";

@ -64,13 +64,13 @@ void eigen2cv( const Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCo
{
if( !(src.Flags & Eigen::RowMajorBit) )
{
Mat _src(src.cols(), src.rows(), DataType<_Tp>::type,
Mat _src(src.cols(), src.rows(), traits::Type<_Tp>::value,
(void*)src.data(), src.stride()*sizeof(_Tp));
transpose(_src, dst);
}
else
{
Mat _src(src.rows(), src.cols(), DataType<_Tp>::type,
Mat _src(src.rows(), src.cols(), traits::Type<_Tp>::value,
(void*)src.data(), src.stride()*sizeof(_Tp));
_src.copyTo(dst);
}
@ -98,7 +98,7 @@ void cv2eigen( const Mat& src,
CV_DbgAssert(src.rows == _rows && src.cols == _cols);
if( !(dst.Flags & Eigen::RowMajorBit) )
{
const Mat _dst(src.cols, src.rows, DataType<_Tp>::type,
const Mat _dst(src.cols, src.rows, traits::Type<_Tp>::value,
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
if( src.type() == _dst.type() )
transpose(src, _dst);
@ -112,7 +112,7 @@ void cv2eigen( const Mat& src,
}
else
{
const Mat _dst(src.rows, src.cols, DataType<_Tp>::type,
const Mat _dst(src.rows, src.cols, traits::Type<_Tp>::value,
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
src.convertTo(_dst, _dst.type());
}
@ -125,13 +125,13 @@ void cv2eigen( const Matx<_Tp, _rows, _cols>& src,
{
if( !(dst.Flags & Eigen::RowMajorBit) )
{
const Mat _dst(_cols, _rows, DataType<_Tp>::type,
const Mat _dst(_cols, _rows, traits::Type<_Tp>::value,
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
transpose(src, _dst);
}
else
{
const Mat _dst(_rows, _cols, DataType<_Tp>::type,
const Mat _dst(_rows, _cols, traits::Type<_Tp>::value,
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
Mat(src).copyTo(_dst);
}
@ -144,7 +144,7 @@ void cv2eigen( const Mat& src,
dst.resize(src.rows, src.cols);
if( !(dst.Flags & Eigen::RowMajorBit) )
{
const Mat _dst(src.cols, src.rows, DataType<_Tp>::type,
const Mat _dst(src.cols, src.rows, traits::Type<_Tp>::value,
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
if( src.type() == _dst.type() )
transpose(src, _dst);
@ -158,7 +158,7 @@ void cv2eigen( const Mat& src,
}
else
{
const Mat _dst(src.rows, src.cols, DataType<_Tp>::type,
const Mat _dst(src.rows, src.cols, traits::Type<_Tp>::value,
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
src.convertTo(_dst, _dst.type());
}
@ -172,13 +172,13 @@ void cv2eigen( const Matx<_Tp, _rows, _cols>& src,
dst.resize(_rows, _cols);
if( !(dst.Flags & Eigen::RowMajorBit) )
{
const Mat _dst(_cols, _rows, DataType<_Tp>::type,
const Mat _dst(_cols, _rows, traits::Type<_Tp>::value,
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
transpose(src, _dst);
}
else
{
const Mat _dst(_rows, _cols, DataType<_Tp>::type,
const Mat _dst(_rows, _cols, traits::Type<_Tp>::value,
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
Mat(src).copyTo(_dst);
}
@ -193,7 +193,7 @@ void cv2eigen( const Mat& src,
if( !(dst.Flags & Eigen::RowMajorBit) )
{
const Mat _dst(src.cols, src.rows, DataType<_Tp>::type,
const Mat _dst(src.cols, src.rows, traits::Type<_Tp>::value,
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
if( src.type() == _dst.type() )
transpose(src, _dst);
@ -202,7 +202,7 @@ void cv2eigen( const Mat& src,
}
else
{
const Mat _dst(src.rows, src.cols, DataType<_Tp>::type,
const Mat _dst(src.rows, src.cols, traits::Type<_Tp>::value,
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
src.convertTo(_dst, _dst.type());
}
@ -217,13 +217,13 @@ void cv2eigen( const Matx<_Tp, _rows, 1>& src,
if( !(dst.Flags & Eigen::RowMajorBit) )
{
const Mat _dst(1, _rows, DataType<_Tp>::type,
const Mat _dst(1, _rows, traits::Type<_Tp>::value,
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
transpose(src, _dst);
}
else
{
const Mat _dst(_rows, 1, DataType<_Tp>::type,
const Mat _dst(_rows, 1, traits::Type<_Tp>::value,
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
src.copyTo(_dst);
}
@ -238,7 +238,7 @@ void cv2eigen( const Mat& src,
dst.resize(src.cols);
if( !(dst.Flags & Eigen::RowMajorBit) )
{
const Mat _dst(src.cols, src.rows, DataType<_Tp>::type,
const Mat _dst(src.cols, src.rows, traits::Type<_Tp>::value,
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
if( src.type() == _dst.type() )
transpose(src, _dst);
@ -247,7 +247,7 @@ void cv2eigen( const Mat& src,
}
else
{
const Mat _dst(src.rows, src.cols, DataType<_Tp>::type,
const Mat _dst(src.rows, src.cols, traits::Type<_Tp>::value,
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
src.convertTo(_dst, _dst.type());
}
@ -261,13 +261,13 @@ void cv2eigen( const Matx<_Tp, 1, _cols>& src,
dst.resize(_cols);
if( !(dst.Flags & Eigen::RowMajorBit) )
{
const Mat _dst(_cols, 1, DataType<_Tp>::type,
const Mat _dst(_cols, 1, traits::Type<_Tp>::value,
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
transpose(src, _dst);
}
else
{
const Mat _dst(1, _cols, DataType<_Tp>::type,
const Mat _dst(1, _cols, traits::Type<_Tp>::value,
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
Mat(src).copyTo(_dst);
}

@ -1531,6 +1531,11 @@ public:
*/
template<typename _Tp> void push_back(const Mat_<_Tp>& elem);
/** @overload
@param elem Added element(s).
*/
template<typename _Tp> void push_back(const std::vector<_Tp>& elem);
/** @overload
@param m Added line(s).
*/
@ -1661,7 +1666,7 @@ public:
inv_scale = 1.f/alpha_scale;
CV_Assert( src1.type() == src2.type() &&
src1.type() == CV_MAKETYPE(DataType<T>::depth, 4) &&
src1.type() == CV_MAKETYPE(traits::Depth<T>::value, 4) &&
src1.size() == src2.size());
Size size = src1.size();
dst.create(size, src1.type());
@ -1941,7 +1946,7 @@ public:
inv_scale = 1.f/alpha_scale;
CV_Assert( src1.type() == src2.type() &&
src1.type() == DataType<VT>::type &&
src1.type() == traits::Type<VT>::value &&
src1.size() == src2.size());
Size size = src1.size();
dst.create(size, src1.type());

@ -82,12 +82,12 @@ inline _InputArray::_InputArray(const std::vector<UMat>& vec) { init(STD_VECTOR_
template<typename _Tp> inline
_InputArray::_InputArray(const std::vector<_Tp>& vec)
{ init(FIXED_TYPE + STD_VECTOR + DataType<_Tp>::type + ACCESS_READ, &vec); }
{ init(FIXED_TYPE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_READ, &vec); }
#ifdef CV_CXX_STD_ARRAY
template<typename _Tp, std::size_t _Nm> inline
_InputArray::_InputArray(const std::array<_Tp, _Nm>& arr)
{ init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + DataType<_Tp>::type + ACCESS_READ, arr.data(), Size(1, _Nm)); }
{ init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_READ, arr.data(), Size(1, _Nm)); }
template<std::size_t _Nm> inline
_InputArray::_InputArray(const std::array<Mat, _Nm>& arr)
@ -96,11 +96,11 @@ _InputArray::_InputArray(const std::array<Mat, _Nm>& arr)
inline
_InputArray::_InputArray(const std::vector<bool>& vec)
{ init(FIXED_TYPE + STD_BOOL_VECTOR + DataType<bool>::type + ACCESS_READ, &vec); }
{ init(FIXED_TYPE + STD_BOOL_VECTOR + traits::Type<bool>::value + 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); }
{ init(FIXED_TYPE + STD_VECTOR_VECTOR + traits::Type<_Tp>::value + ACCESS_READ, &vec); }
inline
_InputArray::_InputArray(const std::vector<std::vector<bool> >&)
@ -108,19 +108,19 @@ _InputArray::_InputArray(const std::vector<std::vector<bool> >&)
template<typename _Tp> inline
_InputArray::_InputArray(const std::vector<Mat_<_Tp> >& vec)
{ init(FIXED_TYPE + STD_VECTOR_MAT + DataType<_Tp>::type + ACCESS_READ, &vec); }
{ init(FIXED_TYPE + STD_VECTOR_MAT + traits::Type<_Tp>::value + ACCESS_READ, &vec); }
template<typename _Tp, int m, int n> inline
_InputArray::_InputArray(const Matx<_Tp, m, n>& mtx)
{ init(FIXED_TYPE + FIXED_SIZE + MATX + DataType<_Tp>::type + ACCESS_READ, &mtx, Size(n, m)); }
{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_READ, &mtx, Size(n, m)); }
template<typename _Tp> inline
_InputArray::_InputArray(const _Tp* vec, int n)
{ init(FIXED_TYPE + FIXED_SIZE + MATX + DataType<_Tp>::type + ACCESS_READ, vec, Size(n, 1)); }
{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_READ, vec, Size(n, 1)); }
template<typename _Tp> inline
_InputArray::_InputArray(const Mat_<_Tp>& m)
{ init(FIXED_TYPE + MAT + DataType<_Tp>::type + ACCESS_READ, &m); }
{ init(FIXED_TYPE + MAT + traits::Type<_Tp>::value + ACCESS_READ, &m); }
inline _InputArray::_InputArray(const double& val)
{ init(FIXED_TYPE + FIXED_SIZE + MATX + CV_64F + ACCESS_READ, &val, Size(1,1)); }
@ -170,12 +170,12 @@ inline _OutputArray::_OutputArray(std::vector<UMat>& vec) { init(STD_VECTOR_UMAT
template<typename _Tp> inline
_OutputArray::_OutputArray(std::vector<_Tp>& vec)
{ init(FIXED_TYPE + STD_VECTOR + DataType<_Tp>::type + ACCESS_WRITE, &vec); }
{ init(FIXED_TYPE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); }
#ifdef CV_CXX_STD_ARRAY
template<typename _Tp, std::size_t _Nm> inline
_OutputArray::_OutputArray(std::array<_Tp, _Nm>& arr)
{ init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + DataType<_Tp>::type + ACCESS_WRITE, arr.data(), Size(1, _Nm)); }
{ init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_WRITE, arr.data(), Size(1, _Nm)); }
template<std::size_t _Nm> inline
_OutputArray::_OutputArray(std::array<Mat, _Nm>& arr)
@ -188,7 +188,7 @@ _OutputArray::_OutputArray(std::vector<bool>&)
template<typename _Tp> inline
_OutputArray::_OutputArray(std::vector<std::vector<_Tp> >& vec)
{ init(FIXED_TYPE + STD_VECTOR_VECTOR + DataType<_Tp>::type + ACCESS_WRITE, &vec); }
{ init(FIXED_TYPE + STD_VECTOR_VECTOR + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); }
inline
_OutputArray::_OutputArray(std::vector<std::vector<bool> >&)
@ -196,28 +196,28 @@ _OutputArray::_OutputArray(std::vector<std::vector<bool> >&)
template<typename _Tp> inline
_OutputArray::_OutputArray(std::vector<Mat_<_Tp> >& vec)
{ init(FIXED_TYPE + STD_VECTOR_MAT + DataType<_Tp>::type + ACCESS_WRITE, &vec); }
{ init(FIXED_TYPE + STD_VECTOR_MAT + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); }
template<typename _Tp> inline
_OutputArray::_OutputArray(Mat_<_Tp>& m)
{ init(FIXED_TYPE + MAT + DataType<_Tp>::type + ACCESS_WRITE, &m); }
{ init(FIXED_TYPE + MAT + traits::Type<_Tp>::value + ACCESS_WRITE, &m); }
template<typename _Tp, int m, int n> inline
_OutputArray::_OutputArray(Matx<_Tp, m, n>& mtx)
{ init(FIXED_TYPE + FIXED_SIZE + MATX + DataType<_Tp>::type + ACCESS_WRITE, &mtx, Size(n, m)); }
{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_WRITE, &mtx, Size(n, m)); }
template<typename _Tp> inline
_OutputArray::_OutputArray(_Tp* vec, int n)
{ init(FIXED_TYPE + FIXED_SIZE + MATX + DataType<_Tp>::type + ACCESS_WRITE, vec, Size(n, 1)); }
{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_WRITE, vec, Size(n, 1)); }
template<typename _Tp> inline
_OutputArray::_OutputArray(const std::vector<_Tp>& vec)
{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR + DataType<_Tp>::type + ACCESS_WRITE, &vec); }
{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); }
#ifdef CV_CXX_STD_ARRAY
template<typename _Tp, std::size_t _Nm> inline
_OutputArray::_OutputArray(const std::array<_Tp, _Nm>& arr)
{ init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + DataType<_Tp>::type + ACCESS_WRITE, arr.data(), Size(1, _Nm)); }
{ init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_WRITE, arr.data(), Size(1, _Nm)); }
template<std::size_t _Nm> inline
_OutputArray::_OutputArray(const std::array<Mat, _Nm>& arr)
@ -226,23 +226,23 @@ _OutputArray::_OutputArray(const std::array<Mat, _Nm>& arr)
template<typename _Tp> inline
_OutputArray::_OutputArray(const std::vector<std::vector<_Tp> >& vec)
{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_VECTOR + DataType<_Tp>::type + ACCESS_WRITE, &vec); }
{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_VECTOR + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); }
template<typename _Tp> inline
_OutputArray::_OutputArray(const std::vector<Mat_<_Tp> >& vec)
{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_MAT + DataType<_Tp>::type + ACCESS_WRITE, &vec); }
{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_MAT + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); }
template<typename _Tp> inline
_OutputArray::_OutputArray(const Mat_<_Tp>& m)
{ init(FIXED_TYPE + FIXED_SIZE + MAT + DataType<_Tp>::type + ACCESS_WRITE, &m); }
{ init(FIXED_TYPE + FIXED_SIZE + MAT + traits::Type<_Tp>::value + ACCESS_WRITE, &m); }
template<typename _Tp, int m, int n> inline
_OutputArray::_OutputArray(const Matx<_Tp, m, n>& mtx)
{ init(FIXED_TYPE + FIXED_SIZE + MATX + DataType<_Tp>::type + ACCESS_WRITE, &mtx, Size(n, m)); }
{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_WRITE, &mtx, Size(n, m)); }
template<typename _Tp> inline
_OutputArray::_OutputArray(const _Tp* vec, int n)
{ init(FIXED_TYPE + FIXED_SIZE + MATX + DataType<_Tp>::type + ACCESS_WRITE, vec, Size(n, 1)); }
{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_WRITE, vec, Size(n, 1)); }
inline _OutputArray::_OutputArray(cuda::GpuMat& d_mat)
{ init(CUDA_GPU_MAT + ACCESS_WRITE, &d_mat); }
@ -289,12 +289,12 @@ inline _InputOutputArray::_InputOutputArray(std::vector<UMat>& vec) { init(STD_V
template<typename _Tp> inline
_InputOutputArray::_InputOutputArray(std::vector<_Tp>& vec)
{ init(FIXED_TYPE + STD_VECTOR + DataType<_Tp>::type + ACCESS_RW, &vec); }
{ init(FIXED_TYPE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_RW, &vec); }
#ifdef CV_CXX_STD_ARRAY
template<typename _Tp, std::size_t _Nm> inline
_InputOutputArray::_InputOutputArray(std::array<_Tp, _Nm>& arr)
{ init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + DataType<_Tp>::type + ACCESS_RW, arr.data(), Size(1, _Nm)); }
{ init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_RW, arr.data(), Size(1, _Nm)); }
template<std::size_t _Nm> inline
_InputOutputArray::_InputOutputArray(std::array<Mat, _Nm>& arr)
@ -306,32 +306,32 @@ inline _InputOutputArray::_InputOutputArray(std::vector<bool>&)
template<typename _Tp> inline
_InputOutputArray::_InputOutputArray(std::vector<std::vector<_Tp> >& vec)
{ init(FIXED_TYPE + STD_VECTOR_VECTOR + DataType<_Tp>::type + ACCESS_RW, &vec); }
{ init(FIXED_TYPE + STD_VECTOR_VECTOR + traits::Type<_Tp>::value + ACCESS_RW, &vec); }
template<typename _Tp> inline
_InputOutputArray::_InputOutputArray(std::vector<Mat_<_Tp> >& vec)
{ init(FIXED_TYPE + STD_VECTOR_MAT + DataType<_Tp>::type + ACCESS_RW, &vec); }
{ init(FIXED_TYPE + STD_VECTOR_MAT + traits::Type<_Tp>::value + ACCESS_RW, &vec); }
template<typename _Tp> inline
_InputOutputArray::_InputOutputArray(Mat_<_Tp>& m)
{ init(FIXED_TYPE + MAT + DataType<_Tp>::type + ACCESS_RW, &m); }
{ init(FIXED_TYPE + MAT + traits::Type<_Tp>::value + ACCESS_RW, &m); }
template<typename _Tp, int m, int n> inline
_InputOutputArray::_InputOutputArray(Matx<_Tp, m, n>& mtx)
{ init(FIXED_TYPE + FIXED_SIZE + MATX + DataType<_Tp>::type + ACCESS_RW, &mtx, Size(n, m)); }
{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_RW, &mtx, Size(n, m)); }
template<typename _Tp> inline
_InputOutputArray::_InputOutputArray(_Tp* vec, int n)
{ init(FIXED_TYPE + FIXED_SIZE + MATX + DataType<_Tp>::type + ACCESS_RW, vec, Size(n, 1)); }
{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_RW, vec, Size(n, 1)); }
template<typename _Tp> inline
_InputOutputArray::_InputOutputArray(const std::vector<_Tp>& vec)
{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR + DataType<_Tp>::type + ACCESS_RW, &vec); }
{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_RW, &vec); }
#ifdef CV_CXX_STD_ARRAY
template<typename _Tp, std::size_t _Nm> inline
_InputOutputArray::_InputOutputArray(const std::array<_Tp, _Nm>& arr)
{ init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + DataType<_Tp>::type + ACCESS_RW, arr.data(), Size(1, _Nm)); }
{ init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_RW, arr.data(), Size(1, _Nm)); }
template<std::size_t _Nm> inline
_InputOutputArray::_InputOutputArray(const std::array<Mat, _Nm>& arr)
@ -340,23 +340,23 @@ _InputOutputArray::_InputOutputArray(const std::array<Mat, _Nm>& arr)
template<typename _Tp> inline
_InputOutputArray::_InputOutputArray(const std::vector<std::vector<_Tp> >& vec)
{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_VECTOR + DataType<_Tp>::type + ACCESS_RW, &vec); }
{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_VECTOR + traits::Type<_Tp>::value + ACCESS_RW, &vec); }
template<typename _Tp> inline
_InputOutputArray::_InputOutputArray(const std::vector<Mat_<_Tp> >& vec)
{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_MAT + DataType<_Tp>::type + ACCESS_RW, &vec); }
{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_MAT + traits::Type<_Tp>::value + ACCESS_RW, &vec); }
template<typename _Tp> inline
_InputOutputArray::_InputOutputArray(const Mat_<_Tp>& m)
{ init(FIXED_TYPE + FIXED_SIZE + MAT + DataType<_Tp>::type + ACCESS_RW, &m); }
{ init(FIXED_TYPE + FIXED_SIZE + MAT + traits::Type<_Tp>::value + ACCESS_RW, &m); }
template<typename _Tp, int m, int n> inline
_InputOutputArray::_InputOutputArray(const Matx<_Tp, m, n>& mtx)
{ init(FIXED_TYPE + FIXED_SIZE + MATX + DataType<_Tp>::type + ACCESS_RW, &mtx, Size(n, m)); }
{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_RW, &mtx, Size(n, m)); }
template<typename _Tp> inline
_InputOutputArray::_InputOutputArray(const _Tp* vec, int n)
{ init(FIXED_TYPE + FIXED_SIZE + MATX + DataType<_Tp>::type + ACCESS_RW, vec, Size(n, 1)); }
{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_RW, vec, Size(n, 1)); }
inline _InputOutputArray::_InputOutputArray(cuda::GpuMat& d_mat)
{ init(CUDA_GPU_MAT + ACCESS_RW, &d_mat); }
@ -559,7 +559,7 @@ Mat::Mat(Size _sz, int _type, void* _data, size_t _step)
template<typename _Tp> inline
Mat::Mat(const std::vector<_Tp>& vec, bool copyData)
: flags(MAGIC_VAL | DataType<_Tp>::type | CV_MAT_CONT_FLAG), dims(2), rows((int)vec.size()),
: flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows((int)vec.size()),
cols(1), data(0), datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0)
{
if(vec.empty())
@ -571,25 +571,25 @@ Mat::Mat(const std::vector<_Tp>& vec, bool copyData)
datalimit = dataend = datastart + rows * step[0];
}
else
Mat((int)vec.size(), 1, DataType<_Tp>::type, (uchar*)&vec[0]).copyTo(*this);
Mat((int)vec.size(), 1, traits::Type<_Tp>::value, (uchar*)&vec[0]).copyTo(*this);
}
#ifdef CV_CXX11
template<typename _Tp, typename> inline
Mat::Mat(const std::initializer_list<_Tp> list)
: flags(MAGIC_VAL | DataType<_Tp>::type | CV_MAT_CONT_FLAG), dims(2), rows((int)list.size()),
: flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows((int)list.size()),
cols(1), data(0), datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0)
{
if(list.size() == 0)
return;
Mat((int)list.size(), 1, DataType<_Tp>::type, (uchar*)list.begin()).copyTo(*this);
Mat((int)list.size(), 1, traits::Type<_Tp>::value, (uchar*)list.begin()).copyTo(*this);
}
#endif
#ifdef CV_CXX_STD_ARRAY
template<typename _Tp, std::size_t _Nm> inline
Mat::Mat(const std::array<_Tp, _Nm>& arr, bool copyData)
: flags(MAGIC_VAL | DataType<_Tp>::type | CV_MAT_CONT_FLAG), dims(2), rows((int)arr.size()),
: flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows((int)arr.size()),
cols(1), data(0), datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0)
{
if(arr.empty())
@ -601,13 +601,13 @@ Mat::Mat(const std::array<_Tp, _Nm>& arr, bool copyData)
datalimit = dataend = datastart + rows * step[0];
}
else
Mat((int)arr.size(), 1, DataType<_Tp>::type, (uchar*)arr.data()).copyTo(*this);
Mat((int)arr.size(), 1, traits::Type<_Tp>::value, (uchar*)arr.data()).copyTo(*this);
}
#endif
template<typename _Tp, int n> inline
Mat::Mat(const Vec<_Tp, n>& vec, bool copyData)
: flags(MAGIC_VAL | DataType<_Tp>::type | CV_MAT_CONT_FLAG), dims(2), rows(n), cols(1), data(0),
: flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows(n), cols(1), data(0),
datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0)
{
if( !copyData )
@ -617,13 +617,13 @@ Mat::Mat(const Vec<_Tp, n>& vec, bool copyData)
datalimit = dataend = datastart + rows * step[0];
}
else
Mat(n, 1, DataType<_Tp>::type, (void*)vec.val).copyTo(*this);
Mat(n, 1, traits::Type<_Tp>::value, (void*)vec.val).copyTo(*this);
}
template<typename _Tp, int m, int n> inline
Mat::Mat(const Matx<_Tp,m,n>& M, bool copyData)
: flags(MAGIC_VAL | DataType<_Tp>::type | CV_MAT_CONT_FLAG), dims(2), rows(m), cols(n), data(0),
: flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows(m), cols(n), data(0),
datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0)
{
if( !copyData )
@ -634,12 +634,12 @@ Mat::Mat(const Matx<_Tp,m,n>& M, bool copyData)
datalimit = dataend = datastart + rows * step[0];
}
else
Mat(m, n, DataType<_Tp>::type, (uchar*)M.val).copyTo(*this);
Mat(m, n, traits::Type<_Tp>::value, (uchar*)M.val).copyTo(*this);
}
template<typename _Tp> inline
Mat::Mat(const Point_<_Tp>& pt, bool copyData)
: flags(MAGIC_VAL | DataType<_Tp>::type | CV_MAT_CONT_FLAG), dims(2), rows(2), cols(1), data(0),
: flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows(2), cols(1), data(0),
datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0)
{
if( !copyData )
@ -650,7 +650,7 @@ Mat::Mat(const Point_<_Tp>& pt, bool copyData)
}
else
{
create(2, 1, DataType<_Tp>::type);
create(2, 1, traits::Type<_Tp>::value);
((_Tp*)data)[0] = pt.x;
((_Tp*)data)[1] = pt.y;
}
@ -658,7 +658,7 @@ Mat::Mat(const Point_<_Tp>& pt, bool copyData)
template<typename _Tp> inline
Mat::Mat(const Point3_<_Tp>& pt, bool copyData)
: flags(MAGIC_VAL | DataType<_Tp>::type | CV_MAT_CONT_FLAG), dims(2), rows(3), cols(1), data(0),
: flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows(3), cols(1), data(0),
datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0)
{
if( !copyData )
@ -669,7 +669,7 @@ Mat::Mat(const Point3_<_Tp>& pt, bool copyData)
}
else
{
create(3, 1, DataType<_Tp>::type);
create(3, 1, traits::Type<_Tp>::value);
((_Tp*)data)[0] = pt.x;
((_Tp*)data)[1] = pt.y;
((_Tp*)data)[2] = pt.z;
@ -678,7 +678,7 @@ Mat::Mat(const Point3_<_Tp>& pt, bool copyData)
template<typename _Tp> inline
Mat::Mat(const MatCommaInitializer_<_Tp>& commaInitializer)
: flags(MAGIC_VAL | DataType<_Tp>::type | CV_MAT_CONT_FLAG), dims(0), rows(0), cols(0), data(0),
: flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(0), rows(0), cols(0), data(0),
datastart(0), dataend(0), allocator(0), u(0), size(&rows)
{
*this = commaInitializer.operator Mat_<_Tp>();
@ -1065,7 +1065,7 @@ _Tp& Mat::at(int i0, int i1)
CV_DbgAssert(data);
CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
CV_DbgAssert((unsigned)(i1 * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels()));
CV_DbgAssert(CV_ELEM_SIZE1(DataType<_Tp>::depth) == elemSize1());
CV_DbgAssert(CV_ELEM_SIZE1(traits::Depth<_Tp>::value) == elemSize1());
return ((_Tp*)(data + step.p[0] * i0))[i1];
}
@ -1076,7 +1076,7 @@ const _Tp& Mat::at(int i0, int i1) const
CV_DbgAssert(data);
CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
CV_DbgAssert((unsigned)(i1 * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels()));
CV_DbgAssert(CV_ELEM_SIZE1(DataType<_Tp>::depth) == elemSize1());
CV_DbgAssert(CV_ELEM_SIZE1(traits::Depth<_Tp>::value) == elemSize1());
return ((const _Tp*)(data + step.p[0] * i0))[i1];
}
@ -1087,7 +1087,7 @@ _Tp& Mat::at(Point pt)
CV_DbgAssert(data);
CV_DbgAssert((unsigned)pt.y < (unsigned)size.p[0]);
CV_DbgAssert((unsigned)(pt.x * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels()));
CV_DbgAssert(CV_ELEM_SIZE1(DataType<_Tp>::depth) == elemSize1());
CV_DbgAssert(CV_ELEM_SIZE1(traits::Depth<_Tp>::value) == elemSize1());
return ((_Tp*)(data + step.p[0] * pt.y))[pt.x];
}
@ -1098,7 +1098,7 @@ const _Tp& Mat::at(Point pt) const
CV_DbgAssert(data);
CV_DbgAssert((unsigned)pt.y < (unsigned)size.p[0]);
CV_DbgAssert((unsigned)(pt.x * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels()));
CV_DbgAssert(CV_ELEM_SIZE1(DataType<_Tp>::depth) == elemSize1());
CV_DbgAssert(CV_ELEM_SIZE1(traits::Depth<_Tp>::value) == elemSize1());
return ((const _Tp*)(data + step.p[0] * pt.y))[pt.x];
}
@ -1108,7 +1108,7 @@ _Tp& Mat::at(int i0)
CV_DbgAssert(dims <= 2);
CV_DbgAssert(data);
CV_DbgAssert((unsigned)i0 < (unsigned)(size.p[0] * size.p[1]));
CV_DbgAssert(elemSize() == CV_ELEM_SIZE(DataType<_Tp>::type));
CV_DbgAssert(elemSize() == sizeof(_Tp));
if( isContinuous() || size.p[0] == 1 )
return ((_Tp*)data)[i0];
if( size.p[1] == 1 )
@ -1123,7 +1123,7 @@ const _Tp& Mat::at(int i0) const
CV_DbgAssert(dims <= 2);
CV_DbgAssert(data);
CV_DbgAssert((unsigned)i0 < (unsigned)(size.p[0] * size.p[1]));
CV_DbgAssert(elemSize() == CV_ELEM_SIZE(DataType<_Tp>::type));
CV_DbgAssert(elemSize() == sizeof(_Tp));
if( isContinuous() || size.p[0] == 1 )
return ((const _Tp*)data)[i0];
if( size.p[1] == 1 )
@ -1135,42 +1135,42 @@ const _Tp& Mat::at(int i0) const
template<typename _Tp> inline
_Tp& Mat::at(int i0, int i1, int i2)
{
CV_DbgAssert( elemSize() == CV_ELEM_SIZE(DataType<_Tp>::type) );
CV_DbgAssert( elemSize() == sizeof(_Tp) );
return *(_Tp*)ptr(i0, i1, i2);
}
template<typename _Tp> inline
const _Tp& Mat::at(int i0, int i1, int i2) const
{
CV_DbgAssert( elemSize() == CV_ELEM_SIZE(DataType<_Tp>::type) );
CV_DbgAssert( elemSize() == sizeof(_Tp) );
return *(const _Tp*)ptr(i0, i1, i2);
}
template<typename _Tp> inline
_Tp& Mat::at(const int* idx)
{
CV_DbgAssert( elemSize() == CV_ELEM_SIZE(DataType<_Tp>::type) );
CV_DbgAssert( elemSize() == sizeof(_Tp) );
return *(_Tp*)ptr(idx);
}
template<typename _Tp> inline
const _Tp& Mat::at(const int* idx) const
{
CV_DbgAssert( elemSize() == CV_ELEM_SIZE(DataType<_Tp>::type) );
CV_DbgAssert( elemSize() == sizeof(_Tp) );
return *(const _Tp*)ptr(idx);
}
template<typename _Tp, int n> inline
_Tp& Mat::at(const Vec<int, n>& idx)
{
CV_DbgAssert( elemSize() == CV_ELEM_SIZE(DataType<_Tp>::type) );
CV_DbgAssert( elemSize() == sizeof(_Tp) );
return *(_Tp*)ptr(idx.val);
}
template<typename _Tp, int n> inline
const _Tp& Mat::at(const Vec<int, n>& idx) const
{
CV_DbgAssert( elemSize() == CV_ELEM_SIZE(DataType<_Tp>::type) );
CV_DbgAssert( elemSize() == sizeof(_Tp) );
return *(const _Tp*)ptr(idx.val);
}
@ -1241,10 +1241,10 @@ Mat::operator Vec<_Tp, n>() const
CV_Assert( data && dims <= 2 && (rows == 1 || cols == 1) &&
rows + cols - 1 == n && channels() == 1 );
if( isContinuous() && type() == DataType<_Tp>::type )
if( isContinuous() && type() == traits::Type<_Tp>::value )
return Vec<_Tp, n>((_Tp*)data);
Vec<_Tp, n> v;
Mat tmp(rows, cols, DataType<_Tp>::type, v.val);
Mat tmp(rows, cols, traits::Type<_Tp>::value, v.val);
convertTo(tmp, tmp.type());
return v;
}
@ -1254,10 +1254,10 @@ Mat::operator Matx<_Tp, m, n>() const
{
CV_Assert( data && dims <= 2 && rows == m && cols == n && channels() == 1 );
if( isContinuous() && type() == DataType<_Tp>::type )
if( isContinuous() && type() == traits::Type<_Tp>::value )
return Matx<_Tp, m, n>((_Tp*)data);
Matx<_Tp, m, n> mtx;
Mat tmp(rows, cols, DataType<_Tp>::type, mtx.val);
Mat tmp(rows, cols, traits::Type<_Tp>::value, mtx.val);
convertTo(tmp, tmp.type());
return mtx;
}
@ -1267,10 +1267,10 @@ void Mat::push_back(const _Tp& elem)
{
if( !data )
{
*this = Mat(1, 1, DataType<_Tp>::type, (void*)&elem).clone();
*this = Mat(1, 1, traits::Type<_Tp>::value, (void*)&elem).clone();
return;
}
CV_Assert(DataType<_Tp>::type == type() && cols == 1
CV_Assert(traits::Type<_Tp>::value == type() && cols == 1
/* && dims == 2 (cols == 1 implies dims == 2) */);
const uchar* tmp = dataend + step[0];
if( !isSubmatrix() && isContinuous() && tmp <= datalimit )
@ -1294,6 +1294,13 @@ void Mat::push_back(const MatExpr& expr)
push_back(static_cast<Mat>(expr));
}
template<typename _Tp> inline
void Mat::push_back(const std::vector<_Tp>& v)
{
push_back(Mat(v));
}
#ifdef CV_CXX_MOVE_SEMANTICS
inline
@ -1462,47 +1469,47 @@ template<typename _Tp> inline
Mat_<_Tp>::Mat_()
: Mat()
{
flags = (flags & ~CV_MAT_TYPE_MASK) | DataType<_Tp>::type;
flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value;
}
template<typename _Tp> inline
Mat_<_Tp>::Mat_(int _rows, int _cols)
: Mat(_rows, _cols, DataType<_Tp>::type)
: Mat(_rows, _cols, traits::Type<_Tp>::value)
{
}
template<typename _Tp> inline
Mat_<_Tp>::Mat_(int _rows, int _cols, const _Tp& value)
: Mat(_rows, _cols, DataType<_Tp>::type)
: Mat(_rows, _cols, traits::Type<_Tp>::value)
{
*this = value;
}
template<typename _Tp> inline
Mat_<_Tp>::Mat_(Size _sz)
: Mat(_sz.height, _sz.width, DataType<_Tp>::type)
: Mat(_sz.height, _sz.width, traits::Type<_Tp>::value)
{}
template<typename _Tp> inline
Mat_<_Tp>::Mat_(Size _sz, const _Tp& value)
: Mat(_sz.height, _sz.width, DataType<_Tp>::type)
: Mat(_sz.height, _sz.width, traits::Type<_Tp>::value)
{
*this = value;
}
template<typename _Tp> inline
Mat_<_Tp>::Mat_(int _dims, const int* _sz)
: Mat(_dims, _sz, DataType<_Tp>::type)
: Mat(_dims, _sz, traits::Type<_Tp>::value)
{}
template<typename _Tp> inline
Mat_<_Tp>::Mat_(int _dims, const int* _sz, const _Tp& _s)
: Mat(_dims, _sz, DataType<_Tp>::type, Scalar(_s))
: Mat(_dims, _sz, traits::Type<_Tp>::value, Scalar(_s))
{}
template<typename _Tp> inline
Mat_<_Tp>::Mat_(int _dims, const int* _sz, _Tp* _data, const size_t* _steps)
: Mat(_dims, _sz, DataType<_Tp>::type, _data, _steps)
: Mat(_dims, _sz, traits::Type<_Tp>::value, _data, _steps)
{}
template<typename _Tp> inline
@ -1519,7 +1526,7 @@ template<typename _Tp> inline
Mat_<_Tp>::Mat_(const Mat& m)
: Mat()
{
flags = (flags & ~CV_MAT_TYPE_MASK) | DataType<_Tp>::type;
flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value;
*this = m;
}
@ -1530,7 +1537,7 @@ Mat_<_Tp>::Mat_(const Mat_& m)
template<typename _Tp> inline
Mat_<_Tp>::Mat_(int _rows, int _cols, _Tp* _data, size_t steps)
: Mat(_rows, _cols, DataType<_Tp>::type, _data, steps)
: Mat(_rows, _cols, traits::Type<_Tp>::value, _data, steps)
{}
template<typename _Tp> inline
@ -1545,7 +1552,7 @@ Mat_<_Tp>::Mat_(const Mat_& m, const Rect& roi)
template<typename _Tp> template<int n> inline
Mat_<_Tp>::Mat_(const Vec<typename DataType<_Tp>::channel_type, n>& vec, bool copyData)
: Mat(n / DataType<_Tp>::channels, 1, DataType<_Tp>::type, (void*)&vec)
: Mat(n / DataType<_Tp>::channels, 1, traits::Type<_Tp>::value, (void*)&vec)
{
CV_Assert(n%DataType<_Tp>::channels == 0);
if( copyData )
@ -1554,7 +1561,7 @@ Mat_<_Tp>::Mat_(const Vec<typename DataType<_Tp>::channel_type, n>& vec, bool co
template<typename _Tp> template<int m, int n> inline
Mat_<_Tp>::Mat_(const Matx<typename DataType<_Tp>::channel_type, m, n>& M, bool copyData)
: Mat(m, n / DataType<_Tp>::channels, DataType<_Tp>::type, (void*)&M)
: Mat(m, n / DataType<_Tp>::channels, traits::Type<_Tp>::value, (void*)&M)
{
CV_Assert(n % DataType<_Tp>::channels == 0);
if( copyData )
@ -1563,7 +1570,7 @@ Mat_<_Tp>::Mat_(const Matx<typename DataType<_Tp>::channel_type, m, n>& M, bool
template<typename _Tp> inline
Mat_<_Tp>::Mat_(const Point_<typename DataType<_Tp>::channel_type>& pt, bool copyData)
: Mat(2 / DataType<_Tp>::channels, 1, DataType<_Tp>::type, (void*)&pt)
: Mat(2 / DataType<_Tp>::channels, 1, traits::Type<_Tp>::value, (void*)&pt)
{
CV_Assert(2 % DataType<_Tp>::channels == 0);
if( copyData )
@ -1572,7 +1579,7 @@ Mat_<_Tp>::Mat_(const Point_<typename DataType<_Tp>::channel_type>& pt, bool cop
template<typename _Tp> inline
Mat_<_Tp>::Mat_(const Point3_<typename DataType<_Tp>::channel_type>& pt, bool copyData)
: Mat(3 / DataType<_Tp>::channels, 1, DataType<_Tp>::type, (void*)&pt)
: Mat(3 / DataType<_Tp>::channels, 1, traits::Type<_Tp>::value, (void*)&pt)
{
CV_Assert(3 % DataType<_Tp>::channels == 0);
if( copyData )
@ -1606,12 +1613,12 @@ Mat_<_Tp>::Mat_(const std::array<_Tp, _Nm>& arr, bool copyData)
template<typename _Tp> inline
Mat_<_Tp>& Mat_<_Tp>::operator = (const Mat& m)
{
if( DataType<_Tp>::type == m.type() )
if( traits::Type<_Tp>::value == m.type() )
{
Mat::operator = (m);
return *this;
}
if( DataType<_Tp>::depth == m.depth() )
if( traits::Depth<_Tp>::value == m.depth() )
{
return (*this = m.reshape(DataType<_Tp>::channels, m.dims, 0));
}
@ -1638,19 +1645,19 @@ Mat_<_Tp>& Mat_<_Tp>::operator = (const _Tp& s)
template<typename _Tp> inline
void Mat_<_Tp>::create(int _rows, int _cols)
{
Mat::create(_rows, _cols, DataType<_Tp>::type);
Mat::create(_rows, _cols, traits::Type<_Tp>::value);
}
template<typename _Tp> inline
void Mat_<_Tp>::create(Size _sz)
{
Mat::create(_sz, DataType<_Tp>::type);
Mat::create(_sz, traits::Type<_Tp>::value);
}
template<typename _Tp> inline
void Mat_<_Tp>::create(int _dims, const int* _sz)
{
Mat::create(_dims, _sz, DataType<_Tp>::type);
Mat::create(_dims, _sz, traits::Type<_Tp>::value);
}
template<typename _Tp> inline
@ -1658,7 +1665,7 @@ void Mat_<_Tp>::release()
{
Mat::release();
#ifdef _DEBUG
flags = (flags & ~CV_MAT_TYPE_MASK) | DataType<_Tp>::type;
flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value;
#endif
}
@ -1715,15 +1722,15 @@ size_t Mat_<_Tp>::elemSize1() const
template<typename _Tp> inline
int Mat_<_Tp>::type() const
{
CV_DbgAssert( Mat::type() == DataType<_Tp>::type );
return DataType<_Tp>::type;
CV_DbgAssert( Mat::type() == traits::Type<_Tp>::value );
return traits::Type<_Tp>::value;
}
template<typename _Tp> inline
int Mat_<_Tp>::depth() const
{
CV_DbgAssert( Mat::depth() == DataType<_Tp>::depth );
return DataType<_Tp>::depth;
CV_DbgAssert( Mat::depth() == traits::Depth<_Tp>::value );
return traits::Depth<_Tp>::value;
}
template<typename _Tp> inline
@ -1796,7 +1803,7 @@ _Tp& Mat_<_Tp>::operator ()(int i0, int i1)
CV_DbgAssert(data);
CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]);
CV_DbgAssert(type() == DataType<_Tp>::type);
CV_DbgAssert(type() == traits::Type<_Tp>::value);
return ((_Tp*)(data + step.p[0] * i0))[i1];
}
@ -1807,7 +1814,7 @@ const _Tp& Mat_<_Tp>::operator ()(int i0, int i1) const
CV_DbgAssert(data);
CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]);
CV_DbgAssert(type() == DataType<_Tp>::type);
CV_DbgAssert(type() == traits::Type<_Tp>::value);
return ((const _Tp*)(data + step.p[0] * i0))[i1];
}
@ -1818,7 +1825,7 @@ _Tp& Mat_<_Tp>::operator ()(Point pt)
CV_DbgAssert(data);
CV_DbgAssert((unsigned)pt.y < (unsigned)size.p[0]);
CV_DbgAssert((unsigned)pt.x < (unsigned)size.p[1]);
CV_DbgAssert(type() == DataType<_Tp>::type);
CV_DbgAssert(type() == traits::Type<_Tp>::value);
return ((_Tp*)(data + step.p[0] * pt.y))[pt.x];
}
@ -1829,7 +1836,7 @@ const _Tp& Mat_<_Tp>::operator ()(Point pt) const
CV_DbgAssert(data);
CV_DbgAssert((unsigned)pt.y < (unsigned)size.p[0]);
CV_DbgAssert((unsigned)pt.x < (unsigned)size.p[1]);
CV_DbgAssert(type() == DataType<_Tp>::type);
CV_DbgAssert(type() == traits::Type<_Tp>::value);
return ((const _Tp*)(data + step.p[0] * pt.y))[pt.x];
}
@ -1980,19 +1987,19 @@ template<typename _Tp> inline
Mat_<_Tp>::Mat_(Mat&& m)
: Mat()
{
flags = (flags & ~CV_MAT_TYPE_MASK) | DataType<_Tp>::type;
flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value;
*this = m;
}
template<typename _Tp> inline
Mat_<_Tp>& Mat_<_Tp>::operator = (Mat&& m)
{
if( DataType<_Tp>::type == m.type() )
if( traits::Type<_Tp>::value == m.type() )
{
Mat::operator = ((Mat&&)m);
return *this;
}
if( DataType<_Tp>::depth == m.depth() )
if( traits::Depth<_Tp>::value == m.depth() )
{
Mat::operator = ((Mat&&)m.reshape(DataType<_Tp>::channels, m.dims, 0));
return *this;
@ -2006,7 +2013,7 @@ template<typename _Tp> inline
Mat_<_Tp>::Mat_(MatExpr&& e)
: Mat()
{
flags = (flags & ~CV_MAT_TYPE_MASK) | DataType<_Tp>::type;
flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value;
*this = Mat(e);
}
@ -2343,21 +2350,21 @@ SparseMatConstIterator_<_Tp> SparseMat::end() const
template<typename _Tp> inline
SparseMat_<_Tp>::SparseMat_()
{
flags = MAGIC_VAL | DataType<_Tp>::type;
flags = MAGIC_VAL | traits::Type<_Tp>::value;
}
template<typename _Tp> inline
SparseMat_<_Tp>::SparseMat_(int _dims, const int* _sizes)
: SparseMat(_dims, _sizes, DataType<_Tp>::type)
: SparseMat(_dims, _sizes, traits::Type<_Tp>::value)
{}
template<typename _Tp> inline
SparseMat_<_Tp>::SparseMat_(const SparseMat& m)
{
if( m.type() == DataType<_Tp>::type )
if( m.type() == traits::Type<_Tp>::value )
*this = (const SparseMat_<_Tp>&)m;
else
m.convertTo(*this, DataType<_Tp>::type);
m.convertTo(*this, traits::Type<_Tp>::value);
}
template<typename _Tp> inline
@ -2392,9 +2399,9 @@ SparseMat_<_Tp>& SparseMat_<_Tp>::operator = (const SparseMat_<_Tp>& m)
template<typename _Tp> inline
SparseMat_<_Tp>& SparseMat_<_Tp>::operator = (const SparseMat& m)
{
if( m.type() == DataType<_Tp>::type )
if( m.type() == traits::Type<_Tp>::value )
return (*this = (const SparseMat_<_Tp>&)m);
m.convertTo(*this, DataType<_Tp>::type);
m.convertTo(*this, traits::Type<_Tp>::value);
return *this;
}
@ -2415,19 +2422,19 @@ SparseMat_<_Tp> SparseMat_<_Tp>::clone() const
template<typename _Tp> inline
void SparseMat_<_Tp>::create(int _dims, const int* _sizes)
{
SparseMat::create(_dims, _sizes, DataType<_Tp>::type);
SparseMat::create(_dims, _sizes, traits::Type<_Tp>::value);
}
template<typename _Tp> inline
int SparseMat_<_Tp>::type() const
{
return DataType<_Tp>::type;
return traits::Type<_Tp>::value;
}
template<typename _Tp> inline
int SparseMat_<_Tp>::depth() const
{
return DataType<_Tp>::depth;
return traits::Depth<_Tp>::value;
}
template<typename _Tp> inline
@ -3128,7 +3135,7 @@ template<typename _Tp> inline
SparseMatConstIterator_<_Tp>::SparseMatConstIterator_(const SparseMat* _m)
: SparseMatConstIterator(_m)
{
CV_Assert( _m->type() == DataType<_Tp>::type );
CV_Assert( _m->type() == traits::Type<_Tp>::value );
}
template<typename _Tp> inline
@ -3264,50 +3271,50 @@ Mat& Mat::operator = (const MatExpr& e)
template<typename _Tp> inline
Mat_<_Tp>::Mat_(const MatExpr& e)
{
e.op->assign(e, *this, DataType<_Tp>::type);
e.op->assign(e, *this, traits::Type<_Tp>::value);
}
template<typename _Tp> inline
Mat_<_Tp>& Mat_<_Tp>::operator = (const MatExpr& e)
{
e.op->assign(e, *this, DataType<_Tp>::type);
e.op->assign(e, *this, traits::Type<_Tp>::value);
return *this;
}
template<typename _Tp> inline
MatExpr Mat_<_Tp>::zeros(int rows, int cols)
{
return Mat::zeros(rows, cols, DataType<_Tp>::type);
return Mat::zeros(rows, cols, traits::Type<_Tp>::value);
}
template<typename _Tp> inline
MatExpr Mat_<_Tp>::zeros(Size sz)
{
return Mat::zeros(sz, DataType<_Tp>::type);
return Mat::zeros(sz, traits::Type<_Tp>::value);
}
template<typename _Tp> inline
MatExpr Mat_<_Tp>::ones(int rows, int cols)
{
return Mat::ones(rows, cols, DataType<_Tp>::type);
return Mat::ones(rows, cols, traits::Type<_Tp>::value);
}
template<typename _Tp> inline
MatExpr Mat_<_Tp>::ones(Size sz)
{
return Mat::ones(sz, DataType<_Tp>::type);
return Mat::ones(sz, traits::Type<_Tp>::value);
}
template<typename _Tp> inline
MatExpr Mat_<_Tp>::eye(int rows, int cols)
{
return Mat::eye(rows, cols, DataType<_Tp>::type);
return Mat::eye(rows, cols, traits::Type<_Tp>::value);
}
template<typename _Tp> inline
MatExpr Mat_<_Tp>::eye(Size sz)
{
return Mat::eye(sz, DataType<_Tp>::type);
return Mat::eye(sz, traits::Type<_Tp>::value);
}
inline
@ -3333,7 +3340,7 @@ template<typename _Tp> inline
MatExpr::operator Mat_<_Tp>() const
{
Mat_<_Tp> m;
op->assign(*this, m, DataType<_Tp>::type);
op->assign(*this, m, traits::Type<_Tp>::value);
return m;
}
@ -3566,7 +3573,7 @@ UMat::UMat(const UMat& m)
template<typename _Tp> inline
UMat::UMat(const std::vector<_Tp>& vec, bool copyData)
: flags(MAGIC_VAL | DataType<_Tp>::type | CV_MAT_CONT_FLAG), dims(2), rows((int)vec.size()),
: flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows((int)vec.size()),
cols(1), allocator(0), usageFlags(USAGE_DEFAULT), u(0), offset(0), size(&rows)
{
if(vec.empty())
@ -3577,7 +3584,7 @@ cols(1), allocator(0), usageFlags(USAGE_DEFAULT), u(0), offset(0), size(&rows)
CV_Error(Error::StsNotImplemented, "");
}
else
Mat((int)vec.size(), 1, DataType<_Tp>::type, (uchar*)&vec[0]).copyTo(*this);
Mat((int)vec.size(), 1, traits::Type<_Tp>::value, (uchar*)&vec[0]).copyTo(*this);
}
inline

@ -100,11 +100,14 @@ In case if C++11 features are avaliable, std::initializer_list can be also used
template<typename _Tp, int m, int n> class Matx
{
public:
enum { depth = DataType<_Tp>::depth,
enum {
rows = m,
cols = n,
channels = rows*cols,
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
depth = traits::Type<_Tp>::value,
type = CV_MAKETYPE(depth, channels),
#endif
shortdim = (m < n ? m : n)
};
@ -259,13 +262,23 @@ public:
typedef value_type vec_type;
enum { generic_type = 0,
depth = DataType<channel_type>::depth,
channels = m * n,
fmt = DataType<channel_type>::fmt + ((channels - 1) << 8),
type = CV_MAKETYPE(depth, channels)
fmt = traits::SafeFmt<channel_type>::fmt + ((channels - 1) << 8)
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
,depth = DataType<channel_type>::depth
,type = CV_MAKETYPE(depth, channels)
#endif
};
};
namespace traits {
template<typename _Tp, int m, int n>
struct Depth< Matx<_Tp, m, n> > { enum { value = Depth<_Tp>::value }; };
template<typename _Tp, int m, int n>
struct Type< Matx<_Tp, m, n> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, n*m) }; };
} // namespace
/** @brief Comma-separated Matrix Initializer
*/
template<typename _Tp, int m, int n> class MatxCommaInitializer
@ -323,9 +336,13 @@ template<typename _Tp, int cn> class Vec : public Matx<_Tp, cn, 1>
{
public:
typedef _Tp value_type;
enum { depth = Matx<_Tp, cn, 1>::depth,
enum {
channels = cn,
type = CV_MAKETYPE(depth, channels)
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
depth = Matx<_Tp, cn, 1>::depth,
type = CV_MAKETYPE(depth, channels),
#endif
_dummy_enum_finalizer = 0
};
//! default constructor
@ -422,13 +439,24 @@ public:
typedef value_type vec_type;
enum { generic_type = 0,
depth = DataType<channel_type>::depth,
channels = cn,
fmt = DataType<channel_type>::fmt + ((channels - 1) << 8),
type = CV_MAKETYPE(depth, channels)
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
depth = DataType<channel_type>::depth,
type = CV_MAKETYPE(depth, channels),
#endif
_dummy_enum_finalizer = 0
};
};
namespace traits {
template<typename _Tp, int cn>
struct Depth< Vec<_Tp, cn> > { enum { value = Depth<_Tp>::value }; };
template<typename _Tp, int cn>
struct Type< Vec<_Tp, cn> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, cn) }; };
} // namespace
/** @brief Comma-separated Vec Initializer
*/
template<typename _Tp, int m> class VecCommaInitializer : public MatxCommaInitializer<_Tp, m, 1>

@ -44,6 +44,11 @@
#ifndef OPENCV_CORE_PERSISTENCE_HPP
#define OPENCV_CORE_PERSISTENCE_HPP
#ifndef CV_DOXYGEN
/// Define to support persistence legacy formats
#define CV__LEGACY_PERSISTENCE
#endif
#ifndef __cplusplus
# error persistence.hpp header must be compiled as C++
#endif
@ -700,8 +705,10 @@ CV_EXPORTS void write( FileStorage& fs, const String& name, double value );
CV_EXPORTS void write( FileStorage& fs, const String& name, const String& value );
CV_EXPORTS void write( FileStorage& fs, const String& name, const Mat& value );
CV_EXPORTS void write( FileStorage& fs, const String& name, const SparseMat& value );
#ifdef CV__LEGACY_PERSISTENCE
CV_EXPORTS void write( FileStorage& fs, const String& name, const std::vector<KeyPoint>& value);
CV_EXPORTS void write( FileStorage& fs, const String& name, const std::vector<DMatch>& value);
#endif
CV_EXPORTS void writeScalar( FileStorage& fs, int value );
CV_EXPORTS void writeScalar( FileStorage& fs, float value );
@ -720,8 +727,12 @@ CV_EXPORTS void read(const FileNode& node, String& value, const String& default_
CV_EXPORTS void read(const FileNode& node, std::string& value, const std::string& default_value);
CV_EXPORTS void read(const FileNode& node, Mat& mat, const Mat& default_mat = Mat() );
CV_EXPORTS void read(const FileNode& node, SparseMat& mat, const SparseMat& default_mat = SparseMat() );
#ifdef CV__LEGACY_PERSISTENCE
CV_EXPORTS void read(const FileNode& node, std::vector<KeyPoint>& keypoints);
CV_EXPORTS void read(const FileNode& node, std::vector<DMatch>& matches);
#endif
CV_EXPORTS void read(const FileNode& node, KeyPoint& value, const KeyPoint& default_value);
CV_EXPORTS void read(const FileNode& node, DMatch& value, const DMatch& default_value);
template<typename _Tp> static inline void read(const FileNode& node, Point_<_Tp>& value, const Point_<_Tp>& default_value)
{
@ -815,7 +826,7 @@ namespace internal
VecWriterProxy( FileStorage* _fs ) : fs(_fs) {}
void operator()(const std::vector<_Tp>& vec) const
{
int _fmt = DataType<_Tp>::fmt;
int _fmt = traits::SafeFmt<_Tp>::fmt;
char fmt[] = { (char)((_fmt >> 8) + '1'), (char)_fmt, '\0' };
fs->writeRaw(fmt, !vec.empty() ? (uchar*)&vec[0] : 0, vec.size() * sizeof(_Tp));
}
@ -846,7 +857,7 @@ namespace internal
{
size_t remaining = it->remaining;
size_t cn = DataType<_Tp>::channels;
int _fmt = DataType<_Tp>::fmt;
int _fmt = traits::SafeFmt<_Tp>::fmt;
char fmt[] = { (char)((_fmt >> 8)+'1'), (char)_fmt, '\0' };
size_t remaining1 = remaining / cn;
count = count < remaining1 ? count : remaining1;
@ -948,27 +959,6 @@ void write(FileStorage& fs, const Scalar_<_Tp>& s )
write(fs, s.val[3]);
}
static inline
void write(FileStorage& fs, const KeyPoint& kpt )
{
write(fs, kpt.pt.x);
write(fs, kpt.pt.y);
write(fs, kpt.size);
write(fs, kpt.angle);
write(fs, kpt.response);
write(fs, kpt.octave);
write(fs, kpt.class_id);
}
static inline
void write(FileStorage& fs, const DMatch& m )
{
write(fs, m.queryIdx);
write(fs, m.trainIdx);
write(fs, m.imgIdx);
write(fs, m.distance);
}
static inline
void write(FileStorage& fs, const Range& r )
{
@ -976,30 +966,10 @@ void write(FileStorage& fs, const Range& r )
write(fs, r.end);
}
static inline
void write( FileStorage& fs, const std::vector<KeyPoint>& vec )
{
size_t npoints = vec.size();
for(size_t i = 0; i < npoints; i++ )
{
write(fs, vec[i]);
}
}
static inline
void write( FileStorage& fs, const std::vector<DMatch>& vec )
{
size_t npoints = vec.size();
for(size_t i = 0; i < npoints; i++ )
{
write(fs, vec[i]);
}
}
template<typename _Tp> static inline
void write( FileStorage& fs, const std::vector<_Tp>& vec )
{
cv::internal::VecWriterProxy<_Tp, DataType<_Tp>::fmt != 0> w(&fs);
cv::internal::VecWriterProxy<_Tp, traits::SafeFmt<_Tp>::fmt != 0> w(&fs);
w(vec);
}
@ -1060,23 +1030,32 @@ void write(FileStorage& fs, const String& name, const Range& r )
}
static inline
void write(FileStorage& fs, const String& name, const KeyPoint& r )
void write(FileStorage& fs, const String& name, const KeyPoint& kpt)
{
cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW);
write(fs, r);
write(fs, kpt.pt.x);
write(fs, kpt.pt.y);
write(fs, kpt.size);
write(fs, kpt.angle);
write(fs, kpt.response);
write(fs, kpt.octave);
write(fs, kpt.class_id);
}
static inline
void write(FileStorage& fs, const String& name, const DMatch& r )
void write(FileStorage& fs, const String& name, const DMatch& m)
{
cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW);
write(fs, r);
write(fs, m.queryIdx);
write(fs, m.trainIdx);
write(fs, m.imgIdx);
write(fs, m.distance);
}
template<typename _Tp> static inline
void write( FileStorage& fs, const String& name, const std::vector<_Tp>& vec )
{
cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+(DataType<_Tp>::fmt != 0 ? FileNode::FLOW : 0));
cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+(traits::SafeFmt<_Tp>::fmt != 0 ? FileNode::FLOW : 0));
write(fs, vec);
}
@ -1086,11 +1065,29 @@ void write( FileStorage& fs, const String& name, const std::vector< std::vector<
cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ);
for(size_t i = 0; i < vec.size(); i++)
{
cv::internal::WriteStructContext ws_(fs, name, FileNode::SEQ+(DataType<_Tp>::fmt != 0 ? FileNode::FLOW : 0));
cv::internal::WriteStructContext ws_(fs, name, FileNode::SEQ+(traits::SafeFmt<_Tp>::fmt != 0 ? FileNode::FLOW : 0));
write(fs, vec[i]);
}
}
#ifdef CV__LEGACY_PERSISTENCE
// This code is not needed anymore, but it is preserved here to keep source compatibility
// Implementation is similar to templates instantiations
static inline void write(FileStorage& fs, const KeyPoint& kpt) { write(fs, String(), kpt); }
static inline void write(FileStorage& fs, const DMatch& m) { write(fs, String(), m); }
static inline void write(FileStorage& fs, const std::vector<KeyPoint>& vec)
{
cv::internal::VecWriterProxy<KeyPoint, 0> w(&fs);
w(vec);
}
static inline void write(FileStorage& fs, const std::vector<DMatch>& vec)
{
cv::internal::VecWriterProxy<DMatch, 0> w(&fs);
w(vec);
}
#endif
//! @} FileStorage
//! @relates cv::FileNode
@ -1139,7 +1136,7 @@ void read(const FileNode& node, short& value, short default_value)
template<typename _Tp> static inline
void read( FileNodeIterator& it, std::vector<_Tp>& vec, size_t maxCount = (size_t)INT_MAX )
{
cv::internal::VecReaderProxy<_Tp, DataType<_Tp>::fmt != 0> r(&it);
cv::internal::VecReaderProxy<_Tp, traits::SafeFmt<_Tp>::fmt != 0> r(&it);
r(vec, maxCount);
}
@ -1228,7 +1225,7 @@ FileNodeIterator& operator >> (FileNodeIterator& it, _Tp& value)
template<typename _Tp> static inline
FileNodeIterator& operator >> (FileNodeIterator& it, std::vector<_Tp>& vec)
{
cv::internal::VecReaderProxy<_Tp, DataType<_Tp>::fmt != 0> r(&it);
cv::internal::VecReaderProxy<_Tp, traits::SafeFmt<_Tp>::fmt != 0> r(&it);
r(vec, (size_t)INT_MAX);
return it;
}
@ -1258,12 +1255,6 @@ void operator >> (const FileNode& n, std::vector<_Tp>& vec)
/** @brief Reads KeyPoint from a file storage.
*/
//It needs special handling because it contains two types of fields, int & float.
static inline
void operator >> (const FileNode& n, std::vector<KeyPoint>& vec)
{
read(n, vec);
}
static inline
void operator >> (const FileNode& n, KeyPoint& kpt)
{
@ -1271,15 +1262,22 @@ void operator >> (const FileNode& n, KeyPoint& kpt)
it >> kpt.pt.x >> kpt.pt.y >> kpt.size >> kpt.angle >> kpt.response >> kpt.octave >> kpt.class_id;
}
/** @brief Reads DMatch from a file storage.
*/
//It needs special handling because it contains two types of fields, int & float.
#ifdef CV__LEGACY_PERSISTENCE
static inline
void operator >> (const FileNode& n, std::vector<KeyPoint>& vec)
{
read(n, vec);
}
static inline
void operator >> (const FileNode& n, std::vector<DMatch>& vec)
{
read(n, vec);
}
#endif
/** @brief Reads DMatch from a file storage.
*/
//It needs special handling because it contains two types of fields, int & float.
static inline
void operator >> (const FileNode& n, DMatch& m)
{

@ -49,11 +49,15 @@
namespace cv
{
//#define OPENCV_TRAITS_ENABLE_DEPRECATED
//! @addtogroup core_basic
//! @{
/** @brief Template "trait" class for OpenCV primitive data types.
@note Deprecated. This is replaced by "single purpose" traits: traits::Type and traits::Depth
A primitive OpenCV data type is one of unsigned char, bool, signed char, unsigned short, signed
short, int, float, double, or a tuple of values of one of these types, where all the values in the
tuple have the same type. Any primitive type from the list can be defined by an identifier in the
@ -102,10 +106,13 @@ So, such traits are used to tell OpenCV which data type you are working with, ev
not native to OpenCV. For example, the matrix B initialization above is compiled because OpenCV
defines the proper specialized template class DataType\<complex\<_Tp\> \> . This mechanism is also
useful (and used in OpenCV this way) for generic algorithms implementations.
@note Default values were dropped to stop confusing developers about using of unsupported types (see #7599)
*/
template<typename _Tp> class DataType
{
public:
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
typedef _Tp value_type;
typedef value_type work_type;
typedef value_type channel_type;
@ -116,6 +123,7 @@ public:
fmt = 0,
type = CV_MAKETYPE(depth, channels)
};
#endif
};
template<> class DataType<bool>
@ -270,11 +278,14 @@ public:
};
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
template<int _depth> class TypeDepth
{
#ifdef OPENCV_TRAITS_ENABLE_LEGACY_DEFAULTS
enum { depth = CV_USRTYPE1 };
typedef void value_type;
#endif
};
template<> class TypeDepth<CV_8U>
@ -319,8 +330,68 @@ template<> class TypeDepth<CV_64F>
typedef double value_type;
};
#endif
//! @}
namespace traits {
namespace internal {
#define CV_CREATE_MEMBER_CHECK(X) \
template<typename T> class CheckMember_##X { \
struct Fallback { int X; }; \
struct Derived : T, Fallback { }; \
template<typename U, U> struct Check; \
typedef char CV_NO[1]; \
typedef char CV_YES[2]; \
template<typename U> static CV_NO & func(Check<int Fallback::*, &U::X> *); \
template<typename U> static CV_YES & func(...); \
public: \
typedef CheckMember_##X type; \
enum { value = sizeof(func<Derived>(0)) == sizeof(CV_YES) }; \
};
CV_CREATE_MEMBER_CHECK(fmt)
CV_CREATE_MEMBER_CHECK(type)
} // namespace internal
template<typename T>
struct Depth
{ enum { value = DataType<T>::depth }; };
template<typename T>
struct Type
{ enum { value = DataType<T>::type }; };
/** Similar to traits::Type<T> but has value = -1 in case of unknown type (instead of compiler error) */
template<typename T, bool available = internal::CheckMember_type< DataType<T> >::value >
struct SafeType {};
template<typename T>
struct SafeType<T, false>
{ enum { value = -1 }; };
template<typename T>
struct SafeType<T, true>
{ enum { value = Type<T>::value }; };
template<typename T, bool available = internal::CheckMember_fmt< DataType<T> >::value >
struct SafeFmt {};
template<typename T>
struct SafeFmt<T, false>
{ enum { fmt = 0 }; };
template<typename T>
struct SafeFmt<T, true>
{ enum { fmt = DataType<T>::fmt }; };
} // namespace
} // cv
#endif // OPENCV_CORE_TRAITS_HPP

@ -98,14 +98,23 @@ public:
typedef _Tp channel_type;
enum { generic_type = 0,
depth = DataType<channel_type>::depth,
channels = 2,
fmt = DataType<channel_type>::fmt + ((channels - 1) << 8),
type = CV_MAKETYPE(depth, channels) };
fmt = DataType<channel_type>::fmt + ((channels - 1) << 8)
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
,depth = DataType<channel_type>::depth
,type = CV_MAKETYPE(depth, channels)
#endif
};
typedef Vec<channel_type, channels> vec_type;
};
namespace traits {
template<typename _Tp>
struct Depth< Complex<_Tp> > { enum { value = Depth<_Tp>::value }; };
template<typename _Tp>
struct Type< Complex<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 2) }; };
} // namespace
//////////////////////////////// Point_ ////////////////////////////////
@ -190,15 +199,23 @@ public:
typedef _Tp channel_type;
enum { generic_type = 0,
depth = DataType<channel_type>::depth,
channels = 2,
fmt = DataType<channel_type>::fmt + ((channels - 1) << 8),
type = CV_MAKETYPE(depth, channels)
fmt = traits::SafeFmt<channel_type>::fmt + ((channels - 1) << 8)
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
,depth = DataType<channel_type>::depth
,type = CV_MAKETYPE(depth, channels)
#endif
};
typedef Vec<channel_type, channels> vec_type;
};
namespace traits {
template<typename _Tp>
struct Depth< Point_<_Tp> > { enum { value = Depth<_Tp>::value }; };
template<typename _Tp>
struct Type< Point_<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 2) }; };
} // namespace
//////////////////////////////// Point3_ ////////////////////////////////
@ -261,16 +278,23 @@ public:
typedef _Tp channel_type;
enum { generic_type = 0,
depth = DataType<channel_type>::depth,
channels = 3,
fmt = DataType<channel_type>::fmt + ((channels - 1) << 8),
type = CV_MAKETYPE(depth, channels)
fmt = traits::SafeFmt<channel_type>::fmt + ((channels - 1) << 8)
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
,depth = DataType<channel_type>::depth
,type = CV_MAKETYPE(depth, channels)
#endif
};
typedef Vec<channel_type, channels> vec_type;
};
namespace traits {
template<typename _Tp>
struct Depth< Point3_<_Tp> > { enum { value = Depth<_Tp>::value }; };
template<typename _Tp>
struct Type< Point3_<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 3) }; };
} // namespace
//////////////////////////////// Size_ ////////////////////////////////
@ -324,16 +348,23 @@ public:
typedef _Tp channel_type;
enum { generic_type = 0,
depth = DataType<channel_type>::depth,
channels = 2,
fmt = DataType<channel_type>::fmt + ((channels - 1) << 8),
type = CV_MAKETYPE(depth, channels)
fmt = DataType<channel_type>::fmt + ((channels - 1) << 8)
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
,depth = DataType<channel_type>::depth
,type = CV_MAKETYPE(depth, channels)
#endif
};
typedef Vec<channel_type, channels> vec_type;
};
namespace traits {
template<typename _Tp>
struct Depth< Size_<_Tp> > { enum { value = Depth<_Tp>::value }; };
template<typename _Tp>
struct Type< Size_<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 2) }; };
} // namespace
//////////////////////////////// Rect_ ////////////////////////////////
@ -427,16 +458,23 @@ public:
typedef _Tp channel_type;
enum { generic_type = 0,
depth = DataType<channel_type>::depth,
channels = 4,
fmt = DataType<channel_type>::fmt + ((channels - 1) << 8),
type = CV_MAKETYPE(depth, channels)
fmt = traits::SafeFmt<channel_type>::fmt + ((channels - 1) << 8)
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
,depth = DataType<channel_type>::depth
,type = CV_MAKETYPE(depth, channels)
#endif
};
typedef Vec<channel_type, channels> vec_type;
};
namespace traits {
template<typename _Tp>
struct Depth< Rect_<_Tp> > { enum { value = Depth<_Tp>::value }; };
template<typename _Tp>
struct Type< Rect_<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 4) }; };
} // namespace
///////////////////////////// RotatedRect /////////////////////////////
@ -505,15 +543,23 @@ public:
typedef float channel_type;
enum { generic_type = 0,
depth = DataType<channel_type>::depth,
channels = (int)sizeof(value_type)/sizeof(channel_type), // 5
fmt = DataType<channel_type>::fmt + ((channels - 1) << 8),
type = CV_MAKETYPE(depth, channels)
fmt = traits::SafeFmt<channel_type>::fmt + ((channels - 1) << 8)
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
,depth = DataType<channel_type>::depth
,type = CV_MAKETYPE(depth, channels)
#endif
};
typedef Vec<channel_type, channels> vec_type;
};
namespace traits {
template<>
struct Depth< RotatedRect > { enum { value = Depth<float>::value }; };
template<>
struct Type< RotatedRect > { enum { value = CV_MAKETYPE(Depth<float>::value, (int)sizeof(RotatedRect)/sizeof(float)) }; };
} // namespace
//////////////////////////////// Range /////////////////////////////////
@ -561,15 +607,23 @@ public:
typedef int channel_type;
enum { generic_type = 0,
depth = DataType<channel_type>::depth,
channels = 2,
fmt = DataType<channel_type>::fmt + ((channels - 1) << 8),
type = CV_MAKETYPE(depth, channels)
fmt = traits::SafeFmt<channel_type>::fmt + ((channels - 1) << 8)
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
,depth = DataType<channel_type>::depth
,type = CV_MAKETYPE(depth, channels)
#endif
};
typedef Vec<channel_type, channels> vec_type;
};
namespace traits {
template<>
struct Depth< Range > { enum { value = Depth<int>::value }; };
template<>
struct Type< Range > { enum { value = CV_MAKETYPE(Depth<int>::value, 2) }; };
} // namespace
//////////////////////////////// Scalar_ ///////////////////////////////
@ -617,15 +671,23 @@ public:
typedef _Tp channel_type;
enum { generic_type = 0,
depth = DataType<channel_type>::depth,
channels = 4,
fmt = DataType<channel_type>::fmt + ((channels - 1) << 8),
type = CV_MAKETYPE(depth, channels)
fmt = traits::SafeFmt<channel_type>::fmt + ((channels - 1) << 8)
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
,depth = DataType<channel_type>::depth
,type = CV_MAKETYPE(depth, channels)
#endif
};
typedef Vec<channel_type, channels> vec_type;
};
namespace traits {
template<typename _Tp>
struct Depth< Scalar_<_Tp> > { enum { value = Depth<_Tp>::value }; };
template<typename _Tp>
struct Type< Scalar_<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 4) }; };
} // namespace
/////////////////////////////// KeyPoint ////////////////////////////////
@ -712,6 +774,7 @@ public:
CV_PROP_RW int class_id; //!< object class (if the keypoints need to be clustered by an object they belong to)
};
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
template<> class DataType<KeyPoint>
{
public:
@ -728,7 +791,7 @@ public:
typedef Vec<channel_type, channels> vec_type;
};
#endif
//////////////////////////////// DMatch /////////////////////////////////
@ -755,6 +818,7 @@ public:
bool operator<(const DMatch &m) const;
};
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
template<> class DataType<DMatch>
{
public:
@ -771,7 +835,7 @@ public:
typedef Vec<channel_type, channels> vec_type;
};
#endif
///////////////////////////// TermCriteria //////////////////////////////
@ -885,15 +949,24 @@ public:
typedef double channel_type;
enum { generic_type = 0,
depth = DataType<channel_type>::depth,
channels = (int)(sizeof(value_type)/sizeof(channel_type)), // 24
fmt = DataType<channel_type>::fmt + ((channels - 1) << 8),
type = CV_MAKETYPE(depth, channels)
fmt = DataType<channel_type>::fmt + ((channels - 1) << 8)
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
,depth = DataType<channel_type>::depth
,type = CV_MAKETYPE(depth, channels)
#endif
};
typedef Vec<channel_type, channels> vec_type;
};
namespace traits {
template<>
struct Depth< Moments > { enum { value = Depth<double>::value }; };
template<>
struct Type< Moments > { enum { value = CV_MAKETYPE(Depth<double>::value, (int)(sizeof(Moments)/sizeof(double))) }; };
} // namespace
//! @} imgproc_shape
//! @cond IGNORED

@ -7333,21 +7333,45 @@ void read( const FileNode& node, SparseMat& mat, const SparseMat& default_mat )
m->copyToSparseMat(mat);
}
void write(FileStorage& fs, const String& objname, const std::vector<KeyPoint>& keypoints)
CV_EXPORTS void read(const FileNode& node, KeyPoint& value, const KeyPoint& default_value)
{
cv::internal::WriteStructContext ws(fs, objname, CV_NODE_SEQ + CV_NODE_FLOW);
if( node.empty() )
{
value = default_value;
return;
}
node >> value;
}
int i, npoints = (int)keypoints.size();
for( i = 0; i < npoints; i++ )
CV_EXPORTS void read(const FileNode& node, DMatch& value, const DMatch& default_value)
{
if( node.empty() )
{
write(fs, keypoints[i]);
value = default_value;
return;
}
node >> value;
}
#ifdef CV__LEGACY_PERSISTENCE
void write( FileStorage& fs, const String& name, const std::vector<KeyPoint>& vec)
{
// from template implementation
cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ);
write(fs, vec);
}
void read(const FileNode& node, std::vector<KeyPoint>& keypoints)
{
keypoints.resize(0);
FileNode first_node = *(node.begin());
if (first_node.isSeq())
{
// modern scheme
FileNodeIterator it = node.begin();
it >> keypoints;
return;
}
keypoints.clear();
FileNodeIterator it = node.begin(), it_end = node.end();
for( ; it != it_end; )
{
@ -7357,21 +7381,24 @@ void read(const FileNode& node, std::vector<KeyPoint>& keypoints)
}
}
void write(FileStorage& fs, const String& objname, const std::vector<DMatch>& matches)
void write( FileStorage& fs, const String& name, const std::vector<DMatch>& vec)
{
cv::internal::WriteStructContext ws(fs, objname, CV_NODE_SEQ + CV_NODE_FLOW);
int i, n = (int)matches.size();
for( i = 0; i < n; i++ )
{
write(fs, matches[i]);
}
// from template implementation
cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ);
write(fs, vec);
}
void read(const FileNode& node, std::vector<DMatch>& matches)
{
matches.resize(0);
FileNode first_node = *(node.begin());
if (first_node.isSeq())
{
// modern scheme
FileNodeIterator it = node.begin();
it >> matches;
return;
}
matches.clear();
FileNodeIterator it = node.begin(), it_end = node.end();
for( ; it != it_end; )
{
@ -7380,7 +7407,7 @@ void read(const FileNode& node, std::vector<DMatch>& matches)
matches.push_back(m);
}
}
#endif
int FileNode::type() const { return !node ? NONE : (node->tag & TYPE_MASK); }
bool FileNode::isNamed() const { return !node ? false : (node->tag & NAMED) != 0; }

@ -1146,15 +1146,19 @@ TEST(Core_InputOutput, FileStorage_DMatch_vector)
EXPECT_STREQ(fs_result.c_str(),
"%YAML:1.0\n"
"---\n"
"dv: [ 1, 2, 3, -1.5000000000000000e+000, 2, 3, 4,\n"
" 1.5000000000000000e+000, 3, 2, 1, 5.0000000000000000e-001 ]\n"
"dv:\n"
" - [ 1, 2, 3, -1.5000000000000000e+000 ]\n"
" - [ 2, 3, 4, 1.5000000000000000e+000 ]\n"
" - [ 3, 2, 1, 5.0000000000000000e-001 ]\n"
);
#else
EXPECT_STREQ(fs_result.c_str(),
"%YAML:1.0\n"
"---\n"
"dv: [ 1, 2, 3, -1.5000000000000000e+00, 2, 3, 4, 1.5000000000000000e+00,\n"
" 3, 2, 1, 5.0000000000000000e-01 ]\n"
"dv:\n"
" - [ 1, 2, 3, -1.5000000000000000e+00 ]\n"
" - [ 2, 3, 4, 1.5000000000000000e+00 ]\n"
" - [ 3, 2, 1, 5.0000000000000000e-01 ]\n"
);
#endif
@ -1200,19 +1204,26 @@ TEST(Core_InputOutput, FileStorage_DMatch_vector_vector)
"%YAML:1.0\n"
"---\n"
"dvv:\n"
" - [ 1, 2, 3, -1.5000000000000000e+000, 2, 3, 4,\n"
" 1.5000000000000000e+000, 3, 2, 1, 5.0000000000000000e-001 ]\n"
" - [ 3, 2, 1, 5.0000000000000000e-001, 1, 2, 3,\n"
" -1.5000000000000000e+000 ]\n"
" -\n"
" - [ 1, 2, 3, -1.5000000000000000e+000 ]\n"
" - [ 2, 3, 4, 1.5000000000000000e+000 ]\n"
" - [ 3, 2, 1, 5.0000000000000000e-001 ]\n"
" -\n"
" - [ 3, 2, 1, 5.0000000000000000e-001 ]\n"
" - [ 1, 2, 3, -1.5000000000000000e+000 ]\n"
);
#else
EXPECT_STREQ(fs_result.c_str(),
"%YAML:1.0\n"
"---\n"
"dvv:\n"
" - [ 1, 2, 3, -1.5000000000000000e+00, 2, 3, 4, 1.5000000000000000e+00,\n"
" 3, 2, 1, 5.0000000000000000e-01 ]\n"
" - [ 3, 2, 1, 5.0000000000000000e-01, 1, 2, 3, -1.5000000000000000e+00 ]\n"
" -\n"
" - [ 1, 2, 3, -1.5000000000000000e+00 ]\n"
" - [ 2, 3, 4, 1.5000000000000000e+00 ]\n"
" - [ 3, 2, 1, 5.0000000000000000e-01 ]\n"
" -\n"
" - [ 3, 2, 1, 5.0000000000000000e-01 ]\n"
" - [ 1, 2, 3, -1.5000000000000000e+00 ]\n"
);
#endif
@ -1237,6 +1248,219 @@ TEST(Core_InputOutput, FileStorage_DMatch_vector_vector)
}
}
TEST(Core_InputOutput, FileStorage_KeyPoint)
{
cv::FileStorage fs("keypoint.xml", cv::FileStorage::WRITE | cv::FileStorage::MEMORY);
cv::KeyPoint k(Point2f(1, 2), 16, 0, 100, 1, -1);
EXPECT_NO_THROW(fs << "k" << k);
cv::String fs_result = fs.releaseAndGetString();
EXPECT_STREQ(fs_result.c_str(),
"<?xml version=\"1.0\"?>\n"
"<opencv_storage>\n"
"<k>\n"
" 1. 2. 16. 0. 100. 1 -1</k>\n"
"</opencv_storage>\n"
);
cv::FileStorage fs_read(fs_result, cv::FileStorage::READ | cv::FileStorage::MEMORY);
cv::KeyPoint k_read;
ASSERT_NO_THROW(fs_read["k"] >> k_read);
EXPECT_EQ(k.pt, k_read.pt);
EXPECT_EQ(k.size, k_read.size);
EXPECT_EQ(k.angle, k_read.angle);
EXPECT_EQ(k.response, k_read.response);
EXPECT_EQ(k.octave, k_read.octave);
EXPECT_EQ(k.class_id, k_read.class_id);
}
TEST(Core_InputOutput, FileStorage_KeyPoint_vector)
{
cv::FileStorage fs("keypoint.xml", cv::FileStorage::WRITE | cv::FileStorage::MEMORY);
cv::KeyPoint k1(Point2f(1, 2), 16, 0, 100, 1, -1);
cv::KeyPoint k2(Point2f(2, 3), 16, 45, 100, 1, -1);
cv::KeyPoint k3(Point2f(1, 2), 16, 90, 100, 1, -1);
std::vector<cv::KeyPoint> kv;
kv.push_back(k1);
kv.push_back(k2);
kv.push_back(k3);
EXPECT_NO_THROW(fs << "kv" << kv);
cv::String fs_result = fs.releaseAndGetString();
EXPECT_STREQ(fs_result.c_str(),
"<?xml version=\"1.0\"?>\n"
"<opencv_storage>\n"
"<kv>\n"
" <_>\n"
" 1. 2. 16. 0. 100. 1 -1</_>\n"
" <_>\n"
" 2. 3. 16. 45. 100. 1 -1</_>\n"
" <_>\n"
" 1. 2. 16. 90. 100. 1 -1</_></kv>\n"
"</opencv_storage>\n"
);
cv::FileStorage fs_read(fs_result, cv::FileStorage::READ | cv::FileStorage::MEMORY);
std::vector<cv::KeyPoint> kv_read;
ASSERT_NO_THROW(fs_read["kv"] >> kv_read);
ASSERT_EQ(kv.size(), kv_read.size());
for (size_t i = 0; i < kv.size(); i++)
{
EXPECT_EQ(kv[i].pt, kv_read[i].pt);
EXPECT_EQ(kv[i].size, kv_read[i].size);
EXPECT_EQ(kv[i].angle, kv_read[i].angle);
EXPECT_EQ(kv[i].response, kv_read[i].response);
EXPECT_EQ(kv[i].octave, kv_read[i].octave);
EXPECT_EQ(kv[i].class_id, kv_read[i].class_id);
}
}
TEST(Core_InputOutput, FileStorage_KeyPoint_vector_vector)
{
cv::FileStorage fs("keypoint.xml", cv::FileStorage::WRITE | cv::FileStorage::MEMORY);
cv::KeyPoint k1(Point2f(1, 2), 16, 0, 100, 1, -1);
cv::KeyPoint k2(Point2f(2, 3), 16, 45, 100, 1, -1);
cv::KeyPoint k3(Point2f(1, 2), 16, 90, 100, 1, -1);
std::vector<cv::KeyPoint> kv1;
kv1.push_back(k1);
kv1.push_back(k2);
kv1.push_back(k3);
std::vector<cv::KeyPoint> kv2;
kv2.push_back(k3);
kv2.push_back(k1);
std::vector< std::vector<cv::KeyPoint> > kvv;
kvv.push_back(kv1);
kvv.push_back(kv2);
EXPECT_NO_THROW(fs << "kvv" << kvv);
cv::String fs_result = fs.releaseAndGetString();
EXPECT_STREQ(fs_result.c_str(),
"<?xml version=\"1.0\"?>\n"
"<opencv_storage>\n"
"<kvv>\n"
" <_>\n"
" <_>\n"
" 1. 2. 16. 0. 100. 1 -1</_>\n"
" <_>\n"
" 2. 3. 16. 45. 100. 1 -1</_>\n"
" <_>\n"
" 1. 2. 16. 90. 100. 1 -1</_></_>\n"
" <_>\n"
" <_>\n"
" 1. 2. 16. 90. 100. 1 -1</_>\n"
" <_>\n"
" 1. 2. 16. 0. 100. 1 -1</_></_></kvv>\n"
"</opencv_storage>\n"
);
cv::FileStorage fs_read(fs_result, cv::FileStorage::READ | cv::FileStorage::MEMORY);
std::vector< std::vector<cv::KeyPoint> > kvv_read;
ASSERT_NO_THROW(fs_read["kvv"] >> kvv_read);
ASSERT_EQ(kvv.size(), kvv_read.size());
for (size_t j = 0; j < kvv.size(); j++)
{
const std::vector<cv::KeyPoint>& kv = kvv[j];
const std::vector<cv::KeyPoint>& kv_read = kvv_read[j];
ASSERT_EQ(kvv.size(), kvv_read.size());
for (size_t i = 0; i < kv.size(); i++)
{
EXPECT_EQ(kv[i].pt, kv_read[i].pt);
EXPECT_EQ(kv[i].size, kv_read[i].size);
EXPECT_EQ(kv[i].angle, kv_read[i].angle);
EXPECT_EQ(kv[i].response, kv_read[i].response);
EXPECT_EQ(kv[i].octave, kv_read[i].octave);
EXPECT_EQ(kv[i].class_id, kv_read[i].class_id);
}
}
}
#ifdef CV__LEGACY_PERSISTENCE
TEST(Core_InputOutput, FileStorage_LEGACY_DMatch_vector)
{
cv::DMatch d1(1, 2, 3, -1.5f);
cv::DMatch d2(2, 3, 4, 1.5f);
cv::DMatch d3(3, 2, 1, 0.5f);
std::vector<cv::DMatch> dv;
dv.push_back(d1);
dv.push_back(d2);
dv.push_back(d3);
String fs_result =
"<?xml version=\"1.0\"?>\n"
"<opencv_storage>\n"
"<dv>\n"
" 1 2 3 -1.5000000000000000e+00 2 3 4 1.5000000000000000e+00 3 2 1\n"
" 5.0000000000000000e-01</dv>\n"
"</opencv_storage>\n"
;
cv::FileStorage fs_read(fs_result, cv::FileStorage::READ | cv::FileStorage::MEMORY);
std::vector<cv::DMatch> dv_read;
ASSERT_NO_THROW(fs_read["dv"] >> dv_read);
ASSERT_EQ(dv.size(), dv_read.size());
for (size_t i = 0; i < dv.size(); i++)
{
EXPECT_EQ(dv[i].queryIdx, dv_read[i].queryIdx);
EXPECT_EQ(dv[i].trainIdx, dv_read[i].trainIdx);
EXPECT_EQ(dv[i].imgIdx, dv_read[i].imgIdx);
EXPECT_EQ(dv[i].distance, dv_read[i].distance);
}
}
TEST(Core_InputOutput, FileStorage_LEGACY_KeyPoint_vector)
{
cv::KeyPoint k1(Point2f(1, 2), 16, 0, 100, 1, -1);
cv::KeyPoint k2(Point2f(2, 3), 16, 45, 100, 1, -1);
cv::KeyPoint k3(Point2f(1, 2), 16, 90, 100, 1, -1);
std::vector<cv::KeyPoint> kv;
kv.push_back(k1);
kv.push_back(k2);
kv.push_back(k3);
cv::String fs_result =
"<?xml version=\"1.0\"?>\n"
"<opencv_storage>\n"
"<kv>\n"
" 1. 2. 16. 0. 100. 1 -1\n"
" 2. 3. 16. 45. 100. 1 -1\n"
" 1. 2. 16. 90. 100. 1 -1</kv>\n"
"</opencv_storage>\n"
;
cv::FileStorage fs_read(fs_result, cv::FileStorage::READ | cv::FileStorage::MEMORY);
std::vector<cv::KeyPoint> kv_read;
ASSERT_NO_THROW(fs_read["kv"] >> kv_read);
ASSERT_EQ(kv.size(), kv_read.size());
for (size_t i = 0; i < kv.size(); i++)
{
EXPECT_EQ(kv[i].pt, kv_read[i].pt);
EXPECT_EQ(kv[i].size, kv_read[i].size);
EXPECT_EQ(kv[i].angle, kv_read[i].angle);
EXPECT_EQ(kv[i].response, kv_read[i].response);
EXPECT_EQ(kv[i].octave, kv_read[i].octave);
EXPECT_EQ(kv[i].class_id, kv_read[i].class_id);
}
}
#endif
TEST(Core_InputOutput, FileStorage_format_xml)
{
FileStorage fs;

@ -105,7 +105,7 @@ CV_OperationsTest::~CV_OperationsTest() {}
template<typename _Tp> void CV_OperationsTest::TestType(Size sz, _Tp value)
{
cv::Mat_<_Tp> m(sz);
CV_Assert(m.cols == sz.width && m.rows == sz.height && m.depth() == DataType<_Tp>::depth &&
CV_Assert(m.cols == sz.width && m.rows == sz.height && m.depth() == cv::traits::Depth<_Tp>::value &&
m.channels() == DataType<_Tp>::channels &&
m.elemSize() == sizeof(_Tp) && m.step == m.elemSize()*m.cols);
for( int y = 0; y < sz.height; y++ )

@ -186,7 +186,7 @@ namespace
}
BufferPool pool(stream);
GpuMat objectsBuf = pool.getBuffer(1, maxNumObjects_, DataType<Rect>::type);
GpuMat objectsBuf = pool.getBuffer(1, maxNumObjects_, traits::Type<Rect>::value);
unsigned int numDetections;
ncvSafeCall( process(image, objectsBuf, ncvMinSize, numDetections) );
@ -220,7 +220,7 @@ namespace
}
CV_Assert( gpu_objects.rows == 1 );
CV_Assert( gpu_objects.type() == DataType<Rect>::type );
CV_Assert( gpu_objects.type() == traits::Type<Rect>::value );
Rect* ptr = gpu_objects.ptr<Rect>();
objects.assign(ptr, ptr + gpu_objects.cols);
@ -533,7 +533,7 @@ namespace
const float grouping_eps = 0.2f;
BufferPool pool(stream);
GpuMat objects = pool.getBuffer(1, maxNumObjects_, DataType<Rect>::type);
GpuMat objects = pool.getBuffer(1, maxNumObjects_, traits::Type<Rect>::value);
// used for debug
// candidates.setTo(cv::Scalar::all(0));
@ -625,7 +625,7 @@ namespace
}
CV_Assert( gpu_objects.rows == 1 );
CV_Assert( gpu_objects.type() == DataType<Rect>::type );
CV_Assert( gpu_objects.type() == traits::Type<Rect>::value );
Rect* ptr = gpu_objects.ptr<Rect>();
objects.assign(ptr, ptr + gpu_objects.cols);

@ -345,7 +345,7 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN
CV_WRAP Ptr<Layer> getLayer(LayerId layerId);
/** @brief Returns pointers to input layers of specific layer. */
CV_WRAP std::vector<Ptr<Layer> > getLayerInputs(LayerId layerId);
std::vector<Ptr<Layer> > getLayerInputs(LayerId layerId); // FIXIT: CV_WRAP
/** @brief Delete layer for the network (not implemented yet) */
CV_WRAP void deleteLayer(LayerId layer);
@ -502,16 +502,16 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN
* @param outLayerShapes output parameter for output layers shapes;
* order is the same as in layersIds
*/
CV_WRAP void getLayerShapes(const MatShape& netInputShape,
void getLayerShapes(const MatShape& netInputShape,
const int layerId,
CV_OUT std::vector<MatShape>& inLayerShapes,
CV_OUT std::vector<MatShape>& outLayerShapes) const;
CV_OUT std::vector<MatShape>& outLayerShapes) const; // FIXIT: CV_WRAP
/** @overload */
CV_WRAP void getLayerShapes(const std::vector<MatShape>& netInputShapes,
void getLayerShapes(const std::vector<MatShape>& netInputShapes,
const int layerId,
CV_OUT std::vector<MatShape>& inLayerShapes,
CV_OUT std::vector<MatShape>& outLayerShapes) const;
CV_OUT std::vector<MatShape>& outLayerShapes) const; // FIXIT: CV_WRAP
/** @brief Computes FLOP for whole loaded model with specified input shapes.
* @param netInputShapes vector of shapes for all net inputs.
@ -544,8 +544,8 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN
* @param weights output parameter to store resulting bytes for weights.
* @param blobs output parameter to store resulting bytes for intermediate blobs.
*/
CV_WRAP void getMemoryConsumption(const std::vector<MatShape>& netInputShapes,
CV_OUT size_t& weights, CV_OUT size_t& blobs) const;
void getMemoryConsumption(const std::vector<MatShape>& netInputShapes,
CV_OUT size_t& weights, CV_OUT size_t& blobs) const; // FIXIT: CV_WRAP
/** @overload */
CV_WRAP void getMemoryConsumption(const MatShape& netInputShape,
CV_OUT size_t& weights, CV_OUT size_t& blobs) const;
@ -565,15 +565,15 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN
* @param weights output parameter to store resulting bytes for weights.
* @param blobs output parameter to store resulting bytes for intermediate blobs.
*/
CV_WRAP void getMemoryConsumption(const std::vector<MatShape>& netInputShapes,
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;
CV_OUT std::vector<size_t>& blobs) const; // FIXIT: CV_WRAP
/** @overload */
CV_WRAP void getMemoryConsumption(const MatShape& netInputShape,
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;
CV_OUT std::vector<size_t>& blobs) const; // FIXIT: CV_WRAP
/** @brief Enables or disables layer fusion in the network.
* @param fusion true to enable the fusion, false to disable. The fusion is enabled by default.

@ -19,18 +19,6 @@ void MatShape_to_Mat(MatShape& matshape, cv::Mat& mat)
mat = cv::Mat(matshape, true);
}
void Mat_to_vector_size_t(cv::Mat& mat, std::vector<size_t>& v_size_t)
{
v_size_t.clear();
CHECK_MAT(mat.type()==CV_32SC1 && mat.cols==1);
v_size_t = (std::vector<size_t>) mat;
}
void vector_size_t_to_Mat(std::vector<size_t>& v_size_t, cv::Mat& mat)
{
mat = cv::Mat(v_size_t, true);
}
std::vector<MatShape> List_to_vector_MatShape(JNIEnv* env, jobject list)
{
static jclass juArrayList = ARRAYLIST(env);

@ -22,10 +22,6 @@ void Mat_to_MatShape(cv::Mat& mat, MatShape& matshape);
void MatShape_to_Mat(MatShape& matshape, cv::Mat& mat);
void Mat_to_vector_size_t(cv::Mat& mat, std::vector<size_t>& v_size_t);
void vector_size_t_to_Mat(std::vector<size_t>& v_size_t, cv::Mat& mat);
std::vector<MatShape> List_to_vector_MatShape(JNIEnv* env, jobject list);
jobject vector_Ptr_Layer_to_List(JNIEnv* env, std::vector<cv::Ptr<cv::dnn::Layer> >& vs);

@ -57,20 +57,3 @@ void Copy_vector_String_to_List(JNIEnv* env, std::vector<cv::String>& vs, jobjec
env->DeleteLocalRef(element);
}
}
#if defined(HAVE_OPENCV_DNN)
void Copy_vector_MatShape_to_List(JNIEnv* env, std::vector<cv::dnn::MatShape>& vs, jobject list)
{
static jclass juArrayList = ARRAYLIST(env);
jmethodID m_clear = LIST_CLEAR(env, juArrayList);
jmethodID m_add = LIST_ADD(env, juArrayList);
env->CallVoidMethod(list, m_clear);
for (std::vector<cv::dnn::MatShape>::iterator it = vs.begin(); it != vs.end(); ++it)
{
jstring element = env->NewStringUTF("");
env->CallBooleanMethod(list, m_add, element);
env->DeleteLocalRef(element);
}
}
#endif

@ -16,9 +16,4 @@ std::vector<cv::String> List_to_vector_String(JNIEnv* env, jobject list);
void Copy_vector_String_to_List(JNIEnv* env, std::vector<cv::String>& vs, jobject list);
#if defined(HAVE_OPENCV_DNN)
#include "opencv2/dnn.hpp"
void Copy_vector_MatShape_to_List(JNIEnv* env, std::vector<cv::dnn::MatShape>& vs, jobject list);
#endif
#endif /* LISTCONVERTERS_HPP */

@ -1076,7 +1076,7 @@ template<typename _Tp> struct pyopencvVecConverter
int i, j, n = (int)PySequence_Fast_GET_SIZE(seq);
value.resize(n);
int type = DataType<_Tp>::type;
int type = traits::Type<_Tp>::value;
int depth = CV_MAT_DEPTH(type), channels = CV_MAT_CN(type);
PyObject** items = PySequence_Fast_ITEMS(seq);
@ -1159,7 +1159,9 @@ template<typename _Tp> struct pyopencvVecConverter
{
if(value.empty())
return PyTuple_New(0);
Mat src((int)value.size(), DataType<_Tp>::channels, DataType<_Tp>::depth, (uchar*)&value[0]);
int type = traits::Type<_Tp>::value;
int depth = CV_MAT_DEPTH(type), channels = CV_MAT_CN(type);
Mat src((int)value.size(), channels, depth, (uchar*)&value[0]);
return pyopencv_from(src);
}
};

Loading…
Cancel
Save