Merge pull request #754 from MikeTheWatchGuy/Dev-latest

Can change the parameters in realtime as video is being processed
This commit is contained in:
MikeTheWatchGuy 2018-11-21 08:40:19 -05:00 committed by GitHub
commit 12c006d8e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 8 deletions

View File

@ -9,8 +9,8 @@ import cv2
import os import os
import PySimpleGUI as sg import PySimpleGUI as sg
i_vid = r'videos/car_chase_01.mp4' i_vid = r'videos\car_chase_01.mp4'
o_vid = r'output/car_chase_01_out.mp4' o_vid = r'output\car_chase_01_out.mp4'
y_path = r'yolo-coco' y_path = r'yolo-coco'
sg.ChangeLookAndFeel('LightGreen') sg.ChangeLookAndFeel('LightGreen')
layout = [ layout = [
@ -40,7 +40,8 @@ win.Close()
# imgbytes = cv2.imencode('.png', image)[1].tobytes() # ditto # imgbytes = cv2.imencode('.png', image)[1].tobytes() # ditto
gui_confidence = args["confidence"]
gui_threshold = args["threshold"]
# load the COCO class labels our YOLO model was trained on # load the COCO class labels our YOLO model was trained on
labelsPath = os.path.sep.join([args["yolo"], "coco.names"]) labelsPath = os.path.sep.join([args["yolo"], "coco.names"])
LABELS = open(labelsPath).read().strip().split("\n") LABELS = open(labelsPath).read().strip().split("\n")
@ -86,11 +87,12 @@ win_started = False
if use_webcam: if use_webcam:
cap = cv2.VideoCapture(0) cap = cv2.VideoCapture(0)
while True: while True:
sg.TimerStart()
# read the next frame from the file or webcam # read the next frame from the file or webcam
if use_webcam: if use_webcam:
grabbed, frame = cap.read() grabbed, frame = cap.read()
else: else:
(grabbed, frame) = vs.read() grabbed, frame = vs.read()
# if the frame was not grabbed, then we have reached the end # if the frame was not grabbed, then we have reached the end
# of the stream # of the stream
@ -129,7 +131,7 @@ while True:
# filter out weak predictions by ensuring the detected # filter out weak predictions by ensuring the detected
# probability is greater than the minimum probability # probability is greater than the minimum probability
if confidence > args["confidence"]: if confidence > gui_confidence:
# scale the bounding box coordinates back relative to # scale the bounding box coordinates back relative to
# the size of the image, keeping in mind that YOLO # the size of the image, keeping in mind that YOLO
# actually returns the center (x, y)-coordinates of # actually returns the center (x, y)-coordinates of
@ -151,8 +153,7 @@ while True:
# apply non-maxima suppression to suppress weak, overlapping # apply non-maxima suppression to suppress weak, overlapping
# bounding boxes # bounding boxes
idxs = cv2.dnn.NMSBoxes(boxes, confidences, args["confidence"], idxs = cv2.dnn.NMSBoxes(boxes, confidences, gui_confidence, gui_threshold)
args["threshold"])
# ensure at least one detection exists # ensure at least one detection exists
if len(idxs) > 0: if len(idxs) > 0:
@ -193,6 +194,10 @@ while True:
layout = [ layout = [
[sg.Text('Yolo Output')], [sg.Text('Yolo Output')],
[sg.Image(data=imgbytes, key='_IMAGE_')], [sg.Image(data=imgbytes, key='_IMAGE_')],
[sg.Text('Confidence'),
sg.Slider(range=(0, 1), orientation='h', resolution=.1, default_value=.5, size=(15, 15), key='confidence')],
[sg.Text('Threshold'),
sg.Slider(range=(0, 1), orientation='h', resolution=.1, default_value=.3, size=(15, 15), key='threshold')],
[sg.Exit()] [sg.Exit()]
] ]
win = sg.Window('YOLO Output', win = sg.Window('YOLO Output',
@ -206,11 +211,14 @@ while True:
event, values = win.Read(timeout=0) event, values = win.Read(timeout=0)
if event is None or event == 'Exit': if event is None or event == 'Exit':
break break
gui_confidence = values['confidence']
gui_threshold = values['threshold']
sg.TimerStop()
win.Close() win.Close()
# release the file pointers # release the file pointers
print("[INFO] cleaning up...") print("[INFO] cleaning up...")
writer.release() writer.release() if writer is not None else None
vs.release() vs.release()