コード例 #1
0
ファイル: function.py プロジェクト: Iftimie/P2P-RPC
def p2prpc_analyze_large_file(video_handle: io.IOBase, arg2: int) -> {
        "res_var": int
}:
    p2p_progress_hook(80, 100)
    time.sleep(5)
    video_handle.close()
    return {"res_var": 10}
コード例 #2
0
ファイル: function.py プロジェクト: Iftimie/P2P-RPC
def p2prpc_analyze_large_file(video_handle: io.IOBase, arg2: int) -> {
        "res_var": int
}:
    p2p_progress_hook(80, 100)
    for i in range(100000):
        print("asdasdasdasdaasdasdasdasdasdasdasdasdasdasdasdasd" + str(i))
        time.sleep(0.001)
    video_handle.close()
    return {"res_var": 10}
コード例 #3
0
def analyze_movie(
    video_handle: io.IOBase) -> {
        "results": io.IOBase,
        "video_results": io.IOBase
    }:
    """
    Args:
        video_handle: file object for the movie to be analyzed.
        progress_hook: function that is called with two integer arguments. the first one represents the current frame index
            the second represents the final index.
    Return:
          dictionary containing path to the .csv file and to .mp4 file
    """
    model = create_model_efficient(
        model_creation_func=partial(create_model, max_operating_res=320))

    video_handle.close()
    video_file = video_handle.name
    frame_ids = p2p_load('frame_ids',
                         loading_func=lambda filepath: np.load(filepath))
    if frame_ids is None:
        frame_ids = movement_frames_indexes(video_file,
                                            progress_hook=p2p_progress_hook)
        p2p_save("frame_ids",
                 frame_ids,
                 saving_func=lambda filepath, item: np.save(filepath, item),
                 filesuffix=".npy")
    image_gen = framedatapoint_generator_by_frame_ids2(video_file,
                                                       frame_ids,
                                                       reason="motionmap")

    # TODO set batchsize by the available VRAM
    pred_gen = compute(image_gen, model=model, batch_size=5)
    filtered_pred = filter_pred_detections(pred_gen)
    if p2p_progress_hook is not None:
        filtered_pred = generator_hook(video_file, filtered_pred,
                                       p2p_progress_hook)
    df = pred_iter_to_pandas(filtered_pred)
    destination = os.path.splitext(video_file)[0] + '.csv'
    df.to_csv(destination)
    if p2p_progress_hook is not None:
        # call one more time the hook. this is just for clean ending of the processing. it may happen in case where the
        # skip is 5 that the final index is not reached, and in percentage it will look like 99.9% finished
        size = get_video_file_size(video_file) - 1
        p2p_progress_hook(size, size)

    visual_destination = os.path.splitext(video_file)[0] + '_results.mp4'
    visual_destination_good_codec = os.path.splitext(
        video_file)[0] + '_results_good_codec.mp4'
    compare_multiple_dataframes(video_file, visual_destination, df)

    subprocess.call(
        ["ffmpeg", "-i", visual_destination, visual_destination_good_codec])
    return {
        "results": open(destination, 'rb'),
        "video_results": open(visual_destination_good_codec, 'rb')
    }
コード例 #4
0
ファイル: function.py プロジェクト: Iftimie/P2P-RPC
def p2prpc_analyze_large_file(
    video_handle: io.IOBase, arg2: int
) -> {
        "results_file1": io.IOBase,
        "results_file2": io.IOBase,
        "res_var": int
}:
    p2p_progress_hook(80, 100)
    time.sleep(5)
    video_handle.close()
    return {
        "results_file1": open(video_handle.name, 'rb'),
        "results_file2": open(__file__, 'rb'),
        "res_var": 10
    }