Skip to content

Commit 7e12c87

Browse files
committed
core: extend traits::Type / traits::Depth for compatible types
DMatch and Keypoint are not compatible types (mixed float/int fields)
1 parent 72f789b commit 7e12c87

File tree

6 files changed

+146
-64
lines changed

6 files changed

+146
-64
lines changed

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/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/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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,7 +1666,7 @@ class CV_EXPORTS Mat
16661666
inv_scale = 1.f/alpha_scale;
16671667
16681668
CV_Assert( src1.type() == src2.type() &&
1669-
src1.type() == CV_MAKETYPE(DataType<T>::depth, 4) &&
1669+
src1.type() == CV_MAKETYPE(traits::Depth<T>::value, 4) &&
16701670
src1.size() == src2.size());
16711671
Size size = src1.size();
16721672
dst.create(size, src1.type());
@@ -1946,7 +1946,7 @@ class CV_EXPORTS Mat
19461946
inv_scale = 1.f/alpha_scale;
19471947
19481948
CV_Assert( src1.type() == src2.type() &&
1949-
src1.type() == DataType<VT>::type &&
1949+
src1.type() == traits::Type<VT>::value &&
19501950
src1.size() == src2.size());
19511951
Size size = src1.size();
19521952
dst.create(size, src1.type());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1665,7 +1665,7 @@ void Mat_<_Tp>::release()
16651665
{
16661666
Mat::release();
16671667
#ifdef _DEBUG
1668-
flags = (flags & ~CV_MAT_TYPE_MASK) | DataType<_Tp>::type;
1668+
flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value;
16691669
#endif
16701670
}
16711671

0 commit comments

Comments
 (0)