Skip to content

Instantly share code, notes, and snippets.

@zhunhung
Last active October 17, 2019 15:01
Show Gist options
  • Save zhunhung/0e33cdb2d2d21a17eb5dfb82b680437c to your computer and use it in GitHub Desktop.
Save zhunhung/0e33cdb2d2d21a17eb5dfb82b680437c to your computer and use it in GitHub Desktop.
Example of using OpenCV colour segmentation
color = [211, 227, 191]
# Convert our image from BGR to HSV
hsv_img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
limit = np.uint8([[color]])
# Convert our color of choice to HSV as well
limit = cv2.cvtColor(limit,cv2.COLOR_BGR2HSV)[0][0]
mask = cv2.inRange(hsv_img, limit, limit)
# Filter for the colour
res = cv2.bitwise_and(img,img, mask= mask)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment