title: OpenCV RGB compare
body: <p>I'm trying to get the number of difference between two pictures.
  When I compare 2 images in gray scale, pixDiff &lt;> 0 but when it come to RGB, pixDiff is always 0.</p>
  
  <p>I used openCV's compare and also a custom loop.</p>
  
  <pre><code>Mat frame, oldFrame;
  cap &gt;&gt; oldFrame;
  
  if(analyseMod == MONOCHROME)
      cvtColor(oldFrame, oldFrame, CV_BGR2GRAY);
  
  nbChannels = oldFrame.channels();
  
  while(1)
  {
      pixDiff = 0;
      cap &gt;&gt; frame;
  
      //Test diff
      Mat diff;
      compare(oldFrame, frame, diff, CMP_NE);
      imshow("video 0", diff);
      imshow("video 1", frame);
  
      if(analyseMod == MONOCHROME)
      {
          cvtColor(frame, frame, CV_BGR2GRAY);
  
          for(int i=0; i&lt;frame.rows; i++)
              for(int j=0; j&lt;frame.cols; j++)
                  if(frame.at&lt;uchar&gt;(i,j) &lt; oldFrame.at&lt;uchar&gt;(i,j) - similarPixelTolerance || frame.at&lt;uchar&gt;(i,j) &gt; oldFrame.at&lt;uchar&gt;(i,j) + similarPixelTolerance)
                      pixDiff++;
      }
      else if(analyseMod == RGB)
      {
          uint8_t *f = (uint8_t *)frame.data;
          uint8_t *o = (uint8_t *)oldFrame.data;
  
          for(int i=0; i&lt;frame.rows; i++)
          {
              for(int j=0; j&lt;frame.cols; j++)
              {
                  if(f[nbChannels*i*frame.cols + j + RED] &lt; o[nbChannels*i*oldFrame.cols + j + RED])
                      pixDiff++;
              }
          }
      }          
  
      frame.copyTo(oldFrame);
  
      cout &lt;&lt; pixDiff;
      if(waitKey(30) &gt;= 0) break;
  }
  </code></pre>
  
  <p>Thx for help</p>