Beispiel #1
0
    def test_trajectory_transform_values(self):
        # input_vid = 'https://s3.amazonaws.com/python-vidstab/ostrich.mp4'
        input_vid = local_vid
        base_url = 'https://s3.amazonaws.com/python-vidstab'
        stabilizer = VidStab()

        for window in [15, 30, 60]:
            stabilizer.gen_transforms(input_path=input_vid,
                                      smoothing_window=window)

            transform_file = '{}/ostrich_transforms_{}.pickle'.format(
                base_url, window)
            trajectory_file = '{}/ostrich_trajectory_{}.pickle'.format(
                base_url, window)
            smooth_trajectory_file = '{}/ostrich_smooth_trajectory_{}.pickle'.format(
                base_url, window)

            with urlopen(transform_file) as f:
                expected_transforms = pickle.load(f)
            with urlopen(trajectory_file) as f:
                expected_trajectory = pickle.load(f)
            with urlopen(smooth_trajectory_file) as f:
                expected_smooth_trajectory = pickle.load(f)

            self.assertTrue(
                np.allclose(stabilizer.transforms, expected_transforms))
            self.assertTrue(
                np.allclose(stabilizer.trajectory, expected_trajectory))
            self.assertTrue(
                np.allclose(stabilizer.smoothed_trajectory,
                            expected_smooth_trajectory))
Beispiel #2
0
    def test_video_dep_funcs_run(self):
        # just tests to check functions run
        # input_vid = 'https://s3.amazonaws.com/python-vidstab/trunc_video.avi'
        input_vid = local_trunc_vid

        stabilizer = VidStab()
        stabilizer.gen_transforms(input_vid,
                                  smoothing_window=1,
                                  show_progress=True)

        self.assertEqual(stabilizer.smoothed_trajectory.shape,
                         stabilizer.trajectory.shape,
                         'trajectory/transform obj shapes')
        self.assertEqual(stabilizer.transforms.shape,
                         stabilizer.trajectory.shape,
                         'trajectory/transform obj shapes')

        with tempfile.TemporaryDirectory() as tmpdir:
            output_vid = '{}/test_output.avi'.format(tmpdir)
            try:
                stabilizer.apply_transforms(input_vid, output_vid)
            except Exception as e:
                self.fail("stabilizer.apply_transforms ran into {}".format(e))

            try:
                stabilizer.stabilize(input_vid, output_vid, smoothing_window=1)
            except Exception as e:
                self.fail("stabilizer.stabilize ran into {}".format(e))
Beispiel #3
0
def test_trajectory_transform_values():
    for window in [15, 30, 60]:
        stabilizer = VidStab(processing_max_dim=float('inf'))
        stabilizer.gen_transforms(input_path=OSTRICH_VIDEO,
                                  smoothing_window=window)

        pickle_test_transforms(stabilizer, 'pickled_transforms')

        check_transforms(stabilizer, is_cv4=imutils.is_cv4())
Beispiel #4
0
def test_video_dep_funcs_run():
    # just tests to check functions run
    stabilizer = VidStab()
    stabilizer.gen_transforms(TRUNCATED_OSTRICH_VIDEO, smoothing_window=2, show_progress=True)

    assert stabilizer.smoothed_trajectory.shape == stabilizer.trajectory.shape
    assert stabilizer.transforms.shape == stabilizer.trajectory.shape

    with tempfile.TemporaryDirectory() as tmpdir:
        output_vid = '{}/test_output.avi'.format(tmpdir)
        stabilizer.apply_transforms(TRUNCATED_OSTRICH_VIDEO, output_vid)
        stabilizer.stabilize(TRUNCATED_OSTRICH_VIDEO, output_vid, smoothing_window=2)
Beispiel #5
0
def test_invalid_input_path():
    stabilizer = VidStab(kp_method='FAST',
                         threshold=42,
                         nonmaxSuppression=False)
    with pytest.raises(FileNotFoundError) as err:
        stabilizer.gen_transforms("fake_input_path.mp4")

    assert "fake_input_path.mp4 does not exist" in str(err.value)

    with pytest.raises(FileNotFoundError) as err:
        stabilizer.stabilize("fake_input_path.mp4", "output.avi")

    assert "fake_input_path.mp4 does not exist" in str(err.value)
Beispiel #6
0
def test_trajectory_transform_values():
    for window in [15, 30, 60]:
        stabilizer = VidStab()
        stabilizer.gen_transforms(input_path=ostrich_video,
                                  smoothing_window=window)

        pickle_test_transforms(stabilizer, 'pickled_transforms')

        unpickled_transforms = download_pickled_transforms(
            window, cv4=imutils.is_cv4())

        assert np.allclose(stabilizer.transforms, unpickled_transforms[0])
        assert np.allclose(stabilizer.trajectory, unpickled_transforms[1])
        assert np.allclose(stabilizer.smoothed_trajectory,
                           unpickled_transforms[2])
Beispiel #7
0
def test_invalid_input_path():
    stabilizer = VidStab(kp_method='FAST', threshold=42, nonmaxSuppression=False)
    with pytest.raises(FileNotFoundError) as err:
        stabilizer.gen_transforms('fake_input_path.mp4')

    assert 'fake_input_path.mp4 does not exist' in str(err.value)

    with pytest.raises(FileNotFoundError) as err:
        stabilizer.stabilize('fake_input_path.mp4', 'output.avi')

    assert 'fake_input_path.mp4 does not exist' in str(err.value)

    with pytest.raises(ValueError) as err:
        tmp_file = tempfile.NamedTemporaryFile(suffix='.mp4')
        with pytest.warns(UserWarning, match='No progress bar will be shown'):
            stabilizer.stabilize(tmp_file.name, 'output.avi')

    assert 'First frame is None' in str(err.value)
Beispiel #8
0
def test_video_dep_funcs_run():
    # just tests to check functions run
    stabilizer = VidStab()
    stabilizer.gen_transforms(local_trunc_vid, smoothing_window=2, show_progress=True)

    assert stabilizer.smoothed_trajectory.shape == stabilizer.trajectory.shape
    assert stabilizer.transforms.shape == stabilizer.trajectory.shape

    with tempfile.TemporaryDirectory() as tmpdir:
        output_vid = '{}/test_output.avi'.format(tmpdir)
        try:
            stabilizer.apply_transforms(local_trunc_vid, output_vid)
        except Exception as e:
            pytest.fail("stabilizer.apply_transforms ran into {}".format(e))

        try:
            stabilizer.stabilize(local_trunc_vid, output_vid, smoothing_window=2)
        except Exception as e:
            pytest.fail("stabilizer.stabilize ran into {}".format(e))
Beispiel #9
0
def test_invalid_input_path():
    stabilizer = VidStab(kp_method='FAST',
                         threshold=42,
                         nonmaxSuppression=False)
    with pytest.raises(FileNotFoundError) as err:
        stabilizer.gen_transforms("fake_input_path.mp4")

    assert "fake_input_path.mp4 does not exist" in str(err.value)

    with pytest.raises(FileNotFoundError) as err:
        stabilizer.stabilize("fake_input_path.mp4", "output.avi")

    assert "fake_input_path.mp4 does not exist" in str(err.value)

    with pytest.raises(ValueError) as err:
        tmp_file = tempfile.NamedTemporaryFile(suffix=".mp4")
        stabilizer.stabilize(tmp_file.name, "output.avi")

    assert "First frame is None" in str(err.value)
from vidstab import VidStab, layer_overlay, layer_blend
import matplotlib.pyplot as plt

input_vid = 'https://s3.amazonaws.com/python-vidstab/ostrich.mp4'

stabilizer = VidStab()
stabilizer.gen_transforms(input_path=input_vid)

stabilizer.plot_trajectory()
plt.savefig('trajectory_plot.png')

stabilizer.plot_transforms()
plt.savefig('transforms_plot.png')

# USING AND SIZING BORDERS

# # default (0 width border)
# stabilizer.stabilize(input_path=input_vid,
#                      output_path='stable_video.avi',
#                      border_type='black')
#
# # wide black border
# stabilizer.stabilize(input_path=input_vid,
#                      output_path='wide_stable_video.avi',
#                      border_type='black',
#                      border_size=100)
#
# # crop with negative border
# stabilizer.stabilize(input_path=input_vid,
#                      output_path='crop_stable_video.avi',
#                      border_type='black',