Пример #1
0
def print_usage():
    """Prints usage information for the program.

    :return: None
    """
    labels = SsdMobileNetProcessor.get_classification_labels()

    print('\nusage: ')
    print('python3 run_video.py [help][resize_window=<width>x<height>]')
    print('')
    print('options:')
    print('  help - prints this message')
    print('  resize_window - resizes the GUI window to specified dimensions')
    print('                  must be formated similar to resize_window=1280x720')
    print('                  Default isto not resize, use size of video frames.')
    print('  init_min_score - set the minimum score for a box to be recognized')
    print('                  must be a number between 0 and 100 inclusive.')
    print('                  Default is: ' + str(DEFAULT_INIT_MIN_SCORE))

    print('  exclude_classes - comma separated list of object class IDs to exclude from following:')
    index = 0
    for oneLabel in labels:
        print("                 class ID " + str(index) + ": " + oneLabel)
        index += 1
    print('            must be a number between 0 and ' + str(len(labels)-1) + ' inclusive.')
    print('            Default is to exclude none.')

    print('')
    print('Example: ')
    print('python3 run_video.py resize_window=1920x1080 init_min_score=50 exclude_classes=5,11')
def handle_args():
    """Reads the commandline args and adjusts initial values of globals values to match

    :return: False if there was an error with the args, or True if args processed ok.
    """
    global resize_output, resize_output_width, resize_output_height, min_score_percent, object_classifications_mask

    labels = SsdMobileNetProcessor.get_classification_labels()

    for an_arg in argv:
        if (an_arg == argv[0]):
            continue

        elif (str(an_arg).lower() == 'help'):
            return False

        elif (str(an_arg).lower().startswith('exclude_classes=')):
            try:
                arg, val = str(an_arg).split('=', 1)
                exclude_list = str(val).split(',')
                for exclude_id_str in exclude_list:
                    exclude_id = int(exclude_id_str)
                    if (exclude_id < 0 or exclude_id > len(labels)):
                        print("invalid exclude_classes= parameter")
                        return False
                    print("Excluding class ID " + str(exclude_id) + " : " +
                          labels[exclude_id])
                    object_classifications_mask[int(exclude_id)] = 0
            except:
                print('Error with exclude_classes argument. ')
                return False

        elif (str(an_arg).lower().startswith('init_min_score=')):
            try:
                arg, val = str(an_arg).split('=', 1)
                init_min_score_str = val
                init_min_score = int(init_min_score_str)
                if (init_min_score < 0 or init_min_score > 100):
                    print(
                        'Error with init_min_score argument.  It must be between 0-100'
                    )
                    return False
                min_score_percent = init_min_score
                print('Initial Minimum Score: ' + str(min_score_percent) +
                      ' %')
            except:
                print(
                    'Error with init_min_score argument.  It must be between 0-100'
                )
                return False

        elif (str(an_arg).lower().startswith('resize_window=')):
            try:
                arg, val = str(an_arg).split('=', 1)
                width_height = str(val).split('x', 1)
                resize_output_width = int(width_height[0])
                resize_output_height = int(width_height[1])
                resize_output = True
                print('GUI window resize now on: \n  width = ' +
                      str(resize_output_width) + '\n  height = ' +
                      str(resize_output_height))
            except:
                print('Error with resize_window argument: "' + an_arg + '"')
                return False
        else:
            return False

    return True
def print_usage():
    """Prints usage information for the program.

    :return: None
    """
    labels = SsdMobileNetProcessor.get_classification_labels()

    print('\nusage: ')
    print('python3 run_video.py [help][resize_window=<width>x<height>]')
    print('')
    print('options:')

    print('  help - Prints this message')
    print('  resize_window - Resizes the GUI window to specified dimensions')
    print(
        '                  must be formated similar to resize_window=1280x720')
    print(
        '                  Default isto not resize, use size of video frames.')

    print(
        '  init_min_score - Set the minimum score for a box to be recognized')
    print('                   must be a number between 0 and 100 inclusive.')
    print('                   Default is: ' + str(DEFAULT_INIT_MIN_SCORE))

    print(
        "  show_fps - Show or do not show the Frames Per Second while running")
    print("             must be 'True' or 'False'.")
    print("             Default is: " + str(DEFAULT_SHOW_FPS))

    print(
        "  device_count - The number of devices to use for inferencing.  If there are "
    )
    print(
        "                 more devices in the system than specified here then the extra"
    )
    print(
        "                 devices will by cycled in and out of use, but no more than"
    )
    print(
        "                 this many devices will be used at a time.  Must be between 1 and "
    )
    print("                 the total number of devices in the system.")
    print("                 Default is to use all devices in the system. ")

    print(
        "  show_device_count - Show or do not show the number of devices in use while running"
    )
    print("             must be 'True' or 'False'.")
    print("             Default is: " + str(DEFAULT_SHOW_NCS_COUNT))

    print("  rest_seconds - The number of seconds to wait between movies ")
    print(
        "                 when devices are throttling a multiplier will be applied."
    )
    print("                 This must be a positive integer.")
    print("                 Default is: " + str(DEFAULT_REST_SECONDS))

    print(
        "  throttle_check_seconds - The number of seconds between throttle checking during long movies "
    )
    print("                 This must be a positive integer.")
    print("                 Default is: " +
          str(DEFAULT_THROTTLE_CHECK_SECONDS))

    print(
        '  exclude_classes - Comma separated list of object class IDs to exclude from following:'
    )
    index = 0
    for oneLabel in labels:
        print("                 class ID " + str(index) + ": " + oneLabel)
        index += 1
    print('            must be a number between 0 and ' +
          str(len(labels) - 1) + ' inclusive.')
    print('            Default is to exclude none.')

    print('')
    print('Example: ')
    print(
        'python3 video_objects_scalable.py resize_window=1920x1080 init_min_score=50 show_fps=False device_count=2 show_device_count=True rest_seconds=20 throttle_check_seconds=10.0 exclude_classes=5,11'
    )
def handle_args():
    """Reads the commandline args and adjusts initial values of globals values to match

    :return: False if there was an error with the args, or True if args processed ok.
    """
    global resize_output, resize_output_width, resize_output_height, min_score_percent, object_classifications_mask,\
           show_fps, show_device_count, device_count, rest_seconds, throttle_check_seconds

    labels = SsdMobileNetProcessor.get_classification_labels()

    for an_arg in argv:
        if (an_arg == argv[0]):
            continue

        elif (str(an_arg).lower() == 'help'):
            return False

        elif (str(an_arg).lower().startswith('exclude_classes=')):
            try:
                arg, val = str(an_arg).split('=', 1)
                exclude_list = str(val).split(',')
                for exclude_id_str in exclude_list:
                    exclude_id = int(exclude_id_str)
                    if (exclude_id < 0 or exclude_id > len(labels)):
                        print("invalid exclude_classes= parameter")
                        return False
                    print("Excluding class ID " + str(exclude_id) + " : " +
                          labels[exclude_id])
                    object_classifications_mask[int(exclude_id)] = 0
            except:
                print('Error with exclude_classes argument. ')
                return False

        elif (str(an_arg).lower().startswith('device_count=')):
            try:
                arg, val = str(an_arg).split('=', 1)
                device_count_str = val
                device_count = int(device_count_str)
                if (device_count < 0):
                    print('Error with device_count argument.  It must be > 0')
                    return False
                print('Device count: ' + str(device_count))
            except:
                print(
                    'Error with device count argument.  It must be between 1 and number of devices'
                )
                return False

        elif (str(an_arg).lower().startswith('rest_seconds=')):
            try:
                arg, val = str(an_arg).split('=', 1)
                rest_seconds_str = val
                rest_seconds = int(rest_seconds_str)
                if (rest_seconds < 0):
                    print('Error with rest_seconds argument.  It must be > 0')
                    return False
                print('Rest Seconds: ' + str(rest_seconds))
            except:
                print(
                    'Error with rest seconds argument.  It must be between 1 and number of devices'
                )
                return False

        elif (str(an_arg).lower().startswith('throttle_check_seconds=')):
            try:
                arg, val = str(an_arg).split('=', 1)
                throttle_check_seconds_str = val
                throttle_check_seconds = float(throttle_check_seconds_str)
                if (throttle_check_seconds < 0):
                    print(
                        'Error with throttle_check_seconds argument.  It must be > 0'
                    )
                    return False
                print('Throttle Check Seconds: ' + str(throttle_check_seconds))
            except:
                print(
                    'Error with throttle check seconds argument.  It must be between 1 and number of devices'
                )
                return False

        elif (str(an_arg).lower().startswith('init_min_score=')):
            try:
                arg, val = str(an_arg).split('=', 1)
                init_min_score_str = val
                init_min_score = int(init_min_score_str)
                if (init_min_score < 0 or init_min_score > 100):
                    print(
                        'Error with init_min_score argument.  It must be between 0-100'
                    )
                    return False
                min_score_percent = init_min_score
                print('Initial Minimum Score: ' + str(min_score_percent) +
                      ' %')
            except:
                print(
                    'Error with init_min_score argument.  It must be between 0-100'
                )
                return False

        elif (str(an_arg).lower().startswith('show_fps=')):
            try:
                arg, val = str(an_arg).split('=', 1)
                show_fps = (val.lower() == 'true')
                print('show_fps: ' + str(show_fps))
            except:
                print(
                    "Error with show_fps argument.  It must be 'True' or 'False' "
                )
                return False

        elif (str(an_arg).lower().startswith('show_device_count=')):
            try:
                arg, val = str(an_arg).split('=', 1)
                show_device_count = (val.lower() == 'true')
                print('show_device_count: ' + str(show_device_count))
            except:
                print(
                    "Error with show_device_count argument.  It must be 'True' or 'False' "
                )
                return False

        elif (str(an_arg).lower().startswith('resize_window=')):
            try:
                arg, val = str(an_arg).split('=', 1)
                width_height = str(val).split('x', 1)
                resize_output_width = int(width_height[0])
                resize_output_height = int(width_height[1])
                resize_output = True
                print('GUI window resize now on: \n  width = ' +
                      str(resize_output_width) + '\n  height = ' +
                      str(resize_output_height))
            except:
                print('Error with resize_window argument: "' + an_arg + '"')
                return False
        else:
            return False

    return True