Skip to content

Commit

Permalink
Merge pull request #126 from AdamSpannbauer/release-1.7.4
Browse files Browse the repository at this point in the history
Release 1.7.4
  • Loading branch information
AdamSpannbauer authored Sep 12, 2021
2 parents f87d82d + b6dedf3 commit e005882
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 12 deletions.
51 changes: 43 additions & 8 deletions tests/test_vidstab.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import tempfile
import cv2
import imutils
import imutils.video
import numpy as np
import pytest

Expand All @@ -12,7 +13,7 @@
# atol value to use when comparing results using np.allclose
NP_ALLCLOSE_ATOL = 1e-3

# excluding non-free 'SIFT' & 'SURF' methods do to exclusion from opencv-contrib-python
# excluding non-free 'SIFT' & 'SURF' methods due to exclusion from opencv-contrib-python
# see: https://github.com/skvark/opencv-python/issues/126
KP_METHODS = ['GFTT', 'BRISK', 'DENSE', 'FAST', 'HARRIS', 'MSER', 'ORB', 'STAR']

Expand Down Expand Up @@ -140,11 +141,45 @@ def test_resize():


def test_writer_reset():
path_1 = 'stable_1.avi'
path_2 = 'stable_2.avi'
stabilizer = VidStab()
stabilizer.stabilize(OSTRICH_VIDEO, path_1, max_frames=16, smoothing_window=1)
stabilizer.stabilize(OSTRICH_VIDEO, path_2, max_frames=16, smoothing_window=1)
with tempfile.TemporaryDirectory() as tmpdir:
path_1 = '{}/stable_1.avi'.format(tmpdir)
path_2 = '{}/stable_2.avi'.format(tmpdir)

stabilizer = VidStab()
stabilizer.stabilize(OSTRICH_VIDEO, path_1, max_frames=16, smoothing_window=1)
stabilizer.stabilize(OSTRICH_VIDEO, path_2, max_frames=16, smoothing_window=1)

assert os.path.exists(path_1)
assert os.path.exists(path_2)

imutils.video.count_frames(path_1)


def test_output_fps():
force_fps = 10
with tempfile.TemporaryDirectory() as tmpdir:
output_vid = '{}/test_output.avi'.format(tmpdir)

stabilizer = VidStab()
stabilizer.stabilize(
OSTRICH_VIDEO,
output_vid,
max_frames=16,
smoothing_window=1,
output_fps=force_fps
)

output_fps = cv2.VideoCapture(output_vid).get(cv2.CAP_PROP_FPS)
assert force_fps == output_fps


def test_max_frames():
max_frames = 16
with tempfile.TemporaryDirectory() as tmpdir:
output_path = '{}/stable_1.avi'.format(tmpdir)

stabilizer = VidStab()
stabilizer.stabilize(OSTRICH_VIDEO, output_path, max_frames=max_frames, smoothing_window=1)

assert os.path.exists(path_1)
assert os.path.exists(path_2)
output_frame_count = imutils.video.count_frames(output_path)
assert max_frames == output_frame_count
3 changes: 3 additions & 0 deletions vidstab/VidStab.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,9 @@ def stabilize(self, input_path, output_path, smoothing_window=30, max_frames=flo
"""
self.writer = None

if max_frames is not None:
max_frames += 1

if border_size == 'auto':
self.auto_border_flag = True

Expand Down
4 changes: 2 additions & 2 deletions vidstab/frame_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def reset_queue(self, max_len=None, max_frames=None):

has_max_frames = self.max_frames is not None and not np.isinf(self.max_frames)
if has_max_frames:
self._max_frames = self.max_frames
self._max_frames = self.max_frames + 1

self.frames = PopDeque(maxlen=max_len)
self.inds = PopDeque(maxlen=max_len)
Expand Down Expand Up @@ -66,7 +66,7 @@ def _append_frame(self, frame, pop_ind=True):
if (pop_ind
and self.i is not None
and self.max_frames is not None):
break_flag = self.i >= self.max_frames
break_flag = self.i >= self.max_frames - 1
else:
break_flag = None

Expand Down
4 changes: 2 additions & 2 deletions vidstab/plot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def plot_trajectory(transforms, trajectory, smoothed_trajectory):
plt.xlabel('Frame Number')

fig.suptitle('Video Trajectory', x=0.15, y=0.96, ha='left')
fig.canvas.set_window_title('Trajectory')
fig.canvas.manager.set_window_title('Trajectory')

return fig, (ax1, ax2)

Expand Down Expand Up @@ -93,6 +93,6 @@ def plot_transforms(transforms, radians=False):
plt.xlabel('Frame Number')

fig.suptitle('Transformations for Stabilizing', x=0.15, y=0.96, ha='left')
fig.canvas.set_window_title('Transforms')
fig.canvas.manager.set_window_title('Transforms')

return fig, (ax1, ax2)

0 comments on commit e005882

Please sign in to comment.