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,29 +27,30 @@ def increase_brightness(img, value=30):
return img return img
def compare(): def compare():
url = config.stream try:
# construct the argument parser and parse the arguments url = config.stream
ap = argparse.ArgumentParser() # construct the argument parser and parse the arguments
ap.add_argument("-v", "--video", help="path to the video file") ap = argparse.ArgumentParser()
ap.add_argument("-amin", "--min-area", type=int, default=3000, help="minimum area size") ap.add_argument("-v", "--video", help="path to the video file")
ap.add_argument("-amax", "--max-area", type=int, default=10000, help="minimum area size") ap.add_argument("-amin", "--min-area", type=int, default=3000, help="minimum area size")
args = vars(ap.parse_args()) ap.add_argument("-amax", "--max-area", type=int, default=10000, help="minimum area size")
args = vars(ap.parse_args())
# if the video argument is None, then we are reading from webcam # if the video argument is None, then we are reading from webcam
args["video"] = url args["video"] = url
#args["video"] = "./videos/example_02.mp4" #args["video"] = "./videos/example_02.mp4"
vs = cv2.VideoCapture(args["video"]) vs = cv2.VideoCapture(args["video"])
counter = 0 counter = 0
threashold = 18 threashold = 18
delay = .3 delay = .3
framerate = 30 framerate = 30
# initialize the first frame in the video stream # initialize the first frame in the video stream
firstFrame = None firstFrame = None
# 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()