Repository: opencv
Issue: Hog compute `Access violation` and `has triggered a breakpoint`
Labels: bug,category: objdetect,confirmed

### System Information

OpenCV version: 4.7.0
Operating System / Platform: windows 10
Compiler & compiler version:  visual studio  2019


### Detailed description

```
Exception thrown at 0x00007FF8B99FD8A8 (opencv_objdetect470d.dll)
 in example_cpp_train_HOG.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
```

![image](https://user-images.githubusercontent.com/13716351/236436954-60fe2a3f-0fa9-43a5-a06e-8dda3d7fc3ec.png)


### Steps to reproduce

```
static void GetHog(int width, int height, HOGDescriptor& hog, int pixelPerCell = 8)
{
    width = width - (width % pixelPerCell);
    height = height - (height % pixelPerCell);
    Size winSize = Size(width, height);
    Size blockSize = Size(width, height);
    Size blockStride = Size(pixelPerCell, pixelPerCell);
    Size cellSize = Size(pixelPerCell, pixelPerCell);
    hog = HOGDescriptor(winSize, blockSize, blockStride, cellSize, 9);
}

int main(int argc, char** argv)
{
    Mat src = Mat(Size(198, 281), CV_8UC1);
    HOGDescriptor hog1;
    GetHog(src.cols, src.rows, hog1);
    std::vector<float> descriptors;
    hog1.compute(src, descriptors);
    return 0;
}

```
If src size **198, 271** or **2400, 2400** there is no error, if src size **2399, 2400** hes error.

Such a correction in hog.cpp line 697 solves the problem:
```
        {
            AutoBuffer<float> di(blockSize.height), dj(blockSize.width);
            float* _di = di.data(), * _dj = dj.data();
            float bh = blockSize.height * 0.5f, bw = blockSize.width * 0.5f;

            i = 0;
#if CV_SIMD128
           v_float32x4 idx(0.0f, 1.0f, 2.0f, 3.0f);
            v_float32x4 _bw = v_setall_f32(bw), _bh = v_setall_f32(bh);
            v_float32x4 ifour = v_setall_f32(4.0);

            for (; i <= blockSize.height - 4; i += 4)
            {
                v_float32x4 t = idx - _bh;
                t *= t;
                idx += ifour;
                v_store(_di + i, t);
            }
#endif
            for (; i < blockSize.height; ++i)
            {
                _di[i] = i - bh;
                _di[i] *= _di[i];
            }

            j = 0;
#if CV_SIMD128
            /*idx = v_float32x4(0.0f, 1.0f, 2.0f, 3.0f);

            for (; j <= blockSize.height - 4; j += 4)
            {
                v_float32x4 t = idx - _bw;
                t *= t;
                idx += ifour;
                v_store(_dj + j, t);
            }*/
#endif
            for (; j < blockSize.width; ++j)
            {
                _dj[j] = j - bw;
                _dj[j] *= _dj[j];
            }

            for (i = 0; i < blockSize.height; i++)
                for (j = 0; j < blockSize.width; j++)
                    weights(i, j) = std::exp(-(_di[i] + _dj[j]) * scale);
        }
```

### Issue submission checklist

- [X] I report the issue, it's not a question
- [x] I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
- [x] I updated to the latest OpenCV version and the issue is still there
- [x] There is reproducer code and related data files (videos, images, onnx, etc)