示例#1
0
def test_Trajectory_from_to_file(util):
    filename = os.path.join(util.TMP_DIR,
                            "moviepy_Trajectory_from_to_file.txt")
    if os.path.isfile(filename):
        try:
            os.remove(filename)
        except PermissionError:
            pass

    trajectory_file_content = """# t(ms)	x	y
0	554	100
166	474	90
333	384	91
"""

    with open(filename, "w") as f:
        f.write(trajectory_file_content)

    trajectory = Trajectory.from_file(filename)

    assert np.array_equal(trajectory.xx, np.array([554, 474, 384]))
    assert np.array_equal(trajectory.yy, np.array([100, 90, 91]))
    assert np.array_equal(trajectory.tt, np.array([0, 0.166, 0.333]))

    trajectory.to_file(filename)

    with open(filename, "r") as f:
        assert f.read() == "\n".join(trajectory_file_content.split("\n")[1:])
示例#2
0
clip = VideoFileClip("media/chaplin.mp4")

# MANUAL TRACKING OF THE HEAD

# the next line is for the manual tracking and its saving
# to a file, it must be commented once the tracking has been done
# (after the first run of the script for instance).
# Note that we save the list (ti, xi, yi), not the functions fx and fy

# manual_tracking(clip, fps=6, savefile="blurred_trajectory.txt")


# IF THE MANUAL TRACKING HAS BEEN PREVIOUSLY DONE,
# LOAD THE TRACKING DATA AND CONVERT IT TO TRAJECTORY INTERPOLATORS fx(t), fy(t)

traj = Trajectory.from_file("blurred_trajectory.txt")


# BLUR CHAPLIN'S HEAD IN THE CLIP PASSING xi(t) and yi(t) FUNCTIONS

clip_blurred = clip.fx(vfx.headblur, traj.xi, traj.yi, 25)


# Generate the text, put in on a grey background

txt = TextClip(
    "Hey you! \n You're blurry!",
    color="grey70",
    size=clip.size,
    bg_color="grey20",
    font="Century-Schoolbook-Italic",