title: Image Borders & Corners C++
body: <p>I'm working on openCV C++ project ,</p>
  
  <p>Part of my project requires to point at any pixel of image with my mouse, get it's x, and y coordinates then I should copy a 8*8 Block of pixels around this pixel to apply some image processing functions for this block.</p>
  
  <p>This is a part of my code that take 8*8 block around pixel:</p>
  
  <pre><code>cv::Mat foo = Mat(8, 8, CV_8UC3);
  foo = img3.colRange(x-4, x + 4).rowRange(y-4, y + 4);
  </code></pre>
  
  <p>But now I have a problem with image borders; if the mouse on a pixel near one of image borders or corners I have an exception because the range of col &amp; rows (The Block size becomes bigger than existing  image).</p>
  
  <p>How can I solve this problem?</p>