def main():
    log.basicConfig(format='[$(levelname)s ] %(message)s', level=log.INFO, stream=sys.stdout)
    args = build_argparser().parse_args()
    num_cam = (args.num_cameras if args.num_cameras else 0)
    vid_src = args.file
    network_name = args.network_name
    input_layer = args.input_layer
    output_layer = args.output_layer
    input_dimension = args.frame_size
    ip_addr = args.ip
    port_no = args.port
    if ((not args.file) and (not args.num_cameras)):
        log.error('Please supply either the camera or the video file. Try -f for options')
        return
    if ((not ip_addr) or (not port_no)):
        log.error('Please supply valid IP and/or port number of OVMS server')
        return
    video_files = []
    if vid_src:
        if os.path.isdir(vid_src):
            for (r, d, f) in os.walk(vid_src):
                for f_ in f:
                    if ('.mp4' in f_):
                        video_files.append((r + f_))
        elif os.path.isfile(vid_src):
            if ('.mp4' in vid_src):
                video_files.append(vid_src)
    thr = ([None] * (num_cam + len(video_files)))
    disp_buf = {}
    for i in range(num_cam):
        disp_buf[i] = None
        thr[i] = threading.Thread(target=thread_function, args=(i, network_name, input_layer, output_layer, input_dimension, ip_addr, port_no, disp_buf, SRC_TYPE[0], None))
        thr[i].start()
    for i in range(num_cam, (num_cam + len(video_files))):
        disp_buf[i] = None
        thr[i] = threading.Thread(target=thread_function, args=(i, network_name, input_layer, output_layer, input_dimension, ip_addr, port_no, disp_buf, SRC_TYPE[1], video_files[(i - num_cam)]))
        thr[i].start()
    global exit_ok
    while (exit_ok == False):
        for i in range((num_cam + len(video_files))):
            if (disp_buf[i] is not None):
                cv2.imshow('Predictions {}'.format(i), disp_buf[i])
                disp_buf[i] = None
            if (cv2.waitKey(1) == ord('q')):
                exit_ok = True
                break
    for i in range(num_cam):
        thr[i].join()
    cv2.destroyAllWindows()
    log.warning('Good Bye!')
def main():
    log.basicConfig(format='[$(levelname)s ] %(message)s', level=log.INFO, stream=sys.stdout)
    args = build_argparser().parse_args()
    num_cam = (args.num_cameras if args.num_cameras else 0)
    vid_src = args.file
    network_name = args.network_name
    input_layer = args.input_layer
    output_layer = args.output_layer
    input_dimension = args.frame_size
    ip_addr = args.ip
    port_no = args.port
    if ((not args.file) and (not args.num_cameras)):
        log.error('Please supply either the camera or the video file. Try -f for options')
        return
    if ((not ip_addr) or (not port_no)):
        log.error('Please supply valid IP and/or port number of OVMS server')
        return
    video_files = []
    if vid_src:
        if os.path.isdir(vid_src):
            for (r, d, f) in os.walk(vid_src):
                for f_ in f:
                    if ('.mp4' in f_):
                        video_files.append((r + f_))
        elif os.path.isfile(vid_src):
            if ('.mp4' in vid_src):
                video_files.append(vid_src)
    thr = ([None] * (num_cam + len(video_files)))
    disp_buf = {}
    for i in range(num_cam):
        disp_buf[i] = None
        thr[i] = threading.Thread(target=thread_function, args=(i, network_name, input_layer, output_layer, input_dimension, ip_addr, port_no, disp_buf, SRC_TYPE[0], None))
        thr[i].start()
    for i in range(num_cam, (num_cam + len(video_files))):
        disp_buf[i] = None
        thr[i] = threading.Thread(target=thread_function, args=(i, network_name, input_layer, output_layer, input_dimension, ip_addr, port_no, disp_buf, SRC_TYPE[1], video_files[(i - num_cam)]))
        thr[i].start()
    global exit_ok
    while (exit_ok == False):
        for i in range((num_cam + len(video_files))):
            if (disp_buf[i] is not None):
                cv2.imshow('Predictions {}'.format(i), disp_buf[i])
                disp_buf[i] = None
            if (cv2.waitKey(1) == ord('q')):
                exit_ok = True
                break
    for i in range(num_cam):
        thr[i].join()
    cv2.destroyAllWindows()
    log.warning('Good Bye!')