title: Exception Unhandled Error Scanning an Image with OpenCV Using .at() in c++
body: <p>I am trying to scan a grey scale image and determine the values of each pixel in that image using OpenCV. I am implementing a double for loop to iterate through each column row by row. I am then trying to read the pixel value at each iteration using OpenCV's function .at(). Below is my current code.</p>
  
  <pre><code>unsigned int column;
  unsigned int row;
  int pixel_value;
  int img_height = image.rows;
  int img_width = image.cols;
  
  for (row = 0; row &lt;= img_height; row++)
  {
      for (column = 0; column &lt;= img_width; column++)
      }
          pixel_value = grey_image.at&lt;uchar&gt;(row, column);
      }
  }
  </code></pre>
  
  <p>When I run this code I get this error:</p>
  
  <blockquote>
    <p>Unhandled exception at 0x00007FFFD9D9A388 in A2V2.exe: Microsoft C++ exception: cv::Exception at memory location 0x000000EB54EFEFD0. </p>
  </blockquote>
  
  <p>This error occurs at line 1107 in OpenCV's <em>mat.inl.hpp</em> file. During debugging I have stepped through the code and figured out that the inner for loop runs through completely. But after this happens once and <code>row</code> is incremented when the outer for loop runs once more is when the exception occurs.</p>
  
  <p>I have tried looking up the documentation for the function <code>.at</code> but I could not see anything I am doing wrong. I also tried looking up other ways to do this such as using <code>MatIterator_</code> and a double for loop configuration with pointers (I am not confident with pointers, I need to practice them, and apparently if you use pointers you have to do more checking to make sure you are passing through the right amount of <em>uchar</em> fields and skipping gaps???, what does this mean?), from this <a href="https://docs.opencv.org/2.4/doc/tutorials/core/how_to_scan_images/how_to_scan_images.html" rel="nofollow noreferrer">https://docs.opencv.org/2.4/doc/tutorials/core/how_to_scan_images/how_to_scan_images.html</a> tutorial. I tried looking up documentation on these too, but I am still confused as to how they work.</p>
  
  <p>I will appreciate any help, thank you for your time.</p>