title: I'm trying to display the percentage of red color in my image with OpenCV and Python
body: <p>I'm fairly new to both OpenCV and Python and I'm trying to calculate the number of red pixels and display it as a percent. However, it keeps displaying 0% even though there is a lot of red in the picture. Could someone please help me out?</p>
  
  <p>This is what I have so far, </p>
  
  <pre><code>import cv2
  import numpy as np
  
  img = cv2.imread('roi.jpg')
  size = img.size
  
  
  RED_MIN = np.array([0,0,128], np.uint8)
  RED_MAX = np.array([250, 250, 255], np.uint8)
  
  
  dstr = cv2.inRange(img, RED_MIN, RED_MAX)
  no_red = cv2.countNonZero(dstr)
  frac_red = np.divide((int(no_red)),(int(size)))
  percent_red = np.multiply((int(frac_red)), 100)
  print('Red: ' + str(percent_red) + '%')
  </code></pre>