Created
September 6, 2019 08:11
-
-
Save PierrickKoch/953ef052a5f60f1f13d0a15711609714 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment