Ejemplo n.º 1
0
def parse_config():
    parser = argparse.ArgumentParser()
    parser.add_argument("target", help="Target CPTV or MP3 file to process")
    args = parser.parse_args()
    config = Config.load_from_file(None)
    config.extract.preview = "none"

    if os.path.splitext(args.target)[1].lower() == ".cptv":
        # run single source
        source_file = tools.find_file_from_cmd_line(config.source_folder, args.target)

    return config, source_file
Ejemplo n.º 2
0
def main():
    parser = argparse.ArgumentParser()

    parser.add_argument(
        'source',
        help=
        'a CPTV file to process, or a folder name, or "all" for all files within subdirectories of source folder.'
    )
    parser.add_argument('-p',
                        '--create-previews',
                        action='count',
                        help='Create MP4 previews for tracks (can be slow)')
    parser.add_argument('-v',
                        '--verbose',
                        action='count',
                        help='Display additional information.')
    parser.add_argument(
        '--start-date',
        help=
        'Only clips on or after this day will be processed (format YYYY-MM-DD)'
    )
    parser.add_argument(
        '--end-date',
        help=
        'Only clips on or before this day will be processed (format YYYY-MM-DD)'
    )
    parser.add_argument('-c',
                        '--config-file',
                        help="Path to config file to use")
    parser.add_argument(
        '--processor-folder',
        help=
        "When running from thermal-processing use this to specify the folder for both the source cptv and output mp4. With this option the metadata will be sent to stdout."
    )

    args = parser.parse_args()
    config = Config.load_from_file(args.config_file)

    # parse command line arguments
    if args.create_previews:
        config.classify.preview = Previewer.PREVIEW_CLASSIFIED

    if args.verbose:
        config.classify_tracking.verbose = True

    if args.processor_folder:
        config.classify.meta_to_stdout = True
        config.base_data_folder = args.processor_folder
        config.classify.classify_folder = args.processor_folder
        config.source_folder = args.processor_folder

    clip_classifier = ClipClassifier(config, config.classify_tracking)

    # parse start and end dates
    if args.start_date:
        clip_classifier.start_date = datetime.strptime(args.start_date,
                                                       "%Y-%m-%d")
    if args.end_date:
        clip_classifier.end_date = datetime.strptime(args.end_date, "%Y-%m-%d")

    if not config.classify.meta_to_stdout:
        log_to_stdout()

    if config.classify.preview != Previewer.PREVIEW_NONE:
        logging.info("Creating previews")

    if not config.use_gpu:
        logging.info("GPU mode disabled.")

    if not os.path.exists(config.classify.model + ".meta"):
        logging.error(
            "No model found named '{}'.".format(config.classify.model +
                                                ".meta"))
        exit(13)

    # just fetch the classifier now so it doesn't impact the benchmarking on the first clip analysed.
    _ = clip_classifier.classifier

    if args.source == "all":
        clip_classifier.process_all(config.source_folder)
    elif os.path.splitext(args.source)[-1].lower() == '.cptv':
        source_file = tools.find_file_from_cmd_line(config.source_folder,
                                                    args.source)
        if source_file is None:
            return
        clip_classifier.process_file(source_file)
    else:
        clip_classifier.process_folder(
            os.path.join(config.source_folder, args.source))
Ejemplo n.º 3
0
def main():
    logging.root.removeHandler(absl.logging._absl_handler)
    absl.logging._warn_preinit_stderr = False
    parser = argparse.ArgumentParser()

    parser.add_argument(
        "source",
        help=
        'a CPTV file to process, or a folder name, or "all" for all files within subdirectories of source folder.',
    )
    parser.add_argument(
        "-p",
        "--preview-type",
        help=
        "Create MP4 previews of this type (can be slow), this overrides the config",
    )
    parser.add_argument("-v",
                        "--verbose",
                        action="count",
                        help="Display additional information.")
    parser.add_argument(
        "--start-date",
        help=
        "Only clips on or after this day will be processed (format YYYY-MM-DD)",
    )
    parser.add_argument(
        "--end-date",
        help=
        "Only clips on or before this day will be processed (format YYYY-MM-DD)",
    )
    parser.add_argument("-c",
                        "--config-file",
                        help="Path to config file to use")
    parser.add_argument(
        "--processor-folder",
        help=
        "When running from thermal-processing use this to specify the folder for both the source cptv and output mp4. With this option the metadata will be sent to stdout.",
    )
    parser.add_argument("-T",
                        "--timestamps",
                        action="store_true",
                        help="Emit log timestamps")
    parser.add_argument(
        "-m",
        "--model-file",
        help="Path to model file to use, will override config model",
    )

    args = parser.parse_args()

    config = Config.load_from_file(args.config_file)
    config.validate()
    init_logging(args.timestamps)

    # parse command line arguments
    if args.preview_type:
        config.classify.preview = args.preview_type

    if args.verbose:
        config.classify_tracking.verbose = True

    if args.processor_folder:
        config.classify.meta_to_stdout = True
        config.base_data_folder = args.processor_folder
        config.classify.classify_folder = args.processor_folder
        config.source_folder = args.processor_folder

    model_file = config.classify.model
    if args.model_file:
        model_file = args.model_file
    clip_classifier = ClipClassifier(config, config.classify_tracking,
                                     model_file)

    # parse start and end dates
    if args.start_date:
        clip_classifier.start_date = datetime.strptime(args.start_date,
                                                       "%Y-%m-%d")
    if args.end_date:
        clip_classifier.end_date = datetime.strptime(args.end_date, "%Y-%m-%d")

    if config.classify.preview != Previewer.PREVIEW_NONE:
        logging.info("Creating previews")

    if not config.use_gpu:
        logging.info("GPU mode disabled.")

    if not os.path.exists(clip_classifier.model_file + ".meta"):
        logging.error(
            "No model found named '{}'.".format(clip_classifier.model_file +
                                                ".meta"))
        exit(13)

    # just fetch the classifier now so it doesn't impact the benchmarking on the first clip analysed.
    _ = clip_classifier.classifier

    if os.path.splitext(args.source)[-1].lower() == ".cptv":
        source_file = tools.find_file_from_cmd_line(config.source_folder,
                                                    args.source)
        if source_file is None:
            return
        clip_classifier.process_file(source_file)
    else:
        folder = config.source_folder
        if args.source != "all":
            os.path.join(config.source_folder, folder)
        clip_classifier.process_all(folder)
Ejemplo n.º 4
0
def parse_params():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        'target',
        default='all',
        help=
        'Target to process, "all" processes all folders, "test" runs test cases, "clean" to remove banned clips from db, or a "cptv" file to run a single source.'
    )

    parser.add_argument('-p',
                        '--create-previews',
                        action='count',
                        help='Create MP4 previews for tracks (can be slow)')
    parser.add_argument('-t',
                        '--test-file',
                        default='tests.txt',
                        help='File containing test cases to run')
    parser.add_argument('-v',
                        '--verbose',
                        action='count',
                        help='Display additional information.')
    parser.add_argument('-i',
                        '--show-build-information',
                        action='count',
                        help='Show openCV build information and exit.')
    parser.add_argument('-c',
                        '--config-file',
                        help="Path to config file to use")
    args = parser.parse_args()

    if args.show_build_information:
        print(cv2.getBuildInformation())
        return

    config = Config.load_from_file(args.config_file)
    if args.create_previews:
        config.extract.preview = "tracking"
    if args.verbose:
        config.extract.verbose = True

    # setup extractor
    extractor = CPTVTrackExtractor(config, config.tracking)

    if os.path.splitext(args.target)[1].lower() == '.cptv':
        # run single source
        source_file = tools.find_file_from_cmd_line(config.source_folder,
                                                    args.target)
        if source_file is None:
            return
        print("Processing file '" + source_file + "'")
        tag = os.path.basename(os.path.dirname(source_file))
        extractor.process_file(source_file, tag=tag)
        return

    if args.target.lower() == 'test':
        print("Running test suite")
        extractor.run_tests(args.source_folder, args.test_file)
        return

    print('Processing tag "{0}"'.format(args.target))

    if args.target.lower() == 'all':
        extractor.clean_all()
        extractor.process_all(config.source_folder)
        return
    if args.target.lower() == 'clean':
        extractor.clean_all()
        return
    else:
        extractor.process_folder(os.path.join(config.source_folder,
                                              args.target),
                                 tag=args.target,
                                 worker_pool_args=(trackdatabase.HDFS_LOCK, ))
        return