title: Color percentage in image for Python using OpenCV
body: <p>I'm creating a code which can detect the percentage of green colour from an image.</p>
  <p><img src="https://i.stack.imgur.com/Ue7Yi.jpg" alt="image" />.</p>
  <p>I have a little experience with OpenCV but am still pretty new to image processing and would like some help with my code. How should I change this code so that it is capable of calculating the percentage of green instead of brown? And if it isn't too troublesome could someone please explain how the changes affect the code? Below is the link to the image I would like to use.
  Credit for the code goes to @mmensing</p>
  <pre class="lang-py prettyprint-override"><code>import numpy as np
  import cv2
  
  img = cv2.imread('potato.jpg')
  
  brown = [145, 80, 40]  # RGB
  diff = 20
  boundaries = [([brown[2]-diff, brown[1]-diff, brown[0]-diff],
                 [brown[2]+diff, brown[1]+diff, brown[0]+diff])]
  
  for (lower, upper) in boundaries:
      lower = np.array(lower, dtype=np.uint8)
      upper = np.array(upper, dtype=np.uint8)
      mask = cv2.inRange(img, lower, upper)
      output = cv2.bitwise_and(img, img, mask=mask)
  
      ratio_brown = cv2.countNonZero(mask)/(img.size/3)
      print('brown pixel percentage:', np.round(ratio_brown*100, 2))
  
      cv2.imshow(&quot;images&quot;, np.hstack([img, output]))
      cv2.waitKey(0)
  </code></pre>