Skip to content

Commit 2ac57a2

Browse files
committed
Merge pull request opencv#9457 from alalek:type_traits_issue_7599
2 parents b05789f + 164a41b commit 2ac57a2

File tree

23 files changed

+756
-340
lines changed

23 files changed

+756
-340
lines changed

cmake/OpenCVUtils.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,12 @@ function(ocv_target_link_libraries target)
940940
endif()
941941
endfunction()
942942

943+
function(ocv_target_compile_definitions target)
944+
_ocv_fix_target(target)
945+
target_compile_definitions(${target} ${ARGN})
946+
endfunction()
947+
948+
943949
function(_ocv_append_target_includes target)
944950
if(DEFINED OCV_TARGET_INCLUDE_DIRS_${target})
945951
target_include_directories(${target} PRIVATE ${OCV_TARGET_INCLUDE_DIRS_${target}})

doc/Doxyfile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ RECURSIVE = YES
107107
EXCLUDE =
108108
EXCLUDE_SYMLINKS = NO
109109
EXCLUDE_PATTERNS = *.inl.hpp *.impl.hpp *_detail.hpp */cudev/**/detail/*.hpp *.m
110-
EXCLUDE_SYMBOLS = cv::DataType<*> int void
110+
EXCLUDE_SYMBOLS = cv::DataType<*> cv::traits::* int void CV__*
111111
EXAMPLE_PATH = @CMAKE_DOXYGEN_EXAMPLE_PATH@
112112
EXAMPLE_PATTERNS = *
113113
EXAMPLE_RECURSIVE = YES

modules/calib3d/test/test_cameracalibration.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,9 +1911,9 @@ double CV_StereoCalibrationTest_C::calibrateStereoCamera( const vector<vector<Po
19111911
}
19121912

19131913
Mat npoints( 1, nimages, CV_32S ),
1914-
objPt( 1, total, DataType<Point3f>::type ),
1915-
imgPt( 1, total, DataType<Point2f>::type ),
1916-
imgPt2( 1, total, DataType<Point2f>::type );
1914+
objPt( 1, total, traits::Type<Point3f>::value ),
1915+
imgPt( 1, total, traits::Type<Point2f>::value ),
1916+
imgPt2( 1, total, traits::Type<Point2f>::value );
19171917

19181918
Point2f* imgPtData2 = imgPt2.ptr<Point2f>();
19191919
Point3f* objPtData = objPt.ptr<Point3f>();

modules/core/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,9 @@ ocv_target_link_libraries(${the_module} LINK_PRIVATE
6363
"${OPENCV_HAL_LINKER_LIBS}"
6464
)
6565

66+
if(HAVE_CUDA)
67+
ocv_target_compile_definitions(${the_module} PUBLIC OPENCV_TRAITS_ENABLE_DEPRECATED)
68+
endif()
69+
6670
ocv_add_accuracy_tests()
6771
ocv_add_perf_tests()

modules/core/include/opencv2/core/affine.hpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,24 @@ namespace cv
153153
typedef _Tp channel_type;
154154

155155
enum { generic_type = 0,
156-
depth = DataType<channel_type>::depth,
157156
channels = 16,
158-
fmt = DataType<channel_type>::fmt + ((channels - 1) << 8),
159-
type = CV_MAKETYPE(depth, channels)
157+
fmt = traits::SafeFmt<channel_type>::fmt + ((channels - 1) << 8)
158+
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
159+
,depth = DataType<channel_type>::depth
160+
,type = CV_MAKETYPE(depth, channels)
161+
#endif
160162
};
161163

162164
typedef Vec<channel_type, channels> vec_type;
163165
};
164166

167+
namespace traits {
168+
template<typename _Tp>
169+
struct Depth< Affine3<_Tp> > { enum { value = Depth<_Tp>::value }; };
170+
template<typename _Tp>
171+
struct Type< Affine3<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 16) }; };
172+
} // namespace
173+
165174
//! @} core
166175

167176
}
@@ -202,7 +211,7 @@ cv::Affine3<T>::Affine3(const Vec3& _rvec, const Vec3& t)
202211
template<typename T> inline
203212
cv::Affine3<T>::Affine3(const cv::Mat& data, const Vec3& t)
204213
{
205-
CV_Assert(data.type() == cv::DataType<T>::type);
214+
CV_Assert(data.type() == cv::traits::Type<T>::value);
206215

207216
if (data.cols == 4 && data.rows == 4)
208217
{
@@ -271,7 +280,7 @@ void cv::Affine3<T>::rotation(const Vec3& _rvec)
271280
template<typename T> inline
272281
void cv::Affine3<T>::rotation(const cv::Mat& data)
273282
{
274-
CV_Assert(data.type() == cv::DataType<T>::type);
283+
CV_Assert(data.type() == cv::traits::Type<T>::value);
275284

276285
if (data.cols == 3 && data.rows == 3)
277286
{
@@ -485,21 +494,21 @@ cv::Vec3d cv::operator*(const cv::Affine3d& affine, const cv::Vec3d& v)
485494
template<typename T> inline
486495
cv::Affine3<T>::Affine3(const Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)>& affine)
487496
{
488-
cv::Mat(4, 4, cv::DataType<T>::type, affine.matrix().data()).copyTo(matrix);
497+
cv::Mat(4, 4, cv::traits::Type<T>::value, affine.matrix().data()).copyTo(matrix);
489498
}
490499

491500
template<typename T> inline
492501
cv::Affine3<T>::Affine3(const Eigen::Transform<T, 3, Eigen::Affine>& affine)
493502
{
494503
Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)> a = affine;
495-
cv::Mat(4, 4, cv::DataType<T>::type, a.matrix().data()).copyTo(matrix);
504+
cv::Mat(4, 4, cv::traits::Type<T>::value, a.matrix().data()).copyTo(matrix);
496505
}
497506

498507
template<typename T> inline
499508
cv::Affine3<T>::operator Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)>() const
500509
{
501510
Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)> r;
502-
cv::Mat hdr(4, 4, cv::DataType<T>::type, r.matrix().data());
511+
cv::Mat hdr(4, 4, cv::traits::Type<T>::value, r.matrix().data());
503512
cv::Mat(matrix, false).copyTo(hdr);
504513
return r;
505514
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ template<typename _Tp, int n> static inline
233233
std::ostream& operator << (std::ostream& out, const Vec<_Tp, n>& vec)
234234
{
235235
out << "[";
236-
if(Vec<_Tp, n>::depth < CV_32F)
236+
if (cv::traits::Depth<_Tp>::value <= CV_32S)
237237
{
238238
for (int i = 0; i < n - 1; ++i) {
239239
out << (int)vec[i] << ", ";

modules/core/include/opencv2/core/eigen.hpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ void eigen2cv( const Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCo
6464
{
6565
if( !(src.Flags & Eigen::RowMajorBit) )
6666
{
67-
Mat _src(src.cols(), src.rows(), DataType<_Tp>::type,
67+
Mat _src(src.cols(), src.rows(), traits::Type<_Tp>::value,
6868
(void*)src.data(), src.stride()*sizeof(_Tp));
6969
transpose(_src, dst);
7070
}
7171
else
7272
{
73-
Mat _src(src.rows(), src.cols(), DataType<_Tp>::type,
73+
Mat _src(src.rows(), src.cols(), traits::Type<_Tp>::value,
7474
(void*)src.data(), src.stride()*sizeof(_Tp));
7575
_src.copyTo(dst);
7676
}
@@ -98,7 +98,7 @@ void cv2eigen( const Mat& src,
9898
CV_DbgAssert(src.rows == _rows && src.cols == _cols);
9999
if( !(dst.Flags & Eigen::RowMajorBit) )
100100
{
101-
const Mat _dst(src.cols, src.rows, DataType<_Tp>::type,
101+
const Mat _dst(src.cols, src.rows, traits::Type<_Tp>::value,
102102
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
103103
if( src.type() == _dst.type() )
104104
transpose(src, _dst);
@@ -112,7 +112,7 @@ void cv2eigen( const Mat& src,
112112
}
113113
else
114114
{
115-
const Mat _dst(src.rows, src.cols, DataType<_Tp>::type,
115+
const Mat _dst(src.rows, src.cols, traits::Type<_Tp>::value,
116116
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
117117
src.convertTo(_dst, _dst.type());
118118
}
@@ -125,13 +125,13 @@ void cv2eigen( const Matx<_Tp, _rows, _cols>& src,
125125
{
126126
if( !(dst.Flags & Eigen::RowMajorBit) )
127127
{
128-
const Mat _dst(_cols, _rows, DataType<_Tp>::type,
128+
const Mat _dst(_cols, _rows, traits::Type<_Tp>::value,
129129
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
130130
transpose(src, _dst);
131131
}
132132
else
133133
{
134-
const Mat _dst(_rows, _cols, DataType<_Tp>::type,
134+
const Mat _dst(_rows, _cols, traits::Type<_Tp>::value,
135135
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
136136
Mat(src).copyTo(_dst);
137137
}
@@ -144,7 +144,7 @@ void cv2eigen( const Mat& src,
144144
dst.resize(src.rows, src.cols);
145145
if( !(dst.Flags & Eigen::RowMajorBit) )
146146
{
147-
const Mat _dst(src.cols, src.rows, DataType<_Tp>::type,
147+
const Mat _dst(src.cols, src.rows, traits::Type<_Tp>::value,
148148
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
149149
if( src.type() == _dst.type() )
150150
transpose(src, _dst);
@@ -158,7 +158,7 @@ void cv2eigen( const Mat& src,
158158
}
159159
else
160160
{
161-
const Mat _dst(src.rows, src.cols, DataType<_Tp>::type,
161+
const Mat _dst(src.rows, src.cols, traits::Type<_Tp>::value,
162162
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
163163
src.convertTo(_dst, _dst.type());
164164
}
@@ -172,13 +172,13 @@ void cv2eigen( const Matx<_Tp, _rows, _cols>& src,
172172
dst.resize(_rows, _cols);
173173
if( !(dst.Flags & Eigen::RowMajorBit) )
174174
{
175-
const Mat _dst(_cols, _rows, DataType<_Tp>::type,
175+
const Mat _dst(_cols, _rows, traits::Type<_Tp>::value,
176176
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
177177
transpose(src, _dst);
178178
}
179179
else
180180
{
181-
const Mat _dst(_rows, _cols, DataType<_Tp>::type,
181+
const Mat _dst(_rows, _cols, traits::Type<_Tp>::value,
182182
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
183183
Mat(src).copyTo(_dst);
184184
}
@@ -193,7 +193,7 @@ void cv2eigen( const Mat& src,
193193

194194
if( !(dst.Flags & Eigen::RowMajorBit) )
195195
{
196-
const Mat _dst(src.cols, src.rows, DataType<_Tp>::type,
196+
const Mat _dst(src.cols, src.rows, traits::Type<_Tp>::value,
197197
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
198198
if( src.type() == _dst.type() )
199199
transpose(src, _dst);
@@ -202,7 +202,7 @@ void cv2eigen( const Mat& src,
202202
}
203203
else
204204
{
205-
const Mat _dst(src.rows, src.cols, DataType<_Tp>::type,
205+
const Mat _dst(src.rows, src.cols, traits::Type<_Tp>::value,
206206
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
207207
src.convertTo(_dst, _dst.type());
208208
}
@@ -217,13 +217,13 @@ void cv2eigen( const Matx<_Tp, _rows, 1>& src,
217217

218218
if( !(dst.Flags & Eigen::RowMajorBit) )
219219
{
220-
const Mat _dst(1, _rows, DataType<_Tp>::type,
220+
const Mat _dst(1, _rows, traits::Type<_Tp>::value,
221221
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
222222
transpose(src, _dst);
223223
}
224224
else
225225
{
226-
const Mat _dst(_rows, 1, DataType<_Tp>::type,
226+
const Mat _dst(_rows, 1, traits::Type<_Tp>::value,
227227
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
228228
src.copyTo(_dst);
229229
}
@@ -238,7 +238,7 @@ void cv2eigen( const Mat& src,
238238
dst.resize(src.cols);
239239
if( !(dst.Flags & Eigen::RowMajorBit) )
240240
{
241-
const Mat _dst(src.cols, src.rows, DataType<_Tp>::type,
241+
const Mat _dst(src.cols, src.rows, traits::Type<_Tp>::value,
242242
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
243243
if( src.type() == _dst.type() )
244244
transpose(src, _dst);
@@ -247,7 +247,7 @@ void cv2eigen( const Mat& src,
247247
}
248248
else
249249
{
250-
const Mat _dst(src.rows, src.cols, DataType<_Tp>::type,
250+
const Mat _dst(src.rows, src.cols, traits::Type<_Tp>::value,
251251
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
252252
src.convertTo(_dst, _dst.type());
253253
}
@@ -261,13 +261,13 @@ void cv2eigen( const Matx<_Tp, 1, _cols>& src,
261261
dst.resize(_cols);
262262
if( !(dst.Flags & Eigen::RowMajorBit) )
263263
{
264-
const Mat _dst(_cols, 1, DataType<_Tp>::type,
264+
const Mat _dst(_cols, 1, traits::Type<_Tp>::value,
265265
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
266266
transpose(src, _dst);
267267
}
268268
else
269269
{
270-
const Mat _dst(1, _cols, DataType<_Tp>::type,
270+
const Mat _dst(1, _cols, traits::Type<_Tp>::value,
271271
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
272272
Mat(src).copyTo(_dst);
273273
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,6 +1531,11 @@ class CV_EXPORTS Mat
15311531
*/
15321532
template<typename _Tp> void push_back(const Mat_<_Tp>& elem);
15331533

1534+
/** @overload
1535+
@param elem Added element(s).
1536+
*/
1537+
template<typename _Tp> void push_back(const std::vector<_Tp>& elem);
1538+
15341539
/** @overload
15351540
@param m Added line(s).
15361541
*/
@@ -1661,7 +1666,7 @@ class CV_EXPORTS Mat
16611666
inv_scale = 1.f/alpha_scale;
16621667
16631668
CV_Assert( src1.type() == src2.type() &&
1664-
src1.type() == CV_MAKETYPE(DataType<T>::depth, 4) &&
1669+
src1.type() == CV_MAKETYPE(traits::Depth<T>::value, 4) &&
16651670
src1.size() == src2.size());
16661671
Size size = src1.size();
16671672
dst.create(size, src1.type());
@@ -1941,7 +1946,7 @@ class CV_EXPORTS Mat
19411946
inv_scale = 1.f/alpha_scale;
19421947
19431948
CV_Assert( src1.type() == src2.type() &&
1944-
src1.type() == DataType<VT>::type &&
1949+
src1.type() == traits::Type<VT>::value &&
19451950
src1.size() == src2.size());
19461951
Size size = src1.size();
19471952
dst.create(size, src1.type());

0 commit comments

Comments
 (0)