For accessing single point, I am using this line of code and it works

```
int intensity = gray_image.at<uchar>(Point(100, 100));

```

However when I use this code to access all the pixels in image, it gives memory error,

```
for (int i = 0; i < gray_image.rows;i++)
{
    for (int j = 0; j < gray_image.cols; j++) {
        intensity += gray_image.at<uchar>(Point(i, j));
    }
}

```

When I run above code, it does not give compile time error but gives memory exception. Where am I going wrong?