Skip to content

Commit e005882

Browse files
Merge pull request #126 from AdamSpannbauer/release-1.7.4
Release 1.7.4
2 parents f87d82d + b6dedf3 commit e005882

4 files changed

Lines changed: 50 additions & 12 deletions

File tree

tests/test_vidstab.py

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import tempfile
33
import cv2
44
import imutils
5+
import imutils.video
56
import numpy as np
67
import pytest
78

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

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

@@ -140,11 +141,45 @@ def test_resize():
140141

141142

142143
def test_writer_reset():
143-
path_1 = 'stable_1.avi'
144-
path_2 = 'stable_2.avi'
145-
stabilizer = VidStab()
146-
stabilizer.stabilize(OSTRICH_VIDEO, path_1, max_frames=16, smoothing_window=1)
147-
stabilizer.stabilize(OSTRICH_VIDEO, path_2, max_frames=16, smoothing_window=1)
144+
with tempfile.TemporaryDirectory() as tmpdir:
145+
path_1 = '{}/stable_1.avi'.format(tmpdir)
146+
path_2 = '{}/stable_2.avi'.format(tmpdir)
147+
148+
stabilizer = VidStab()
149+
stabilizer.stabilize(OSTRICH_VIDEO, path_1, max_frames=16, smoothing_window=1)
150+
stabilizer.stabilize(OSTRICH_VIDEO, path_2, max_frames=16, smoothing_window=1)
151+
152+
assert os.path.exists(path_1)
153+
assert os.path.exists(path_2)
154+
155+
imutils.video.count_frames(path_1)
156+
157+
158+
def test_output_fps():
159+
force_fps = 10
160+
with tempfile.TemporaryDirectory() as tmpdir:
161+
output_vid = '{}/test_output.avi'.format(tmpdir)
162+
163+
stabilizer = VidStab()
164+
stabilizer.stabilize(
165+
OSTRICH_VIDEO,
166+
output_vid,
167+
max_frames=16,
168+
smoothing_window=1,
169+
output_fps=force_fps
170+
)
171+
172+
output_fps = cv2.VideoCapture(output_vid).get(cv2.CAP_PROP_FPS)
173+
assert force_fps == output_fps
174+
175+
176+
def test_max_frames():
177+
max_frames = 16
178+
with tempfile.TemporaryDirectory() as tmpdir:
179+
output_path = '{}/stable_1.avi'.format(tmpdir)
180+
181+
stabilizer = VidStab()
182+
stabilizer.stabilize(OSTRICH_VIDEO, output_path, max_frames=max_frames, smoothing_window=1)
148183

149-
assert os.path.exists(path_1)
150-
assert os.path.exists(path_2)
184+
output_frame_count = imutils.video.count_frames(output_path)
185+
assert max_frames == output_frame_count

vidstab/VidStab.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,9 @@ def stabilize(self, input_path, output_path, smoothing_window=30, max_frames=flo
551551
"""
552552
self.writer = None
553553

554+
if max_frames is not None:
555+
max_frames += 1
556+
554557
if border_size == 'auto':
555558
self.auto_border_flag = True
556559

vidstab/frame_queue.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def reset_queue(self, max_len=None, max_frames=None):
2626

2727
has_max_frames = self.max_frames is not None and not np.isinf(self.max_frames)
2828
if has_max_frames:
29-
self._max_frames = self.max_frames
29+
self._max_frames = self.max_frames + 1
3030

3131
self.frames = PopDeque(maxlen=max_len)
3232
self.inds = PopDeque(maxlen=max_len)
@@ -66,7 +66,7 @@ def _append_frame(self, frame, pop_ind=True):
6666
if (pop_ind
6767
and self.i is not None
6868
and self.max_frames is not None):
69-
break_flag = self.i >= self.max_frames
69+
break_flag = self.i >= self.max_frames - 1
7070
else:
7171
break_flag = None
7272

vidstab/plot_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def plot_trajectory(transforms, trajectory, smoothed_trajectory):
4343
plt.xlabel('Frame Number')
4444

4545
fig.suptitle('Video Trajectory', x=0.15, y=0.96, ha='left')
46-
fig.canvas.set_window_title('Trajectory')
46+
fig.canvas.manager.set_window_title('Trajectory')
4747

4848
return fig, (ax1, ax2)
4949

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

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

9898
return fig, (ax1, ax2)

0 commit comments

Comments
 (0)