Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import sys
- import cv2
- import numpy as np
- file_or_dev = sys.argv[1] if len(sys.argv) > 1 else 0
- def nothing(*arg):
- pass
- cv2.namedWindow('dvs')
- cv2.createTrackbar('T', 'dvs', 10, 100, nothing)
- cap = cv2.VideoCapture(file_or_dev)
- _, img = cap.read()
- prev = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) >> 1
- while 1:
- _, img = cap.read()
- gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) >> 1
- diff = 128 + prev - gray
- prev = gray
- cv2.imshow('diff', diff.astype('uint8'))
- # cv2.imwrite('diff.%05i.png'%inc, diff.astype('uint8'))
- T = cv2.getTrackbarPos('T', 'dvs')
- img[...,0] = 0 # img is BGR
- img[...,1] = np.where(diff > (128 + T), diff, 0)
- img[...,2] = np.where(diff < (128 - T), 255 - diff, 0)
- cv2.imshow('dvs', img)
- if cv2.waitKey(1) == 27:
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement