Note that there are some explanatory texts on larger screens.

plurals
  1. POC++, how to load images and count pixels of certain colours
    primarykey
    data
    text
    <p>here's my problem:</p> <p>I'm looking for a way to import an image into C++ then traverse its pixels, incrementing a counter every time a pixel of a certain colour is found.</p> <p>I've done some research, but I haven't found anything particularly useful. <a href="http://openil.sourceforge.net/" rel="nofollow noreferrer" title="DevIL">DevIL</a> looks like a good option, but I'm not sure where to start.</p> <p>Here's a bit of C++/python pseudo-code hopefully illustrating what I'm trying to do:</p> <pre><code>for image in folder: A = 0; B = 0; for pixel in image: if (pixel == colourA) {A++} if (pixel == colourB) {B++} //Output the count of colours for each image outputToFile(A, B); </code></pre> <p>Does anyone have some tips on where to start?</p> <p>Thanks</p> <p>EDIT Some extra information: I'm using Windows 7 and all the images are .pngs</p> <p>EDIT2 I've got everything working, except actually finding out the colour of the current pixel. Currently I'm using this:</p> <pre><code>int blue = ((uchar *)(img-&gt;imageData + pixelX*img-&gt;widthStep))[pixelY*img-&gt;nChannels + 0]; </code></pre> <p>But it doesn't work, and I have no idea how it works. I haven't been able to find anything about this that I could understand. Could anyone point me in the right direction on how to find the RGB values of a certain pixel?</p> <p>Edit3 Done! For anyone who finds this trying to do a similar thing, most of my remaining questions and a fair bit of code can be found <a href="https://stackoverflow.com/questions/3851604/c-access-violation-using-opencv-to-get-rgb-value-of-pixel">here</a>. Thanks for the help!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload