Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import sys
  3. import cv2
  4. import numpy as np
  5.  
  6. file_or_dev = sys.argv[1] if len(sys.argv) > 1 else 0
  7.  
  8. def nothing(*arg):
  9. pass
  10.  
  11. cv2.namedWindow('dvs')
  12. cv2.createTrackbar('T', 'dvs', 10, 100, nothing)
  13.  
  14. cap = cv2.VideoCapture(file_or_dev)
  15. _, img = cap.read()
  16. prev = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) >> 1
  17. while 1:
  18. _, img = cap.read()
  19. gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) >> 1
  20. diff = 128 + prev - gray
  21. prev = gray
  22. cv2.imshow('diff', diff.astype('uint8'))
  23. # cv2.imwrite('diff.%05i.png'%inc, diff.astype('uint8'))
  24. T = cv2.getTrackbarPos('T', 'dvs')
  25. img[...,0] = 0 # img is BGR
  26. img[...,1] = np.where(diff > (128 + T), diff, 0)
  27. img[...,2] = np.where(diff < (128 - T), 255 - diff, 0)
  28. cv2.imshow('dvs', img)
  29. if cv2.waitKey(1) == 27:
  30. break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement