Created
May 22, 2018 02:17
-
-
Save TonsOfFun/75cc04248d534a88c6dbcfd98be20033 to your computer and use it in GitHub Desktop.
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
# Defined bounds using https://github.com/jrosebr1/imutils/blob/master/bin/range-detector | |
leaf_lower = (29, 0, 0) | |
leaf_upper = (255, 255, 128) | |
def leaf_mask(bgr_image): | |
frame = imutils.resize(bgr_image, width=500) | |
blurred = cv2.GaussianBlur(frame, (11, 11), 0) | |
hsv = cv2.cvtColor(blurred, cv2.COLOR_BGR2HSV) | |
# construct a mask for the color "green", then perform | |
# a series of dilations and erosions to remove any small | |
# blobs left in the mask | |
mask = cv2.inRange(hsv, leaf_lower, leaf_upper) | |
mask = cv2.erode(mask, None, iterations=4) | |
mask = cv2.dilate(mask, None, iterations=2) | |
return mask |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment