diff --git a/modules/objdetect/src/hog.cpp b/modules/objdetect/src/hog.cpp
index 9b6c30f89a101204c214058d10a4f3466e9dd281..43911c50d1e31404d3e04598586a9caa4acead4a 100644
--- a/modules/objdetect/src/hog.cpp
+++ b/modules/objdetect/src/hog.cpp
@@ -200,10 +200,10 @@ void HOGDescriptor::computeGradient(const Mat& img, Mat& grad, Mat& qangle,
 
     for( x = -1; x < gradsize.width + 1; x++ )
         xmap[x] = borderInterpolate(x - paddingTL.width + roiofs.x,
-                        wholeSize.width, borderType);
+                        wholeSize.width, borderType) - roiofs.x;
     for( y = -1; y < gradsize.height + 1; y++ )
         ymap[y] = borderInterpolate(y - paddingTL.height + roiofs.y,
-                        wholeSize.height, borderType);
+                        wholeSize.height, borderType) - roiofs.y;
 
     // x- & y- derivatives for the whole row
     int width = gradsize.width;