python - How to detect black and gray from an image -


i trying program detect hue of black (and slight gray), having difficulties trying find upper hue vector (the upper_hue variable) allow me extract hues of black out extracting other colors. seems work pictures black shoes or umbrella, there has problems photos of roads brightness varies.

i trying find upper hue range allow program robust against this, risks getting non-black colors.

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

what upper hue vector of values black , gray. if isn't issue, way solve this?

code:

import cv2 import numpy np import imutils  def color_seg(choice):     if choice == 'blue':         lower_hue = np.array([100,30,30])         upper_hue = np.array([150,148,255])     elif choice == 'white':         lower_hue = np.array([0,0,0])         upper_hue = np.array([0,0,255])     elif choice == 'black':         lower_hue = np.array([0,0,0])         upper_hue = np.array([50,50,100])     return lower_hue, upper_hue   # take each frame frame = cv2.imread('images/black0.jpg') #frame = cv2.imread('images/road_1.jpg')  frame = imutils.resize(frame, height = 300) chosen_color = 'black'   # convert bgr hsv hsv = cv2.cvtcolor(frame, cv2.color_bgr2hsv)  # define range of color in hsv lower_hue, upper_hue = color_seg(chosen_color)   # threshold hsv image blue colors mask = cv2.inrange(hsv, lower_hue, upper_hue)   cv2.imshow('frame',frame) cv2.imshow('mask',mask)  cv2.waitkey(0) 


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

android - Go back to previous fragment -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -