Created
March 25, 2016 12:45
-
-
Save ylh888/4bb893a4142a2b9a32fc 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
# import the necessary packages | |
from imutils.video import VideoStream | |
from numpy import * | |
import datetime | |
import argparse | |
import imutils | |
import time | |
import cv2 | |
def improc (src): | |
p0 = cv2.cvtColor( src, cv2.COLOR_BGR2GRAY ) | |
p1 = cv2.blur( p0, (7,7) ) | |
cv2.equalizeHist( p1, p0 ) | |
return p0 | |
def cpBigframe (i, frame): | |
bigframe[ :, i*wd:(i+1)*wd] = frame[:,:] | |
return | |
vs = VideoStream(0).start() | |
# def parameters and init | |
ht,wd=360,480 # 600/400 | |
#bigframe = zeros( (300, 800, 3), uint8 ) #[0:600, 0:400] | |
#bigframe = zeros( (ht, wd*2), uint8 ) #[0:600, 0:400] | |
bigframe = zeros( (ht, wd*3), uint8 ) #[0:600, 0:400] | |
template1 = template2 = zeros( (ht, wd), uint8 ) #[0:600, 0:400] | |
# loop over the frames from the video stream | |
tick = 0 | |
while True: | |
time.sleep(0.03) | |
# grab the frame from the threaded video stream and resize it | |
# to have a maximum width of 400 pixels | |
try: | |
frame = vs.read() | |
frame = imutils.resize(frame, width=wd) | |
cv2.imshow("Eye Scope", frame) | |
processed = improc( frame ) # from color to b&w | |
cpBigframe(0, processed) | |
cpBigframe(1, template1) | |
cpBigframe(2, template2) | |
# draw the timestamp on the frame | |
timestamp = datetime.datetime.now() | |
ts = timestamp.strftime("%Y-%m-%d %a %H:%M:%S") | |
cv2.putText(bigframe, ts, (10, bigframe.shape[0] - 10), cv2.FONT_HERSHEY_SIMPLEX, | |
0.35, (0, 0, 255), 1) | |
# show the frame | |
cv2.imshow("Processed", bigframe) | |
key = cv2.waitKey(1) & 0xFF | |
if key == ord("1"): | |
template1 = processed | |
if key == ord("2"): | |
template2 = processed | |
# if the `q` key was pressed, break from the loop | |
if key == ord("q"): | |
break | |
finally: | |
""" | |
if ( tick ): | |
tick = False | |
print ( "\r-", end="", flush=True ) | |
else: | |
tick = True | |
print ( "\r|", end="", flush=True ) | |
""" | |
# do a bit of cleanup | |
cv2.destroyAllWindows() | |
vs.stop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment