more error resistant

This commit is contained in:
Askill 2019-11-23 12:14:19 +01:00
parent ddb6ead02f
commit 724b977549
1 changed files with 31 additions and 34 deletions

View File

@ -27,6 +27,7 @@ def increase_brightness(img, value=30):
return img return img
def compare(): def compare():
try:
url = config.stream url = config.stream
# construct the argument parser and parse the arguments # construct the argument parser and parse the arguments
ap = argparse.ArgumentParser() ap = argparse.ArgumentParser()
@ -49,7 +50,7 @@ def compare():
# loop over the frames of the video # loop over the frames of the video
while True: while True:
try: print(counter)
# grab the current frame and initialize the occupied/unoccupied # grab the current frame and initialize the occupied/unoccupied
# text # text
frame = vs.read() frame = vs.read()
@ -59,7 +60,7 @@ def compare():
# if the frame could not be grabbed, then we have reached the end # if the frame could not be grabbed, then we have reached the end
# of the video # of the video
if frame is None: if frame is None:
break retry("frame was none")
# resize the frame, convert it to grayscale, and blur it # resize the frame, convert it to grayscale, and blur it
frame = imutils.resize(frame, width=500) frame = imutils.resize(frame, width=500)
@ -107,20 +108,16 @@ def compare():
com.notify(location) com.notify(location)
print(text) print(text)
key = cv2.waitKey(1) & 0xFF
counter+=1 counter+=1
if counter % (framerate * delay) == 0: if counter % (framerate * delay) == 0:
firstFrame = gray firstFrame = gray
except Exception as e: except Exception as e:
print(e) retry(e)
# cleanup the camera and close any open windows # cleanup the camera and close any open windows
#vs.stop() if args.get("video", None) is None else vs.release() vs.stop() if args.get("video", None) is None else vs.release()
def retry(error):
print(error)
time.sleep(10)
compare()