コード例 #1
0
def get_recordings(ingest_session_path):
    params = get_recording_params(ingest_session_path, verbose=False)
    file_list = find_files(params[0],
                           params[1],
                           params[2],
                           drop_last_file=True,
                           verbose=False)

    # print("INGEST SESSION PATH: {}".format(ingest_session_path))
    # print(file_list)

    keepers = [item[1].split(".mp4")[0] for item in file_list]
    # recording_names = []
    # last_recording_num = {}
    # for item in os.listdir(os.path.join(ingest_session_path,"recording")):
    #     recording_names.append(item.split(".mp4")[0])

    # # remove all recordings that are currently being written to
    # keepers = []
    # for item in recording_names:
    #     for other_item in recording_names:
    #         camera1 = item.split("_")[1]
    #         camera2 = other_item.split("_")[1]
    #         if camera1 == camera2:
    #             num1 = int(item.split("_")[2].split(".mp4")[0])
    #             num2 = int(other_item.split("_")[2].split(".mp4")[0])
    #             if num1 < num2:
    #                 keepers.append(item) # there exists a recording with greater number than item for that camera

    return keepers
コード例 #2
0
ファイル: build_dataset.py プロジェクト: mcf1110/planktool
def build_dataset():
    directories = [x[0] for x in os.walk(INPUT)]
    directories.reverse()

    #Clear existing
    existing_csv = utils.find_files(OUTPUT, filetypes=['csv'])
    for csv in existing_csv:
        os.remove(csv)

    matrix = []

    for d in directories:
        print("Getting features for %s" % d)

        files = utils.find_files(d, depth=0)  #all jpegs within d

        for f in files:
            full_image = utils.image_read(f)
            rois = subimages.extract(full_image, preprocessor.default_ensemble)
            i = 0
            for (cropped, cnt) in rois:
                vector = features.get(full_image, cropped, cnt)
                if (vector is False):
                    continue  #skip it
                specific = os.path.basename(os.path.dirname(f))
                general = os.path.dirname(f).split(os.sep)[1]
                filename = os.path.normpath(
                    f)  #"%s_%d" % ( os.path.basename(f), i )
                vector += [specific, general, filename] + list(
                    cv2.boundingRect(cnt))
                matrix.append(vector)

                i += 1
    cols = features.get_labels() + [
        'specific_class', 'general_class', 'filename', 'x', 'y', 'w', 'h'
    ]
    df = pd.DataFrame(matrix, columns=cols)

    df.to_csv(os.path.join(OUTPUT, 'dataset.csv'))
コード例 #3
0
COMPILER_INCLUDE_DIRS = [
    build_globals.from_proj_root('arduino_core', 'include'),
    build_globals.from_proj_root('arduino_core', 'variants', 'arduino_due_x'),
    build_globals.from_proj_root('device_libs', 'CMSIS', 'CMSIS', 'Include'),
    build_globals.from_proj_root('device_libs', 'CMSIS', 'Device', 'ATMEL'),
    build_globals.from_proj_root('device_libs', 'libsam'),
    build_globals.from_proj_root('src'),
    build_globals.from_proj_root('my_static_lib'),
    build_globals.from_proj_root('test_harness', 'Unity')
]

LINKER = 'gcc'

SOURCE_DIRS = ['src', 'tests', 'test_harness', 'my_static_lib']

SOURCES = utilities.find_files(SOURCE_DIRS, extensions=['.c'])

HEADERS = utilities.find_files(SOURCE_DIRS, extensions=['.h'])

# manually add auto-generated sources as they can't be found before building
SOURCES += [build_globals.UNIT_TEST_RUNNER_SOURCE]

OBJECTS = [utilities.source_to_obj(source, OBJ_DIR) for source in SOURCES]

EXE_TARGET_NAME = build_globals.get_exe_target_name(NAME, 'exe')

EXE_TARGET = os.path.join(BUILD_DIR, EXE_TARGET_NAME)


#-----------------------------------------------------------
# Functions
コード例 #4
0
def main(argv):
    usage = """
    query_frames.py [-h] [-l] -s <session-directory>
    
    # primary behavior mode selection (must indicate one primary or alternate mode)
    -c/--count: count frames using FFmpeg container query
    -t/--timestamp: parse timestamps in frames using pixel checksum method (currently very slow, consider)
    
    # alternate behavior modes
    -h/--help: print usage information, then exit
    -l/--load_plot_output: load results file in session directory (need -s), plot the results, then exit; if non-default
        frame count results output filename, then specify it with -o/--output_filename= option
    
    # required arguments
    -s/--session_directory= /path/to/session_directory : (required) path of the session directory where files are stored
    
    # options with value required (options themselves are not required)
    -o/--output_filename= /path/to/output_file.csv : override output filename for results
    -f/--first_file= ### : file segment index at which to start querying
    -i/--input_filename= : comma-delineated list of file name fragments to narrow down video segment files; uses simple 
        `if 'fragment' in full_file_path:` check, so be specific; e.g., p2c3_00150,p3c1_00004
    -a/--append_outputs= /path/to/alt_output1.csv,path/to/alt_output2.csv : comma-delineated list of *absolute* results 
        file paths to append to -o/--output_filename= specified results (used during post-facto plotting option -l/--.)
    
    # options with no value to specify
    -d/--drop_last_file: flag to not query the last file in recording sequence, in case recording is actively occurring
    -p/--plot_output: flag to plot output of frame counting, grouped by pole (same filename as output, but .pdf)
    --print_output: flag to print output of frame counting as it is being written to file
    
    """
    try:
        opts, args = getopt.getopt(argv, 'cthldps:o:f:i:a:',
                                   ['count', 'timestamp', 'help', 'load_plot_output',
                                    'drop_last_file', 'plot_output', 'print_output',
                                    'session_directory=', 'output_filename=',
                                    'first_file=', 'input_filename=', 'append_outputs='])
    except getopt.GetoptError:
        print("Usage:", usage)
        print_exc()
        sys.exit(2)

    # defaults for mode choice
    count_frames = False
    parse_timestamps = False
    # defaults for inputs
    session_directory = None
    drop_last_file = False
    results_filename = None
    input_filename_filters = None
    append_results = None
    first_file = 0
    print_output = False
    plot_output = False
    # flag to plot output and exit (needs to capture session_directory value)
    plot_and_exit = False
    # parse inputs
    for opt, arg in opts:
        if opt in ('-h', '--help'):
            print("Usage:", usage)
            sys.exit()
        elif opt in ('-c', '--count'):
            count_frames = True
        elif opt in ('-t', '--timestamp'):
            parse_timestamps = True
        elif opt in ('-l', '--load_plot_output'):
            plot_and_exit = True
        elif opt in ('-s', '--session_directory'):
            session_directory = arg
        elif opt in ('-d', '--drop_last_file'):
            drop_last_file = True
        elif opt in ('-o', '--output_filename'):
            results_filename = arg
        elif opt in ('-a', '--append_outputs'):
            if ',' not in arg:
                warnings.warn("Only got on results file to append. If that's not right, check comma delineation.")
            append_results_unfiltered = arg.split(',')
            append_results = []
            for fn in append_results_unfiltered:
                if os.path.exists(fn):
                    append_results.append(fn)
                else:
                    warnings.warn("Path to results file in append argument does not exist: {}".format(fn))
            if len(append_results) == 0:
                append_results = None
        elif opt in ('-i', '--input_filename'):
            input_filename_filters = arg.split(',')
        elif opt in ('-f', '--first_file',):
            first_file = int(arg)
        elif opt in ('--print_output',):
            print_output = True
        elif opt in ('-p', '--plot_output',):
            plot_output = True
        else:
            warnings.warn("Got unhandled option/argument. OPTION=[{}] ARGUMENT=[{}]".format(opt, arg))

    # this is the only required input
    if session_directory is None:
        print("Must supply session directory so we can pull config file and recordings.")
        print("Usage:", usage)
        sys.exit(2)
    session_info_file_path = os.path.join(session_directory, DEFAULT_SESSION_INFO_FILENAME)
    session_number = utilities.get_session_number(session_info_filename=session_info_file_path)

    # one of these modes must be selected
    if plot_and_exit is False:
        if count_frames is False and parse_timestamps is False:
            print("Must select a mode: count frames (-c), parse timestamps (-t), or load and plot results (-l).")
            print("Usage:", usage)
            sys.exit(2)

    default_count_filename = 'frame_counts_recording.csv'
    default_plot_filename = 'frame_counts_recording.pdf'
    default_timestamp_filename = 'frame_timestamp_recording.csv'

    # default to files in session directory if not specified
    if results_filename is None:
        count_filename = os.path.join(session_directory, default_count_filename)
        plot_filename = os.path.join(session_directory, default_plot_filename)
        timestamp_filename = os.path.join(session_directory, default_timestamp_filename)
    # results filename was specified (custom), so determine how this goes to count, plot, and timestamp filenames
    else:
        if count_frames is True and parse_timestamps is True:
            # both count and timestamp indicated, so differentiate the value for results_filename, then .pdf for plot
            rfp, rfe = os.path.splitext(results_filename)
            count_filename = rfp + '-count' + rfe
            plot_filename = os.path.splitext(count_filename)[0] + '.pdf'
            timestamp_filename = rfp + '-timestamp' + rfe
        elif count_frames is True:
            # count indicated, so define that filename and the plot one
            count_filename = results_filename
            plot_filename = os.path.splitext(count_filename)[0] + '.pdf'
            timestamp_filename = None
        elif parse_timestamps is True:
            # timestamp indicated, so define that filename only
            count_filename = None
            plot_filename = None
            timestamp_filename = results_filename
        else:
            # for else case, plot_and_exit must = True
            # so change the extension from the results filename to PDF for the plot
            count_filename = None
            timestamp_filename = None
            plot_filename = os.path.splitext(results_filename)[0] + '.pdf'

    # if plot and exit requested, then do so
    if plot_and_exit is True:
        file_frame_counts = read_frame_count_results(file_path=results_filename)
        if append_results is not None:
            for arfn in append_results:
                file_frame_counts.update(read_frame_count_results(file_path=arfn))
        plot_frame_count_results(results_dict=file_frame_counts, filename=plot_filename,
                                 session_info_filename=session_info_file_path)
        sys.exit()

    # determine the config file path and parse that file
    config_file_path = os.path.join(session_directory, "_SESSION_CONFIG.config")
    camera_config, _, _, recording_config = utilities.parse_config_file(config_file=config_file_path)
    # go get the relevant configuration parameters
    recording_directories, recording_filenames, camera_names = utilities.get_recording_params(
        session_root_directory=session_directory, session_number=session_number,
        camera_configs=camera_config, recording_config=recording_config)
    # determine the files in the recording directory matching the filename format
    matching_files = utilities.find_files(recording_directories=recording_directories,
                                          file_name_formats=recording_filenames, camera_names=camera_names,
                                          drop_last_file=drop_last_file, first_file_index=first_file,
                                          filter_filenames=input_filename_filters)

    if count_frames is True:
        # run the frame count queries
        file_frame_counts = get_video_frame_counts(video_file_names=matching_files)
        # write the frame count results to a CSV file
        write_frame_count_results(results_dict=file_frame_counts,
                                  filename=count_filename, print_results=print_output)
        # plot frame count results, if indicated
        if plot_output is True:
            plot_frame_count_results(results_dict=file_frame_counts, filename=plot_filename,
                                     session_info_filename=session_info_file_path)

    if parse_timestamps is True:
        # run the parse timestamp queries
        file_frame_timestamps = get_video_frame_timestamps(video_file_names=matching_files)
        # write the frame timestamp results to a CSV file
        write_frame_timestamp_results(results_dict=file_frame_timestamps, filename=timestamp_filename)