Created
September 18, 2018 12:15
-
-
Save socratesk/fd6354507ee3c9cc122655d7f391a5fb to your computer and use it in GitHub Desktop.
This snippet is used as part of blog post related to HSV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Initalize webcam. 0 starts built-in camera | |
cap = cv2.VideoCapture(0) | |
# Specify HSV range of Tennis Ball | |
ballHSVLower = np.array([25, 75, 85]) | |
ballHSVUpper = np.array([50, 220, 255]) | |
while True: | |
# Read captured webcam frame | |
_, frame = cap.read() | |
# Convert color frame into HSV | |
hsv_img = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) | |
# Threshold the HSV image to get Tennis ball only | |
mask = cv2.inRange(hsv_img, ballHSVLower, ballHSVUpper) | |
# Find contours from HSV masked image | |
_, contours, _ = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment