}
template<typename _Tp> inline
+_Tp* Mat::ptr(const int* idx)
+{
+ int i, d = dims;
+ uchar* p = data;
+ CV_DbgAssert( d >= 1 && p );
+ for( i = 0; i < d; i++ )
+ {
+ CV_DbgAssert( (unsigned)idx[i] < (unsigned)size.p[i] );
+ p += idx[i] * step.p[i];
+ }
+ return (_Tp*)p;
+}
+
+template<typename _Tp> inline
+const _Tp* Mat::ptr(const int* idx) const
+{
+ int i, d = dims;
+ uchar* p = data;
+ CV_DbgAssert( d >= 1 && p );
+ for( i = 0; i < d; i++ )
+ {
+ CV_DbgAssert( (unsigned)idx[i] < (unsigned)size.p[i] );
+ p += idx[i] * step.p[i];
+ }
+ return (const _Tp*)p;
+}
+
+template<typename _Tp> inline
_Tp& Mat::at(int i0, int i1)
{
CV_DbgAssert(dims <= 2);
ASSERT_DOUBLE_EQ(norm(A, B, NORM_INF), 0.);
}
+
+TEST(Mat, template_based_ptr)
+{
+ Mat mat = (Mat_<float>(2, 2) << 11.0f, 22.0f, 33.0f, 44.0f);
+ int idx[2] = {1, 0};
+ ASSERT_FLOAT_EQ(33.0f, *(mat.ptr<float>(idx)));
+ idx[0] = 1;
+ idx[1] = 1;
+ ASSERT_FLOAT_EQ(44.0f, *(mat.ptr<float>(idx)));
+}
+
+TEST(Mat_, template_based_ptr)
+{
+ int dim[4] = {2, 2, 1, 2};
+ Mat_<float> mat = (Mat_<float>(4, dim) << 11.0f, 22.0f, 33.0f, 44.0f,
+ 55.0f, 66.0f, 77.0f, 88.0f);
+ int idx[4] = {1, 0, 0, 1};
+ ASSERT_FLOAT_EQ(66.0f, *(mat.ptr<float>(idx)));
+}
+
#endif