1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 15:53:03 +04:00

fix#9570: implement mat ptr for generic types

The original template based mat ptr for indexing is not implemented,
add the similar implementation as uchar type, but cast to
user-defined type from the uchar pointer.
This commit is contained in:
tz70s
2017-10-10 13:28:07 +08:00
parent 92a0808379
commit 6c1247b38c
2 changed files with 48 additions and 0 deletions
@@ -1058,6 +1058,34 @@ const uchar* Mat::ptr(const int* idx) const
return p;
}
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)
{