title: Determining the type of Matrix in OpenCV
body: <p>I'm trying to index a 3 channel image in opencv.</p>
  
  <p>When I read in image files this code works</p>
  
  <pre><code>int Blue  = LeftCol.at&lt;cv::Vec3b&gt;(v,u)[0];
  int Green = LeftCol.at&lt;cv::Vec3b&gt;(v,u)[1]; 
  int Red   = LeftCol.at&lt;cv::Vec3b&gt;(v,u)[2]; 
  </code></pre>
  
  <p>But it crashes when I use a webcam input. The webcam has 3 channels and <code>u,v</code> starts at <code>0,0</code>.
  I have no idea why it won't work.
  I've tried all variations of <code>Vec3b</code>, <code>Vec3i</code>, <code>Vec3s</code>, <code>Vec3f</code>, <code>Vec3d</code></p>
  
  <p>I'm lost.... why can't I index this webcam image?</p>
  
  <h2>EDIT</h2>
  
  <p>Right so after many hours this is where I've got to...here's an outline of the program. I was having the problem I mentioned above inside a function. So I've gone back to basic, trying to look at the matrix before the function...</p>
  
  <pre><code>void main (int argc, char** argv) {
  Mat LeftCol;
  while (1==1) {
      if (ProgramMode == "Files") {
          //read in the colour images
          LeftCol  = imread(ColImLeft.c_str(),1);
          RightCol = imread(ColImRight.c_str(),1);
  
      } else if (ProgramMode == "Camera") {
          VideoCapture CapLeft, CapRight;
          CapLeft.open(1);
          CapRight.open(2);
  
          CapLeft  &gt;&gt; LeftCol;
          CapRight &gt;&gt; RightCol;
  
                      //THIS WORKS, THIS PIXEL VALUES ARE DISPLAYED
          cout &lt;&lt; "uchar" &lt;&lt; endl;
          for (int x=0;x&lt;10;x++) {
              for (int y=0;y&lt;10;y++) {
                  int pixel = LeftCol.at&lt;cv::Vec3b&gt;(x,y)[0];
                  cout &lt;&lt; pixel;
              }
              cout &lt;&lt; endl;
          }
      } //end if
  
              ///////ADDED THIS BIT ////////
      cout &lt;&lt; "channels = " &lt;&lt; LeftCol.channels() &lt;&lt; endl;
              //^^This bit works, output shows "channels = 3"
  
              //vv This bit doesn't work.... so there's a problem with LeftCol.
              //I wonder if reading the data like CapLeft  &gt;&gt; LeftCol; is changing something
      imshow("Test",LeftCol);
              ///////ADDED THIS BIT ////////
  
             //THIS DOES NOT WORK WHEN USING THE CAMERA INPUT, PROGRAM CRASHES
      cout &lt;&lt; "uchar" &lt;&lt; endl;
      for (int x=0;x&lt;10;x++) {
          for (int y=0;y&lt;10;y++) {
              int pixel = LeftCol.at&lt;cv::Vec3b&gt;(x,y)[0];
              cout &lt;&lt; pixel;
          } //end for
          cout &lt;&lt; endl;
      } //end for
  
     } //end while
  } //end main
  </code></pre>
  
  <p>Right I have got it working but it's not ideal. I'm creating a temp <code>Mat</code> to read the files into it then cloning them.</p>
  
  <pre><code>        Mat TempLeft;
          Mat TempRight;
  
          VideoCapture CapLeft, CapRight;
          CapLeft.open(1);
          CapRight.open(2);
  
          CapLeft  &gt;&gt; TempLeft;
          CapRight &gt;&gt; TempRight;
  
          LeftCol = TempLeft.clone();
          RightCol = TempRight.clone();
  </code></pre>