title: Changing brightness and contrast of an image
body: <p>I am working on the following code</p>
  
  <pre><code>#include &lt;opencv2/core/core.hpp&gt;
  #include &lt;opencv2/highgui/highgui.hpp&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  using namespace cv;
  
  Mat change(Mat m);
  
  int main()
  
  {
      Mat image = imread("C:/Users/Public/Pictures/Sample Pictures/Penguins.jpg");
  
      Mat copy = Mat::zeros(image.size(),image.type());
  
      Mat changedImage = change(copy);
  
      namedWindow("Image");
      imshow("Image",changedImage);
  
      waitKey(0);
  }
  
  Mat change(Mat m)
  {
      int cols = m.cols;
      int rows = m.rows;
  
      double alpha = 2.2;
      int beta = 50;
  
  
      for(int i=0;i&lt;rows;i++)
      {
          for(int c=0;c&lt;cols;c++)
          {
              m.at&lt;Vec3b&gt;(rows,c)[0] = saturate_cast&lt;uchar&gt;(alpha* (m.at&lt;Vec3b&gt;(rows,cols)[0]) + beta);
              m.at&lt;Vec3b&gt;(rows,c)[1] = saturate_cast&lt;uchar&gt;(alpha* (m.at&lt;Vec3b&gt;(rows,cols)[1]) + beta);
              m.at&lt;Vec3b&gt;(rows,c)[2] = saturate_cast&lt;uchar&gt;(alpha* (m.at&lt;Vec3b&gt;(rows,cols)[2]) + beta);
          }
      }
  
      return m;
  
  }
  </code></pre>
  
  <p>This compiles fine, but when I run this, I get the following error</p>
  
  <pre><code>    OpenCV Error: Assertion failed (dims &lt;= 2 &amp;&amp; data &amp;&amp; (unsigned)i0 &lt; (unsigned)si
  ze.p[0] &amp;&amp; (unsigned)(i1*DataType&lt;_Tp&gt;::channels) &lt; (unsigned)(size.p[1]*channel
  s()) &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 unknown function, file c:\opencv\build\inclu
  de\opencv2\core\mat.hpp, line 534
  </code></pre>
  
  <p>Why I am getting this? I guess I have done everything correctly.</p>