Advertisement
Guest User

Untitled

a guest
Sep 5th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. import cv2
  2. import numpy as np
  3. import imutils
  4.  
  5.  
  6. cap = cv2.VideoCapture('test4.mp4')
  7. clahe = cv2.createCLAHE(2.0, (8,8))
  8.  
  9. history = 50
  10. fgbg = cv2.createBackgroundSubtractorMOG2(history=history, detectShadows=True)
  11.  
  12. while cap.isOpened():
  13. frame = cap.read()[1]
  14. width, height = frame.shape[:2]
  15. frame = imutils.resize(frame, width=min(500, width))
  16. origin = frame.copy()
  17. hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
  18.  
  19. for channel in range(3):
  20. hsv[:,:,channel] = clahe.apply(hsv[:,:,channel])
  21.  
  22. fgmask = fgbg.apply(hsv, learningRate=1 / history)
  23. blur = cv2.medianBlur(fgmask, 5)
  24.  
  25. cv2.imshow('mask', fgmask)
  26. cv2.imshow('hcv', hsv)
  27. cv2.imshow('origin', origin)
  28. k = cv2.waitKey(30) & 0xff
  29. if k == 27 or k == ord('q'):
  30. break
  31.  
  32. cap.release()
  33. cv2.destroyAllWindows()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement