title: Open CV : Assertion failed while implementing SIFT
body: <p>I am trying to implement SIFT in studio 2013 and opencv 2.4. And I am getting the following error.</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)(i1*DataType&lt;_Tp&gt;::channels) &lt; (unsigned)(size.p[1]*channels()) &amp;&amp; ((((sizeof(size_t)&lt;&lt;28)|0x8442211)
  
  ((DataType&lt;_Tp&gt;::depth) &amp; ((1 &lt;&lt; 3) - 1))*4) &amp; 15) == elemSize1()) in unknown function, file C:\opencv231\build\include\opencv2/core/mat.hpp, line 552
  </code></pre>
  
  <p>I think the error is in this code :</p>
  
  <pre><code>    void FindMaxMin()
  {
  
      cout &lt;&lt; endl &lt;&lt; "IN findmaxmin  " &lt;&lt; endl;
      int i;
      int j;
      int xiter, yiter;
      for (i = 0; i &lt; 4; i++)
      {
          for (j = 1; j &lt; 3; j++)
          {
              middle = LOG_img[i][j];
              up = LOG_img[i][j - 1];
              down = LOG_img[i][j + 1];
  
              for (yiter = 1; yiter &lt; middle.rows-1; yiter++)
              {
                  for (xiter = 1; xiter &lt; middle.cols-1; xiter++)
                  {
                      cout &lt;&lt; i &lt;&lt; "  " &lt;&lt; j &lt;&lt; "  " &lt;&lt; yiter &lt;&lt; "  " &lt;&lt; xiter&lt;&lt; "  "&lt;&lt;endl;
                      double currentPixel = middle.at&lt;uchar&gt;(yiter, xiter);
                      cout &lt;&lt; "1 ";
                      // Check for a maximum
                      if (currentPixel&gt; middle.at&lt;uchar&gt;(yiter, xiter + 1) &amp;&amp;
                          currentPixel&gt; middle.at&lt;uchar&gt;(yiter, xiter - 1) &amp;&amp;
                          currentPixel &gt; middle.at&lt;uchar&gt;(yiter + 1, xiter) &amp;&amp;
                          currentPixel &gt; middle.at&lt;uchar&gt;(yiter + 1, xiter - 1) &amp;&amp;
                          currentPixel &gt; middle.at&lt;uchar&gt;(yiter, xiter + 1) &amp;&amp;
                          currentPixel &gt; middle.at&lt;uchar&gt;(yiter - 1, xiter) &amp;&amp;
                          currentPixel &gt; middle.at&lt;uchar&gt;(yiter - 1, xiter + 1) &amp;&amp;
                          currentPixel &gt; middle.at&lt;uchar&gt;(yiter - 1, xiter - 1) &amp;&amp;
  
                          currentPixel &gt; up.at&lt;uchar&gt;(yiter, xiter) &amp;&amp;
                          currentPixel &gt; up.at&lt;uchar&gt;(yiter, xiter + 1) &amp;&amp;
                          currentPixel &gt; up.at&lt;uchar&gt;(yiter, xiter - 1) &amp;&amp;
                          currentPixel &gt; up.at&lt;uchar&gt;(yiter + 1, xiter) &amp;&amp;
                          currentPixel &gt; up.at&lt;uchar&gt;(yiter + 1, xiter - 1) &amp;&amp;
                          currentPixel &gt; up.at&lt;uchar&gt;(yiter, xiter + 1) &amp;&amp;
                          currentPixel &gt; up.at&lt;uchar&gt;(yiter - 1, xiter) &amp;&amp;
                          currentPixel &gt; up.at&lt;uchar&gt;(yiter - 1, xiter + 1) &amp;&amp;
                          currentPixel &gt; up.at&lt;uchar&gt;(yiter - 1, xiter - 1) &amp;&amp;
  
                          currentPixel &gt; down.at&lt;uchar&gt;(yiter, xiter) &amp;&amp;
                          currentPixel &gt; down.at&lt;uchar&gt;(yiter, xiter + 1) &amp;&amp;
                          currentPixel &gt; down.at&lt;uchar&gt;(yiter, xiter - 1) &amp;&amp;
                          currentPixel &gt; down.at&lt;uchar&gt;(yiter + 1, xiter) &amp;&amp;
                          currentPixel &gt; down.at&lt;uchar&gt;(yiter + 1, xiter - 1) &amp;&amp;
                          currentPixel &gt; down.at&lt;uchar&gt;(yiter, xiter + 1) &amp;&amp;
                          currentPixel &gt; down.at&lt;uchar&gt;(yiter - 1, xiter) &amp;&amp;
                          currentPixel &gt; down.at&lt;uchar&gt;(yiter - 1, xiter + 1) &amp;&amp;
                          currentPixel &gt; down.at&lt;uchar&gt;(yiter - 1, xiter - 1)
                          )
                      {
                          cout &lt;&lt; "inside, updating extrema  ";
                          Extrema[i][j - 1].at&lt;uchar&gt;(xiter, yiter) = 255;
                      }
  
                      else if (currentPixel&lt; middle.at&lt;uchar&gt;(yiter, xiter + 1) &amp;&amp;
                          currentPixel&lt; middle.at&lt;uchar&gt;(yiter, xiter - 1) &amp;&amp;
                          currentPixel &lt; middle.at&lt;uchar&gt;(yiter + 1, xiter) &amp;&amp;
                          currentPixel &lt; middle.at&lt;uchar&gt;(yiter + 1, xiter - 1) &amp;&amp;
                          currentPixel &lt; middle.at&lt;uchar&gt;(yiter, xiter + 1) &amp;&amp;
                          currentPixel &lt; middle.at&lt;uchar&gt;(yiter - 1, xiter) &amp;&amp;
                          currentPixel &lt; middle.at&lt;uchar&gt;(yiter - 1, xiter + 1) &amp;&amp;
                          currentPixel &lt; middle.at&lt;uchar&gt;(yiter - 1, xiter - 1) &amp;&amp;
  
                          currentPixel &lt; up.at&lt;uchar&gt;(yiter, xiter) &amp;&amp;
                          currentPixel &lt; up.at&lt;uchar&gt;(yiter, xiter + 1) &amp;&amp;
                          currentPixel &lt; up.at&lt;uchar&gt;(yiter, xiter - 1) &amp;&amp;
                          currentPixel &lt; up.at&lt;uchar&gt;(yiter + 1, xiter) &amp;&amp;
                          currentPixel &lt; up.at&lt;uchar&gt;(yiter + 1, xiter - 1) &amp;&amp;
                          currentPixel &lt; up.at&lt;uchar&gt;(yiter, xiter + 1) &amp;&amp;
                          currentPixel &lt; up.at&lt;uchar&gt;(yiter - 1, xiter) &amp;&amp;
                          currentPixel &lt; up.at&lt;uchar&gt;(yiter - 1, xiter + 1) &amp;&amp;
                          currentPixel &lt; up.at&lt;uchar&gt;(yiter - 1, xiter - 1) &amp;&amp;
  
                          currentPixel &lt; down.at&lt;uchar&gt;(yiter, xiter) &amp;&amp;
                          currentPixel &lt; down.at&lt;uchar&gt;(yiter, xiter + 1) &amp;&amp;
                          currentPixel &lt; down.at&lt;uchar&gt;(yiter, xiter - 1) &amp;&amp;
                          currentPixel &lt; down.at&lt;uchar&gt;(yiter + 1, xiter) &amp;&amp;
                          currentPixel &lt; down.at&lt;uchar&gt;(yiter + 1, xiter - 1) &amp;&amp;
                          currentPixel &lt; down.at&lt;uchar&gt;(yiter, xiter + 1) &amp;&amp;
                          currentPixel &lt; down.at&lt;uchar&gt;(yiter - 1, xiter) &amp;&amp;
                          currentPixel &lt; down.at&lt;uchar&gt;(yiter - 1, xiter + 1) &amp;&amp;
                          currentPixel &lt; down.at&lt;uchar&gt;(yiter - 1, xiter - 1)
                          )
                      {
                          Extrema[i][j - 1].at&lt;uchar&gt;(xiter, yiter) = 255;
                      }
  
                      else
                          Extrema[i][j - 1].at&lt;uchar&gt;(xiter, yiter) = 0;
                  }
  
  
  
  
              }
          }
      }
  }
  </code></pre>
  
  <p>The code is printing    " IN findmaxmin"
                           0 1 1 1
  and then the error is occuring. I have checked the remaining code by commenting out this function, and the code works fine.</p>