-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_common_overlay_apps.py
127 lines (89 loc) · 3.49 KB
/
test_common_overlay_apps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# -*- coding: utf-8 -*-
import os
import sys
import cv2
import pytest
import mock
import numpy as np
import sksurgeryutils.common_overlay_apps as coa
def test_OverlayOnVideoFeedCropRecord_from_file(setup_qt, tmpdir):
in_github_ci = os.environ.get('CI')
if in_github_ci and sys.platform.startswith("linux"):
pytest.skip("Test not working on Linux runner \
because of unknown issue.")
input_file = 'tests/data/100x50_100_frames.avi'
out_file = os.path.join(tmpdir, 'overlay_test.avi')
overlay_app = coa.OverlayOnVideoFeedCropRecord(input_file, out_file)
# Start app and get a frame from input, so that
# the window is showing something, before we start
# recording.
overlay_app.start()
overlay_app.update()
overlay_app.on_record_start()
for i in range(50):
overlay_app.update()
overlay_app.on_record_stop()
overlay_app.stop()
# Check that 50 frames were actually written to the output file
output_video = cv2.VideoCapture(out_file)
for i in range(50):
ret, _ = output_video.read()
assert ret
# Trying to read 51st frame should return False
ret, _ = output_video.read()
assert not ret
output_video.release()
def test_OverlayOnVideoFeedCropRecord_from_webcam(setup_qt):
"""
Test will only run if there is a camera avilable.
"""
# Try to open a camera. If one isn't available, the rest of test
# will be skipped.
source = 0
cam = cv2.VideoCapture(source)
if not cam.isOpened():
pytest.skip("No camera available")
cam.release()
# Don't pass an output filename as a parameter, so that
# the code to generate a filename from current date/time is executed.
overlay_app = coa.OverlayOnVideoFeedCropRecord(0)
# Start app and get a frame from input, so that
# the window is showing something, before we start
# recording.
overlay_app.start()
overlay_app.update()
overlay_app.on_record_start()
for i in range(50):
overlay_app.update()
overlay_app.on_record_stop()
overlay_app.stop()
def test_OverlayBaseAppRaisesNotImplementedError(setup_qt):
class ErrorApp(coa.OverlayBaseApp):
def something(self):
pass
with pytest.raises(NotImplementedError):
input_file = 'tests/data/100x50_100_frames.avi'
overlay_app = ErrorApp(input_file)
overlay_app.update()
def test_OverlayOnVideoFeedCropRecord_set_roi(setup_qt):
input_file = 'tests/data/100x50_100_frames.avi'
overlay_app = coa.OverlayOnVideoFeedCropRecord(input_file)
overlay_app.update() # Get a frame so that we can crop it
with pytest.raises(RuntimeError):
overlay_app.set_roi()
def test_DuplicateOverlayWindow(setup_qt):
input_file = 'tests/data/100x50_100_frames.avi'
overlay_app = coa.OverlayOnVideoFeed(input_file)
duplicate = coa.DuplicateOverlayWindow()
duplicate.set_source_window(overlay_app)
overlay_app.update()
duplicate.update()
np.testing.assert_array_equal(overlay_app.img, duplicate.vtk_overlay_window.input)
def test_DuplicateOverlayWindowWithCrop(setup_qt):
input_file = 'tests/data/100x50_100_frames.avi'
overlay_app = coa.OverlayOnVideoFeedCropRecord(input_file)
duplicate = coa.DuplicateOverlayWindow()
duplicate.set_source_window(overlay_app)
overlay_app.update()
duplicate.update()
np.testing.assert_array_equal(overlay_app.img, duplicate.vtk_overlay_window.input)