Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- import numpy as np
- cap = cv2.cv2.VideoCapture(0)
- kernel = np.ones((5,5), np.uint8)
- while True:
- ret, frame = cap.read()
- rangomax = np.array([50,255,50])
- rangomin = np.array([0, 51, 0])
- mascara = cv2.cv2.inRange(frame, rangomin, rangomax)
- opening = cv2.cv2.morphologyEx(mascara, cv2.cv2.MORPH_OPEN, kernel)
- x,y,w,h = cv2.cv2.boundingRect(opening)
- cv2.cv2.rectangle(frame, (x,y), (x+w, y+h), (0,255,0), 3)
- cv2.cv2.circle(frame,(x+w/2, y+h/2), 5,(0,0,255), -1)
- cv2.cv2.imshow('video', frame)
- k = cv2.cv2.waitKey(1) & 0xFF
- if k == 27:
- break
- cap.release()
Add Comment
Please, Sign In to add comment