Skip to content

Instantly share code, notes, and snippets.

@amarlearning
Created July 28, 2018 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amarlearning/14a1b6cd4a291c3e4d4c8a93e2bc39d9 to your computer and use it in GitHub Desktop.
Save amarlearning/14a1b6cd4a291c3e4d4c8a93e2bc39d9 to your computer and use it in GitHub Desktop.
def hist_masking(frame, hist):
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
dst = cv2.calcBackProject([hsv], [0, 1], hist, [0, 180, 0, 256], 1)
disc = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (31, 31))
cv2.filter2D(dst, -1, disc, dst)
ret, thresh = cv2.threshold(dst, 150, 255, cv2.THRESH_BINARY)
thresh = cv2.merge((thresh, thresh, thresh))
return cv2.bitwise_and(frame, thresh)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment