title: ROI Assertion failed (C++ and openCV)
body: <p>I have a Student class and an imagehandler class (which as the opencv image handler)</p>
  
  <p>Student object has a field:</p>
  
  <pre><code>imagehandler img;
  </code></pre>
  
  <p>and in the imagehandler class there is a function to copy image from one image to another into a certain location.</p>
  
  <pre><code>void imagehandler::copy_paste_image(imagehandler&amp; dst, int xLoc, int yLoc){
   cv::Rect roi(xLoc, yLoc, m_image.size().width, m_image.size().height);
   cv::Mat imageROI (dst.m_image, roi);
   m_image.copyTo(imageROI);
  }
  </code></pre>
  
  <p>and the imagehandler class has a Mat object m_image:</p>
  
  <pre><code>private:
   cv::Mat m_image;
  </code></pre>
  
  <p>Now in the main, I have declared a new image through the imagehandler specified constructor.</p>
  
  <p>the constructor I use to make the image:</p>
  
  <pre><code>imagehandler::imagehandler(int width, int height)
  : m_image(width, height, CV_8UC3){
  
  
  }
  </code></pre>
  
  <p>in the main, I declare the image like this:</p>
  
  <pre><code>imagehandler CSImg((4*300), (320 * ceil((float)(numOfCSStudents/4))));
  </code></pre>
  
  <p>Trust me on this one: CSImg is way bigger than all of the images I want to input in it.</p>
  
  <p>Now I want to copy a certain student's picture and input it into CS Img. That's what I do:</p>
  
  <pre><code>studentsVector.at(i)-&gt;getImg().copy_paste_image(CSImg, CSWidthCount*300, CSHeightCount*320);
  </code></pre>
  
  <p>And I get this error:</p>
  
  <pre><code>OpenCV Error: Assertion failed (0 &lt;= roi.x &amp;&amp; 0 &lt;= roi.width &amp;&amp; roi.x + roi.width &lt;= m.cols &amp;&amp; 0 &lt;= roi.y &amp;&amp; 0 &lt;= roi.height &amp;&amp; roi.y + roi.height &lt;= m.rows) in Mat, file /build/buildd/opencv-2.3.1/modules/core/src/matrix.cpp, line 303
  terminate called after throwing an instance of 'cv::Exception'
    what():  /build/buildd/opencv-2.3.1/modules/core/src/matrix.cpp:303: error: (-215) 0 &lt;= roi.x &amp;&amp; 0 &lt;= roi.width &amp;&amp; roi.x + roi.width &lt;= m.cols &amp;&amp; 0 &lt;= roi.y &amp;&amp; 0 &lt;= roi.height &amp;&amp; roi.y + roi.height &lt;= m.rows in function Mat
  </code></pre>
  
  <p>I've noticed that this happens in roi, I have no clue why. I -am- a total beginner at openCV and I am doing this for homework.</p>
  
  <p>Thank you.
  If you need any further info please ask.</p>