diff --git a/modules/calib3d/test/test_cameracalibration.cpp b/modules/calib3d/test/test_cameracalibration.cpp index d738341eeb..85c37516f9 100644 --- a/modules/calib3d/test/test_cameracalibration.cpp +++ b/modules/calib3d/test/test_cameracalibration.cpp @@ -1911,9 +1911,9 @@ double CV_StereoCalibrationTest_C::calibrateStereoCamera( const vector::type ), - imgPt( 1, total, DataType::type ), - imgPt2( 1, total, DataType::type ); + objPt( 1, total, traits::Type::value ), + imgPt( 1, total, traits::Type::value ), + imgPt2( 1, total, traits::Type::value ); Point2f* imgPtData2 = imgPt2.ptr(); Point3f* objPtData = objPt.ptr(); diff --git a/modules/core/include/opencv2/core/affine.hpp b/modules/core/include/opencv2/core/affine.hpp index 41de5c6b57..443097a52c 100644 --- a/modules/core/include/opencv2/core/affine.hpp +++ b/modules/core/include/opencv2/core/affine.hpp @@ -153,15 +153,24 @@ namespace cv typedef _Tp channel_type; enum { generic_type = 0, - depth = DataType::depth, channels = 16, - fmt = DataType::fmt + ((channels - 1) << 8), - type = CV_MAKETYPE(depth, channels) + fmt = traits::SafeFmt::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType::depth + ,type = CV_MAKETYPE(depth, channels) +#endif }; typedef Vec vec_type; }; + namespace traits { + template + struct Depth< Affine3<_Tp> > { enum { value = Depth<_Tp>::value }; }; + template + struct Type< Affine3<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 16) }; }; + } // namespace + //! @} core } @@ -202,7 +211,7 @@ cv::Affine3::Affine3(const Vec3& _rvec, const Vec3& t) template inline cv::Affine3::Affine3(const cv::Mat& data, const Vec3& t) { - CV_Assert(data.type() == cv::DataType::type); + CV_Assert(data.type() == cv::traits::Type::value); if (data.cols == 4 && data.rows == 4) { @@ -271,7 +280,7 @@ void cv::Affine3::rotation(const Vec3& _rvec) template inline void cv::Affine3::rotation(const cv::Mat& data) { - CV_Assert(data.type() == cv::DataType::type); + CV_Assert(data.type() == cv::traits::Type::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 inline cv::Affine3::Affine3(const Eigen::Transform& affine) { - cv::Mat(4, 4, cv::DataType::type, affine.matrix().data()).copyTo(matrix); + cv::Mat(4, 4, cv::traits::Type::value, affine.matrix().data()).copyTo(matrix); } template inline cv::Affine3::Affine3(const Eigen::Transform& affine) { Eigen::Transform a = affine; - cv::Mat(4, 4, cv::DataType::type, a.matrix().data()).copyTo(matrix); + cv::Mat(4, 4, cv::traits::Type::value, a.matrix().data()).copyTo(matrix); } template inline cv::Affine3::operator Eigen::Transform() const { Eigen::Transform r; - cv::Mat hdr(4, 4, cv::DataType::type, r.matrix().data()); + cv::Mat hdr(4, 4, cv::traits::Type::value, r.matrix().data()); cv::Mat(matrix, false).copyTo(hdr); return r; } diff --git a/modules/core/include/opencv2/core/eigen.hpp b/modules/core/include/opencv2/core/eigen.hpp index c2f1ee6a83..35a4c81145 100644 --- a/modules/core/include/opencv2/core/eigen.hpp +++ b/modules/core/include/opencv2/core/eigen.hpp @@ -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); } diff --git a/modules/core/include/opencv2/core/mat.hpp b/modules/core/include/opencv2/core/mat.hpp index 8e35fd4dc4..31d182c713 100644 --- a/modules/core/include/opencv2/core/mat.hpp +++ b/modules/core/include/opencv2/core/mat.hpp @@ -1666,7 +1666,7 @@ public: inv_scale = 1.f/alpha_scale; CV_Assert( src1.type() == src2.type() && - src1.type() == CV_MAKETYPE(DataType::depth, 4) && + src1.type() == CV_MAKETYPE(traits::Depth::value, 4) && src1.size() == src2.size()); Size size = src1.size(); dst.create(size, src1.type()); @@ -1946,7 +1946,7 @@ public: inv_scale = 1.f/alpha_scale; CV_Assert( src1.type() == src2.type() && - src1.type() == DataType::type && + src1.type() == traits::Type::value && src1.size() == src2.size()); Size size = src1.size(); dst.create(size, src1.type()); diff --git a/modules/core/include/opencv2/core/mat.inl.hpp b/modules/core/include/opencv2/core/mat.inl.hpp index 934a8f07cb..3afdb0f247 100644 --- a/modules/core/include/opencv2/core/mat.inl.hpp +++ b/modules/core/include/opencv2/core/mat.inl.hpp @@ -1665,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 } diff --git a/modules/core/include/opencv2/core/types.hpp b/modules/core/include/opencv2/core/types.hpp index a99346a0c5..f3a7b518bf 100644 --- a/modules/core/include/opencv2/core/types.hpp +++ b/modules/core/include/opencv2/core/types.hpp @@ -98,14 +98,23 @@ public: typedef _Tp channel_type; enum { generic_type = 0, - depth = DataType::depth, channels = 2, - fmt = DataType::fmt + ((channels - 1) << 8), - type = CV_MAKETYPE(depth, channels) }; + fmt = DataType::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType::depth + ,type = CV_MAKETYPE(depth, channels) +#endif + }; typedef Vec vec_type; }; +namespace traits { +template +struct Depth< Complex<_Tp> > { enum { value = Depth<_Tp>::value }; }; +template +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::depth, channels = 2, - fmt = DataType::fmt + ((channels - 1) << 8), - type = CV_MAKETYPE(depth, channels) + fmt = traits::SafeFmt::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType::depth + ,type = CV_MAKETYPE(depth, channels) +#endif }; typedef Vec vec_type; }; +namespace traits { +template +struct Depth< Point_<_Tp> > { enum { value = Depth<_Tp>::value }; }; +template +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::depth, channels = 3, - fmt = DataType::fmt + ((channels - 1) << 8), - type = CV_MAKETYPE(depth, channels) + fmt = traits::SafeFmt::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType::depth + ,type = CV_MAKETYPE(depth, channels) +#endif }; typedef Vec vec_type; }; - +namespace traits { +template +struct Depth< Point3_<_Tp> > { enum { value = Depth<_Tp>::value }; }; +template +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::depth, channels = 2, - fmt = DataType::fmt + ((channels - 1) << 8), - type = CV_MAKETYPE(depth, channels) + fmt = DataType::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType::depth + ,type = CV_MAKETYPE(depth, channels) +#endif }; typedef Vec vec_type; }; - +namespace traits { +template +struct Depth< Size_<_Tp> > { enum { value = Depth<_Tp>::value }; }; +template +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::depth, channels = 4, - fmt = DataType::fmt + ((channels - 1) << 8), - type = CV_MAKETYPE(depth, channels) + fmt = traits::SafeFmt::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType::depth + ,type = CV_MAKETYPE(depth, channels) +#endif }; typedef Vec vec_type; }; - +namespace traits { +template +struct Depth< Rect_<_Tp> > { enum { value = Depth<_Tp>::value }; }; +template +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::depth, channels = (int)sizeof(value_type)/sizeof(channel_type), // 5 - fmt = DataType::fmt + ((channels - 1) << 8), - type = CV_MAKETYPE(depth, channels) + fmt = traits::SafeFmt::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType::depth + ,type = CV_MAKETYPE(depth, channels) +#endif }; typedef Vec vec_type; }; +namespace traits { +template<> +struct Depth< RotatedRect > { enum { value = Depth::value }; }; +template<> +struct Type< RotatedRect > { enum { value = CV_MAKETYPE(Depth::value, (int)sizeof(RotatedRect)/sizeof(float)) }; }; +} // namespace //////////////////////////////// Range ///////////////////////////////// @@ -561,15 +607,23 @@ public: typedef int channel_type; enum { generic_type = 0, - depth = DataType::depth, channels = 2, - fmt = DataType::fmt + ((channels - 1) << 8), - type = CV_MAKETYPE(depth, channels) + fmt = traits::SafeFmt::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType::depth + ,type = CV_MAKETYPE(depth, channels) +#endif }; typedef Vec vec_type; }; +namespace traits { +template<> +struct Depth< Range > { enum { value = Depth::value }; }; +template<> +struct Type< Range > { enum { value = CV_MAKETYPE(Depth::value, 2) }; }; +} // namespace //////////////////////////////// Scalar_ /////////////////////////////// @@ -617,15 +671,23 @@ public: typedef _Tp channel_type; enum { generic_type = 0, - depth = DataType::depth, channels = 4, - fmt = DataType::fmt + ((channels - 1) << 8), - type = CV_MAKETYPE(depth, channels) + fmt = traits::SafeFmt::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType::depth + ,type = CV_MAKETYPE(depth, channels) +#endif }; typedef Vec vec_type; }; +namespace traits { +template +struct Depth< Scalar_<_Tp> > { enum { value = Depth<_Tp>::value }; }; +template +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 { public: @@ -728,7 +791,7 @@ public: typedef Vec vec_type; }; - +#endif //////////////////////////////// DMatch ///////////////////////////////// @@ -755,6 +818,7 @@ public: bool operator<(const DMatch &m) const; }; +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED template<> class DataType { public: @@ -771,7 +835,7 @@ public: typedef Vec vec_type; }; - +#endif ///////////////////////////// TermCriteria ////////////////////////////// @@ -885,15 +949,24 @@ public: typedef double channel_type; enum { generic_type = 0, - depth = DataType::depth, channels = (int)(sizeof(value_type)/sizeof(channel_type)), // 24 - fmt = DataType::fmt + ((channels - 1) << 8), - type = CV_MAKETYPE(depth, channels) + fmt = DataType::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType::depth + ,type = CV_MAKETYPE(depth, channels) +#endif }; typedef Vec vec_type; }; +namespace traits { +template<> +struct Depth< Moments > { enum { value = Depth::value }; }; +template<> +struct Type< Moments > { enum { value = CV_MAKETYPE(Depth::value, (int)(sizeof(Moments)/sizeof(double))) }; }; +} // namespace + //! @} imgproc_shape //! @cond IGNORED