|
2 | 2 | import tempfile |
3 | 3 | import cv2 |
4 | 4 | import imutils |
| 5 | +import imutils.video |
5 | 6 | import numpy as np |
6 | 7 | import pytest |
7 | 8 |
|
|
12 | 13 | # atol value to use when comparing results using np.allclose |
13 | 14 | NP_ALLCLOSE_ATOL = 1e-3 |
14 | 15 |
|
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 |
16 | 17 | # see: https://github.com/skvark/opencv-python/issues/126 |
17 | 18 | KP_METHODS = ['GFTT', 'BRISK', 'DENSE', 'FAST', 'HARRIS', 'MSER', 'ORB', 'STAR'] |
18 | 19 |
|
@@ -140,11 +141,45 @@ def test_resize(): |
140 | 141 |
|
141 | 142 |
|
142 | 143 | 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) |
148 | 183 |
|
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 |
0 commit comments