title: debug assertion failed vc\include\vector vector iterator + offset out of range in chamferMatching Opencv
body: <p>I am stuck with the problem while implementing chamfer matching program in OpenCV </p>
  
  <p>https:// code.ros.org/trac/opencv/browser/trunk/opencv/samples/cpp/chamfer.cpp?rev=4194</p>
  
  <p>Following is the code it is reading 
  template image </p>
  
  <p><img src="https://i.stack.imgur.com/662x2.png" alt="http://img593.imageshack.us/img593/6391/5klx.png"></p>
  
  <p>and test image
  <img src="https://i.stack.imgur.com/Z4KWJ.png" alt="http://img5.imageshack.us/img5/6619/u76z.png"></p>
  
  <p>, I am using VS 2008 and OpenCV2.4.6</p>
  
  <pre><code>#include "stdafx.h"
  
  #include &lt;opencv2/imgproc/imgproc.hpp&gt;
  #include &lt;opencv2/highgui/highgui.hpp&gt;
  #include &lt;opencv2/contrib/contrib.hpp&gt;
  #include &lt;iostream&gt;
  using namespace cv;
  using namespace std;
  
  int main( int argc, char** argv )
  {    
      IplImage *src;
      src = cvLoadImage("C:\\Users\\JOSHI\\Desktop\\Images\\logo_in_clutter.png",1);      
      Mat img=cvarrToMat(src);  
      imshow("Mat",img); 
  
      src = cvLoadImage("C:\\Users\\JOSHI\\Desktop\\Images\\logo.png",1);  
      Mat tpl=cvarrToMat(src);  
      imshow("Mat",tpl); 
      Mat cimg;
  
      // if the image and the template are not edge maps but normal grayscale images,
      // you might want to uncomment the lines below to produce the maps. You can also
      // run Sobel instead of Canny.    
       Canny(img, img, 5, 50, 3);
       Canny(tpl, tpl, 5, 50, 3);    
      vector&lt;vector&lt;Point&gt; &gt; results;
      vector&lt;float&gt; costs;
      int best = chamerMatching( img, tpl, results, costs );
      if( best &lt; 0 )
      {
          cout &lt;&lt; "not found;\n";
          return 0;
      }    
      size_t i, n = results[best].size();
      for( i = 0; i &lt; n; i++ )
      {
          Point pt = results[best][i];
          if( pt.inside(Rect(0, 0, cimg.cols, cimg.rows)) )
             cimg.at&lt;Vec3b&gt;(pt) = Vec3b(0, 255, 0);
      }
      imshow("result", cimg);
  
      waitKey();
      return 0;
  }
  </code></pre>
  
  <p>this is the error image 
  <img src="https://i.stack.imgur.com/rShCK.png" alt="http:// img138.imageshack.us/img138/7339/m1d.png"></p>
  
  <p>can you suggest me why I am getting this error as I am new to OpenCV and Image Processing</p>