title: Count the number of black pixels using ByteBuffer javacv
body: <p>I have use this code..I am new to <code>javacv</code> and I need to get the pixels one by one in a region and get the color of that pixel. Can I please know how to do it using the <code>ByteBuffer</code> ,because byte buffer can read pixel by pixel and I need to check whether the pixel is black or white...</p>
  
  <p>Can anyone please consider about this..I am really stuck here...</p>
  
  <pre><code>IplImage img=cvLoadImage("img\\ROI.jpg");
  
  
      CvScalar Black =  cvScalar(0, 0, 0, 0);
      CvScalar white =  cvScalar(255, 255, 255, 255);
      ByteBuffer buffer = img.getByteBuffer();
  
      for(int y = 0; y &lt; img.height(); y++) {
          for(int x = 0; x &lt; img.width(); x++) {
              int index = y * img.widthStep() + x * img.nChannels();
  
              // Used to read the pixel value - the 0xFF is needed to cast from
              // an unsigned byte to an int.
              int value = buffer.get(index) &amp; 0xFF;
  
              // Sets the pixel to a value (greyscale).
              buffer.put(index, (byte) value);
  
  
              // Sets the pixel to a value (RGB, stored in BGR order).
              //buffer.putInt(index, Black);
             // buffer.put(index + 1, white);
          }
  
  
      }
  </code></pre>