title: How to access image Data from a RGB image (3channel image) in opencv
body: <p>I am trying to take the imageData of image in this where w= width of image and h = height of image </p>
  
  <pre><code>for (int i = x; i &lt; x+h; i++) //height of frame pixels
  {
      for (int j = y; j &lt; y+w; j++)//width of frame pixels
      {
          int pos = i * w * Channels + j; //channels is 3 as rgb 
          // if any data exists
          if (data-&gt;imageData[pos]&gt;0) //Taking data (here is the problem how to take)
          {
              xPos += j;
              yPos += i;
              nPix++;
          }
      }
  }
  </code></pre>