示例#1
0
def html_imgs_generator(video_path, csv_path):
    pred_gen_from_df = pandas_to_pred_iter(pd.read_csv(csv_path))
    filtered_pred = filter_pred_detections(pred_gen_from_df)
    filtered_dataframe = pred_iter_to_pandas(filtered_pred)

    important_frames, important_df = get_important_frames(filtered_dataframe)
    image_gen = framedatapoint_generator_by_frame_ids2(video_path, important_frames)

    pred_from_important = pandas_to_pred_iter(important_df)

    for fdp in plot_detections(image_gen, pred_from_important):
        yield image2htmlstr(fdp.image)
def test_pipeline():
    csv_file_path = osp.join(osp.dirname(__file__), 'data', 'cut.csv')
    pred_gen_from_df = pandas_to_pred_iter(pd.read_csv(csv_file_path))
    tracker_list = []
    id_incrementer = 0
    for idx, pdp in enumerate(pred_gen_from_df):
        good_detections, tracker_list, id_incrementer = pipeline(
            pdp.pred, tracker_list, id_incrementer)

        print(len(good_detections['boxes']))
        if idx == 10: break
def test_filter_predictions_generator():
    show_video = False
    csv_file_path = osp.join(osp.dirname(__file__), 'data', 'cut.csv')
    pred_gen_from_df = pandas_to_pred_iter(pd.read_csv(csv_file_path))
    filtered_pred = filter_pred_detections(pred_gen_from_df)
    # filtered_dataframe = TruckDetector.pred_iter_to_pandas(filtered_pred)

    video_file = osp.join(osp.dirname(__file__), '..', 'service', 'data',
                          'cut.mkv')
    image_gen = framedatapoint_generator(video_file, skip=0)
    if show_video:
        for fdp in plot_detections(image_gen, filtered_pred):
            cv2.imshow("image", fdp.image)
            cv2.waitKey(0)
def test_TruckDetector_pred_iter_to_pandas():
    auu_data_root = r'D:\aau-rainsnow\Hjorringvej\Hjorringvej-2'
    video_file = [
        osp.join(r, f) for (r, _, fs) in os.walk(auu_data_root) for f in fs
        if 'avi' in f or 'mkv' in f
    ][0]
    #file 'Hjorringvej\\Hjorringvej-2\\cam1.mkv' has 6000 frames
    model = create_model(max_operating_res=320)
    image_gen = framedatapoint_generator(video_file, skip=6000 // 30)
    image_gen1, image_gen2 = tee(image_gen)

    pred_gen = compute(image_gen1, model)

    df = pred_iter_to_pandas(pred_gen)

    pred_gen_from_df = pandas_to_pred_iter(df)

    for idx, fdp in enumerate(plot_detections(image_gen2, pred_gen_from_df)):
        cv2.imshow("image", fdp.image)
        cv2.waitKey(1)
        if idx == 5: break
def compare_multiple_dataframes(video_path, destination, *dataframes):
    """
    Given a set of dataframes this function will look at the union of the dataframes. The resulted frames will be the
    union of the dataframes where there is a prediction or there is a reason (motionmap) for the presence of a frame.
    In other words, rows that have at least one column not Null.

    In this way you can see frames where one detector managed to detect something when the other didn't.

    The dataframes do not need to have the same number of rows in order to be compared. The presence of the 'img_id'
    column is sufficient.

    Args:
        video_path: video file from which the dataframes resulted
        destination: path to a destination .mp4 or .avi file that will contain the plotting of the dataframes
        dataframes: positional arguments with dataframes

    Result:
        None
    """
    common_frames = get_common_frames(dataframes)
    dataframes = normalize_dataframes(dataframes, common_frames)
    g = framedatapoint_generator_by_frame_ids2(video_path, common_frames)
    fdpgs = tee(g, len(dataframes))

    gdfs = [pandas_to_pred_iter(df) for df in dataframes]
    plots = [plot_detections(fdpg, gdf) for fdpg, gdf in zip(fdpgs, gdfs)]
    pairsg = zip(*plots)

    fdp_list = next(pairsg)
    assert all(fdp.frame_id == fdp_list[0].frame_id for fdp in fdp_list)

    images = [fdp.image for fdp in fdp_list]
    frame = np.concatenate((*images, ), axis=1)
    with create_avi(destination, frame) as append_fn:
        for fdp_list in pairsg:
            assert all(fdp.frame_id == fdp_list[0].frame_id
                       for fdp in fdp_list)
            images = [fdp.image for fdp in fdp_list]
            frame = np.concatenate((*images, ), axis=1)
            append_fn(frame)
def test_dataframe_filtered():
    csv_file_path = osp.join(osp.dirname(__file__), 'data', 'cut.csv')
    pred_gen_from_df = pandas_to_pred_iter(pd.read_csv(csv_file_path))
    filtered_pred = filter_pred_detections(pred_gen_from_df)
    filtered_dataframe = pred_iter_to_pandas(filtered_pred)
def get_tracked_df_from_df(df):
    g1 = filter_pred_detections(pandas_to_pred_iter(df))
    filtered_df = pred_iter_to_pandas(g1)
    return filtered_df