Popular Posts

May 22, 2020

Object Detection


How to Use the HSV Color Model
The HSV color wheel sometimes appears as a cone or cylinder, but always with these three components:
HUE
Hue is the color portion of the model, expressed as a number from 0 to 360 degrees:
  • Red falls between 0 and 60 degrees.
  • Yellow falls between 61 and 120 degrees.
  • Green falls between 121 and 180 degrees.
  • Cyan falls between 181 and 240 degrees.
  • Blue falls between 241 and 300 degrees.
  • Magenta falls between 301 and 360 degrees.
SATURATION
Saturation describes the amount of gray in a particular color, from 0 to 100 percent. Reducing this component toward zero introduces more gray and produces a faded effect. Sometimes, saturation appears as a range from 0 to 1, where 0 is gray, and 1 is a primary color.
VALUE (OR BRIGHTNESS)
Value works in conjunction with saturation and describes the brightness or intensity of the color, from 0 to 100 percent, where 0 is completely black, and 100 is the brightest and reveals the most color.
Uses of HSV
Designers use the HSV color model when selecting colors for paint or ink because HSV better represents how people relate to colors than the RGB color model does.
The HSV color wheel also contributes to high-quality graphics. Although less well-known than its RGB and CMYK cousins, the HSV approach is available in many high-end image editing software programs.
Selecting an HSV color begins with picking one of the available hues and then adjusting the shade and brightness values.



import cv2
import numpy as np

def nothing(x):
   
pass

#create trackbar
cv2.namedWindow("Tracking")
cv2.createTrackbar(
"LH", "Tracking", 0, 255, nothing)
cv2.createTrackbar(
"LS", "Tracking", 0, 255, nothing)
cv2.createTrackbar(
"LV", "Tracking", 0, 255, nothing)

cv2.createTrackbar(
"UH", "Tracking", 255, 255, nothing)
cv2.createTrackbar(
"US", "Tracking", 255, 255, nothing)
cv2.createTrackbar(
"UV", "Tracking", 255, 255, nothing)


while True:
    frame = cv2.imread(
'smarties.png')

    hsv = cv2.cvtColor(frame
, cv2.COLOR_BGR2HSV)
   
#get Trackbar values
   
l_h = cv2.getTrackbarPos("LH", "Tracking")
    l_s = cv2.getTrackbarPos(
"LS", "Tracking")
    l_v = cv2.getTrackbarPos(
"LV", "Tracking")

    u_h = cv2.getTrackbarPos(
"UH", "Tracking")
    u_s = cv2.getTrackbarPos(
"US", "Tracking")
    u_v = cv2.getTrackbarPos(
"UV", "Tracking")

    l_b = np.array([l_h
, l_s, l_v])
    u_b = np.array([u_h
, u_s, u_v])

    mask = cv2.inRange(hsv
, l_b, u_b)
    res = cv2.bitwise_and(frame
, frame, mask=mask)

    cv2.imshow(
"frame", frame)
    cv2.imshow(
"mask", mask)
    cv2.imshow(
"res", res)

    key = cv2.waitKey(
1)

   
if key==27:
       
break

cv2.destroyAllWindows()


No comments:

Post a Comment