コード例 #1
0
ファイル: video_view.py プロジェクト: inwwin/waterwave-ddm
def main():
    import argparse
    import pathlib
    # import json

    parser = argparse.ArgumentParser()
    # parser.add_argument('--method', default='diff', choices=['diff', 'fft', 'corr'])
    parser.add_argument('-p', '--position', nargs=2, default=[0, 0], type=int)
    parser.add_argument('size', type=int)
    parser.add_argument(
        'vid_in')  # Directly passed to PyAV which then pass on to FFmpeg
    params = parser.parse_args()

    # print(params)

    frames_iter = pyav_single_frames_reader(params.vid_in)
    vid_info = next(frames_iter)
    # vid_info.pop('codec_context')

    video = frames_iter
    video = crop(video, (
        (params.position[0], params.position[0] + params.size),
        (params.position[1], params.position[1] + params.size),
    ))

    vid_info['vid_in_path'] = str(pathlib.Path(params.vid_in).resolve())

    print(vid_info)

    viewer = VideoViewer(video, vmin=0, vmax=255, count=vid_info['duration'])
    viewer.show()
コード例 #2
0
                               t2,
                               shape=SIMSHAPE,
                               background=0,
                               num_particles=NUM_PARTICLES2,
                               dt=DT_DUAL,
                               sigma=SIGMA2,
                               delta=DELTA2,
                               intensity=INTENSITY2,
                               dtype="uint16")

video = add(video1, video2)

#video = (move_pixels(frames) for frames in video)

#: crop video to selected region of interest
video = crop(video, roi=((0, SHAPE[0]), (0, SHAPE[1])))

# apply dust particles
if APPLY_DUST:
    dust1 = plt.imread(DUST1_PATH)[0:SHAPE[0], 0:SHAPE[1],
                                   0]  #float normalized to (0,1)
    dust2 = plt.imread(DUST2_PATH)[0:SHAPE[0], 0:SHAPE[1],
                                   0]  #float normalized to (0,1)

    dust = ((dust1, dust2), ) * NFRAMES_DUAL
    video = multiply(video, dust, dtype="uint16")

noise_model = (NOISE_MODEL, NOISE_MODEL)

video = (tuple((adc(f,
                    noise_model=noise_model[i],
コード例 #3
0
def main():
    import argparse
    import pathlib
    import json

    parser = argparse.ArgumentParser()
    # parser.add_argument('--method', default='diff', choices=['diff', 'fft', 'corr'])
    parser.add_argument('--kmax', default=None, type=int)
    parser.add_argument('-p', '--position', nargs=2, default=[0, 0], type=int)
    parser.add_argument('-r', '--framerate', type=str, default=None)
    parser.add_argument('-f', '--select', nargs=2, type=int)
    parser.add_argument('size', type=int)
    parser.add_argument('vid_in')  # Directly passed to PyAV which then pass on to FFmpeg
    # parser.add_argument('fft_out', type=argparse.FileType('wb'))  # pass to np.save
    parser.add_argument('fft_out', type=pathlib.Path)
    params = parser.parse_args()

    # print(params)

    try:
        params.fft_out.mkdir(mode=0o755, parents=True, exist_ok=True)
    except FileExistsError:
        parser.error('fft_out must be a directory')

    copt = dict()
    if params.framerate:
        copt['framerate'] = params.framerate
    if params.select:
        copt['start_number'] = str(params.select[0])

    frames_iter = pyav_single_frames_reader(
        params.vid_in,
        container_options=copt,
        frame_count=params.select[1] if params.select else None,
    )
    vid_info = next(frames_iter)
    vid_info.pop('codec_context')

    video = frames_iter
    video = crop(video, (
        (params.position[0], params.position[0] + params.size),
        (params.position[1], params.position[1] + params.size),
    ))

    fft_path = params.fft_out / 'fft_array'

    if params.select:
        frame_count = vid_info['framecount']
    else:
        frame_count = vid_info['duration']
    fft_info = fft_save(video, str(fft_path), params.size, count=frame_count, kmax=params.kmax)

    vid_info['vid_in_path'] = str(pathlib.Path(params.vid_in).resolve())
    fft_info['position'] = params.position
    fft_info['size'] = params.size
    vid_info['fft'] = fft_info

    def fraction_serializer(obj):
        try:
            return [obj.numerator, obj.denominator]
        except AttributeError:
            raise TypeError

    with open(params.fft_out / 'vid_info.json', 'w') as j:
        json.dump(vid_info, j, indent=4, default=fraction_serializer)
コード例 #4
0
 def test_crop(self):
     video = fromarrays((vid, ))
     with self.assertRaises(ValueError):
         list(crop(video, roi=((0, 4), 0, 2)))
     out, = asarrays(crop(video, roi=((0, 2), (0, 2))), 128)
     self.assertTrue(np.allclose(out[:], vid[:, 0:2, 0:2]))