Skip to content

Instantly share code, notes, and snippets.

@demacdolincoln
Created April 14, 2016 21:08
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 demacdolincoln/ddc838186fdb2cb89690ea7900332817 to your computer and use it in GitHub Desktop.
Save demacdolincoln/ddc838186fdb2cb89690ea7900332817 to your computer and use it in GitHub Desktop.
"""
dependências:
* python2
* opencv
* numpy
* matplotlib
"""
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
while True:
_, frame = cap.read()
# _, thr = cv2.threshold(frame, 12, 120, cv2.THRESH_BINARY_INV)
# grayscale = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# gauss = cv2.adaptiveThreshold(grayscale,
# 255,
# cv2.ADAPTIVE_THRESH_MEAN_C,
# cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
# cv2.THRESH_BINARY_INV, 155, 1)
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
low = np.array([160,10,0])
up = np.array([190,255,255])
mask = cv2.inRange(hsv, low, up)
res = cv2.bitwise_and(frame, frame, mask=mask)
cv2.imshow("cam",frame)
# cv2.imshow("thresh",thr)
# cv2.imshow("gauss",gauss)
cv2.imshow("mask",mask)
cv2.imshow("res",res)
if cv2.waitKey(2) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment