OpenCV

OpenCV documentation:

HSV color-space (OpenCV):
  • Hue (H) -> [0, 179]
  • Saturation (S) -> [0, 255] 
  • Value (V) -> [0, 255] 
# Convert BGR frame to HSV
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

Convert BGR color/pixel to HSV
green_bgr = np.uint8([[[0,255,0 ]]])
green_hsv = cv2.cvtColor(green_bgr,cv2.COLOR_BGR2HSV) 

print green_hsv

# Threshold the HSV image to get only blue colors
mask = cv2.inRange(hsv, lower_blue, upper_blue)

# Image Histogram:
  • is a graphical representation of the intensity distribution of an image
  • quantifies the number of pixels for each intensity value
hist = cv2.calcHist(images, channels, mask, histSize, ranges[, hist[, accumulate]])
hist = cv2.calcHist([gray_img],[0],None,[256],[0,256])
  • images: source image of type uint8 or float32. it should be given in as a list, ie, [gray_img].
  • channels: it is also given in as a list []. It the index of channel for which we calculate histogram. For example, if input is grayscale image, its value is [0]. For color image, you can pass [0],[1] or [2] to calculate histogram of blue,green or red channel, respectively.
  • mask: mask image. To find histogram of full image, it is set as None. However, if we want to get histogram of specific region of image, we should create a mask image for that and give it as mask.
  • histSize: this represents our BIN count. Need to be given in []. For full scale, we pass [256].
  • ranges: Normally, it is [0,256].