diff --git a/modules/core/include/opencv2/core/mat.inl.hpp b/modules/core/include/opencv2/core/mat.inl.hpp index 49357555de..fffb860f18 100644 --- a/modules/core/include/opencv2/core/mat.inl.hpp +++ b/modules/core/include/opencv2/core/mat.inl.hpp @@ -898,6 +898,33 @@ const _Tp* Mat::ptr(const int* idx) const return (const _Tp*)p; } +template inline +uchar* Mat::ptr(const Vec& idx) +{ + return Mat::ptr(idx.val); +} + +template inline +const uchar* Mat::ptr(const Vec& idx) const +{ + return Mat::ptr(idx.val); +} + +template inline +_Tp* Mat::ptr(const Vec& idx) +{ + CV_DbgAssert( elemSize() == sizeof(_Tp) ); + return Mat::ptr<_Tp>(idx.val); +} + +template inline +const _Tp* Mat::ptr(const Vec& idx) const +{ + CV_DbgAssert( elemSize() == sizeof(_Tp) ); + return Mat::ptr<_Tp>(idx.val); +} + + template inline _Tp& Mat::at(int i0, int i1) { diff --git a/modules/core/test/test_mat.cpp b/modules/core/test/test_mat.cpp index 2afd926bd1..4f7cbb6725 100644 --- a/modules/core/test/test_mat.cpp +++ b/modules/core/test/test_mat.cpp @@ -2365,4 +2365,20 @@ TEST(Mat, regression_18473) } +TEST(Mat, ptrVecni_20044) +{ + Mat_ m(3,4); m << 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12; + Vec2i idx(1,1); + + uchar *u = m.ptr(idx); + EXPECT_EQ(int(6), *(int*)(u)); + const uchar *cu = m.ptr(idx); + EXPECT_EQ(int(6), *(int*)(cu)); + + int *i = m.ptr(idx); + EXPECT_EQ(int(6), *(i)); + const int *ci = m.ptr(idx); + EXPECT_EQ(int(6), *(ci)); +} + }} // namespace