title: python - opencv - convert pixel from bgr to hsv
body: <pre><code>img = cv2.imread('example.jpg')
  img_hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
  # lower mask (0-10)
  lower_red = np.array([0, 50, 50])
  upper_red = np.array([10, 255, 255]
  mask0 = cv2.inRange(img_hsv, lower_red, upper_red)
  # upper mask (170-180)
  lower_red = np.array([170, 50, 50])
  upper_red = np.array([180, 255, 255])
  mask1 = cv2.inRange(img_hsv, lower_red, upper_red)
  # join my masks
  mask = mask0 + mask1
  
  height = mask.shape[0]
  width = mask.shape[1]
  # iterate over every pixel
  for i in range(height):
      for j in range(width):
          px = mask[i,j]
          print px
          # check if pixel is white or black
          if (px[2] &gt;= 0 and px[2] &lt;= 40):
  </code></pre>
  
  <p>In the above example 'px' is a pixel in BGR. I need to convert the value to HSV because I want to check if the pixel is in a certain color range.</p>
  
  <p>I already tried </p>
  
  <pre><code>colorsys.rgb_to_hsv(px[2], px[1], px[0})
  </code></pre>
  
  <p>which evokes the error: invalid index to scalar variable</p>
  
  <p>Thanks!</p>