Index: include/opencv/cxmat.hpp =================================================================== --- include/opencv/cxmat.hpp (revision 2588) +++ include/opencv/cxmat.hpp (working copy) @@ -3376,8 +3376,11 @@ Point pt = pos(); int cols = m->cols; ofs += pt.y*cols + pt.x; - if( ofs > cols*m->rows ) - ofs = cols*m->rows; + if( ofs > cols*m->rows ) // end of matrix + { + ptr = sliceEnd = (_Tp*)(m->data + m->step*(m->rows-1)) + cols; + return *this; + } else if( ofs < 0 ) ofs = 0; pt.y = ofs/cols;