Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- import numpy as np
- import imutils
- cap = cv2.VideoCapture('test4.mp4')
- clahe = cv2.createCLAHE(2.0, (8,8))
- history = 50
- fgbg = cv2.createBackgroundSubtractorMOG2(history=history, detectShadows=True)
- while cap.isOpened():
- frame = cap.read()[1]
- width, height = frame.shape[:2]
- frame = imutils.resize(frame, width=min(500, width))
- origin = frame.copy()
- hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
- for channel in range(3):
- hsv[:,:,channel] = clahe.apply(hsv[:,:,channel])
- fgmask = fgbg.apply(hsv, learningRate=1 / history)
- blur = cv2.medianBlur(fgmask, 5)
- cv2.imshow('mask', fgmask)
- cv2.imshow('hcv', hsv)
- cv2.imshow('origin', origin)
- k = cv2.waitKey(30) & 0xff
- if k == 27 or k == ord('q'):
- break
- cap.release()
- cv2.destroyAllWindows()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement