title: Accessing pixel value with .at<uchar> and .at<Vec3b> does not work
body: <p>I am trying to rewrite the value for a pixel in a Mat-type grayscale image using Visual Studio Express 2012 for Windows Desktop. I've tried:</p>
  
  <pre><code>imgGrayComp.at&lt;uchar&gt;(5, 4) = 0; 
  </code></pre>
  
  <p>.</p>
  
  <pre><code>imgGrayComp.ptr(4)[5] = 0; 
  </code></pre>
  
  <p>.</p>
  
  <pre><code>imgGrayComp.at&lt;Vec3b&gt;(5, 4) = 0;
  </code></pre>
  
  <p>But it gives me this instead:</p>
  
  <pre><code>OpenCV Error: Assertion failed (dims &lt;= 2 &amp;&amp; data &amp;&amp; (unsigned)i0 &lt; (unsigned)size.p[0] &amp;&amp; (unsigned)(i1DataType&lt;_Tp&gt;::channels) &lt; (unsigned)(size.p[1]channels()) &amp;&amp; ((((sizeof(size_t)&lt;&lt;28)|0x8442211) &gt;&gt; ((DataType&lt;_Tp&gt;::depth) &amp; ((1 &lt;&lt; 3) - 1))*4) &amp; 15) == elemSize1()) in cv::Mat::at, file c:\opencv\build\include\opencv2\core\mat.hpp, line 537
  </code></pre>
  
  <p>==========================================================================================</p>
  
  <p>EDIT - Here's the code:</p>
  
  <p>Calling classify():</p>
  
  <pre><code>classify("./src/0.jpg", contour, hierarchy, mDatabase, '0');
  </code></pre>
  
  <p>In classify():</p>
  
  <pre><code>void classify(std::string imageFile, 
      vector&lt;vector&lt;Point&gt; &gt; contour,
      vector&lt;Vec4i&gt; hierarchy, float mDatabase [][charsToClassify],
      char whichChar)
  {
      Mat image = imread(imageFile, 1);
      Mat imageGrayClassify;
  
      image.convertTo(imageGrayClassify, COLOR_BGR2GRAY);
      int numPoints = computeNumContourPts(imageGrayClassify); // calling compute...()
  }
  </code></pre>
  
  <p>In compute...():</p>
  
  <pre><code>int computeNumContourPts(Mat imgGrayComp)
  {
  
      // dilation x1 (increases workload):
      dilate(imgGrayComp, imgGrayComp, Mat(), Point(-1,-1), 2);
      // erosion x1 (decreases workload):
      erode(imgGrayComp, imgGrayComp, Mat(), Point(-1,-1), 1);
  
      imgGrayComp.at&lt;uchar&gt;(5, 4) = 0;
  }
  </code></pre>