diff --git a/modules/ximgproc/src/find_ellipses.cpp b/modules/ximgproc/src/find_ellipses.cpp index b5ab61e793..3164aa26f4 100644 --- a/modules/ximgproc/src/find_ellipses.cpp +++ b/modules/ximgproc/src/find_ellipses.cpp @@ -1301,12 +1301,12 @@ void EllipseDetectorImpl::preProcessing(Mat1b &src, Mat1b &dp, Mat1b &dn) { // 2 - the pixel does belong to an edge for (int i = 0; i <= imgSize.height; i++) { int *tmpMag = magBuffer[(i > 0) + 1] + 1; - const short *tmpDx = dx.ptr(i); - const short *tmpDy = dy.ptr(i); uchar *tmpMap; int prevFlag = 0; if (i < imgSize.height) { + const short *tmpDx = dx.ptr(i); + const short *tmpDy = dy.ptr(i); tmpMag[-1] = tmpMag[imgSize.width] = 0; for (int j = 0; j < imgSize.width; j++) tmpMag[j] = abs(tmpDx[j]) + abs(tmpDy[j]); @@ -1322,8 +1322,8 @@ void EllipseDetectorImpl::preProcessing(Mat1b &src, Mat1b &dp, Mat1b &dn) { tmpMap[-1] = tmpMap[imgSize.width] = 1; tmpMag = magBuffer[1] + 1; // take the central row - tmpDx = (short *) (dx[i - 1]); - tmpDy = (short *) (dy[i - 1]); + const short *tmpDx = dx.ptr(i - 1); + const short *tmpDy = dy.ptr(i - 1); ptrdiff_t magStep1, magStep2; magStep1 = magBuffer[2] - magBuffer[1];