Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Without understanding your measurement of greenness, the lines which computes the measurement is:</p> <pre><code>nCombinedVal = (pixelPtr[nPixelPos +2]) *( 255 - pixelPtr[nPixelPos +1]); </code></pre> <p>The nPixelPos is the index to the pixel. If the image follows the OpenCV BGR convention +1 will give you the green channel and +2 gives you the red channel. If it follows the RGB convention, +1 will still be green but +2 will be blue.</p> <p><strike>To change detected color to red, my best guess would be to replace +1 with +2 and change +2 to +1 or +0. Be sure to modify both lines.</p> <pre><code>nCombinedVal = (pixelPtr[nPixelPos +1]) *( 255 - pixelPtr[nPixelPos +2]); </code></pre> <p></strike></p> <p>If you would be willing to replace the code, I would suggest a different measurement of color:</p> <pre><code>greenness = green - max(red, blue) redness = red - max(green, blue) blueness = blue - max(red, green) </code></pre> <p><strike> Which would look something like this in your code:</p> <pre><code>for(int i = 0; i &lt; img_output.rows; i++) { for(int j = 0; j &lt; img_output.cols; j++) { nPixelPos = i*img_output.cols*cn + j*cn; int greenness = int(pixelPtr[nPixelPos +1]) - max(pixelPtr[nPixelPos], pixelPtr[nPixelPos +2]); if (greeness &gt; 10) { pixelPtr1[nPixelPos + 0] = 255; pixelPtr1[nPixelPos + 1] = 255; pixelPtr1[nPixelPos + 2] = 255; } else { pixelPtr1[nPixelPos + 0] = 0; pixelPtr1[nPixelPos + 1] = 0; pixelPtr1[nPixelPos + 2] = 0; } } } </code></pre> <p></strike></p> <p><strong>EDIT:</strong> OpenCV stores HSV color information in reversed order and divides hue by two to fit into a byte (more details <a href="http://docs.opencv.org/modules/imgproc/doc/miscellaneous_transformations.html?highlight=cvtcolor#cvtcolor" rel="nofollow">here</a>). pixelPtr[nPixelPos +2] is therefore the hue and pixelPtr[nPixelPos +1] is the saturation. To change the color you are looking for, replace the row with something like this:</p> <pre><code>nCombinedVal = abs(pixelPtr[nPixelPos +2]-target_hue) *( 255 - pixelPtr[nPixelPos +1]); </code></pre> <p>Where target_hue is the hue you want to find divided by two.</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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