title: OpenCV: Accessing elements of 5D Matrix
body: <p>I have a problem accessing elements of a 5D Matrix in OpenCV. I create my Matrix using</p>
  
  <pre><code>int sizes[5] = { height_, width_, range_, range_, range_ };
  Mat w_i_ = Mat(2 + channels, sizes, CV_16UC(channels), Scalar(0));
  </code></pre>
  
  <p>where channels = 3. Then I'm trying to access and modify the matrix elements using for loops:</p>
  
  <pre><code>for (UINT Y = 0; Y &lt; height; ++Y) {
      for (UINT X = 0; X &lt; width; ++X) {
  
          // a) Compute the homogeneous vector (wi,w)
          Vec3b wi = image.at&lt;Vec3b&gt;(Y, X);
  
          // b) Compute the downsampled coordinates
          UINT y = round(Y / sigmaSpatial);
          UINT x = round(X / sigmaSpatial);
          Vec3b zeta = round( (image.at&lt;Vec3b&gt;(Y, X) - min) / sigmaRange);
                         // round() here is overloaded for vectors
  
          // c) Update the downsampled S×R space
          int idx[5] = { y, x, zeta[0], zeta[1], zeta[2] };
          w_i_.at&lt;Vec3b&gt;(idx) = wi;
      }
  }
  </code></pre>
  
  <p>I am getting an assertion failed error produced by Mat::at() when I run the code. Specifically the message I get is:</p>
  
  <pre><code>OpenCV Error: Assertion failed (elemSize() == (((((DataType&lt;_Tp&gt;::type) &amp; ((512 - 1) &lt;&lt; 3)) &gt;&gt; 3) + 1) &lt;&lt; ((((sizeof(size_t)/4+1)*16384|0x3a50) &gt;&gt; ((DataType&lt;_Tp&gt;::type) &amp; ((1 &lt;&lt; 3) - 1))*2) &amp; 3))) in cv::Mat::at, file c:\opencv\build\include\opencv2\core\mat.inl.hpp, line 1003
  </code></pre>
  
  <p>I have searched the web but I can't seem to find any topics on 5D Matrices (similar topics proved of no help).</p>
  
  <p>Thanks in advance</p>