forked from videoai/videoai-sdk
/
unittests.py
168 lines (132 loc) · 6.98 KB
/
unittests.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
from twisted.conch.test.test_transport import factory
from videoai import KamCheck, AlarmVerification, FaceDetect, FaceDetectImage, FaceLog
import unittest
import base64
import requests
import os
import json
import time
kamcheck_data_dir = os.path.join('..', 'test-data', 'KamCheck')
alarm_verification_data_dir = os.path.join('..', 'test-data', 'AlarmVerification')
face_detect_data_dir = os.path.join('..', 'test-data', 'FaceDetector')
class TestKamCheck(unittest.TestCase):
def do_kam_check(self, image_file, video_file):
image_path = os.path.join(kamcheck_data_dir, image_file)
video_path = os.path.join(kamcheck_data_dir, video_file)
kamcheck = KamCheck()
task = kamcheck.apply(image_file=image_path, video_file=video_path)
print task
return task
def test_kam_check(self):
print "Testing kam check..."
task = self.do_kam_check('parkingRef.png', 'parking.avi')
self.assert_(task['analytic'], "kamcheck")
self.assertTrue(task['complete'])
self.assertEqual(task['probability'], 0)
task = self.do_kam_check('PTZRef.png', 'PTZ.avi')
self.assert_(task['analytic'], "kamcheck")
self.assertTrue(task['complete'])
self.assertEqual(task['probability'], 100)
# what happens when someone gets them muddled up
with self.assertRaises(Exception):
task = self.do_kam_check('PTZ.avi', 'PTZRef.png')
class TestAlarmVerification(unittest.TestCase):
# Do the actual alarm verification
def do_alarm_verification(self, video_file):
video_path = os.path.join(alarm_verification_data_dir, video_file)
alarm_verification = AlarmVerification()
task = alarm_verification.apply(video_file=video_path)
print task
return task
# Test on some known videos
def test_alarm_verification(self):
print "Testing alarm verification..."
#test_data = { 'Alarm.mpg':100, 'NoAlarm.mpg':2, '1.avi':100, '2.avi':100 }
test_data = { 'intrusion.avi':100, 'officeEntry.mp4':100 }
for key, value in test_data.iteritems():
print "** Testing {0} with expected result {1} **".format(key, value)
task = self.do_alarm_verification(key)
self.assert_(task['analytic'], "alarm_verification")
self.assertTrue(task['complete'])
self.assertEqual(task['probability'], value)
class TestFaceDetectImage(unittest.TestCase):
# Do the actual alarm verification
def do_face_detect(self, image_file):
face_detect_image = FaceDetectImage(verbose=True)
image_path = os.path.join(face_detect_data_dir, image_file)
task = face_detect_image.apply(image_path)
return task
# Test on some known videos
def test_face_detect(self):
print "Testing face detection..."
test_data = { 'group.jpg':16 , 'monifiethGIRLSpresentation2009-748708.jpg':16, 'KaliningradFaces.jpg':43 }
for key, value in test_data.iteritems():
print "** Testing {0} with expected result {1} **".format(key, value)
task = self.do_face_detect(key)
self.assert_(task['analytic'], "face_detect_image")
self.assertTrue(task['complete'])
self.assertEqual(task['number_of_faces'], value)
class TestFaceDetect(unittest.TestCase):
class TestData:
def __init__(self, video_file, frames, max_frames, number_of_faces):
self.video_file = video_file
self.frames = frames
self.max_frames = max_frames
self.number_of_faces = number_of_faces
self.verbose = True
# Do the actual alarm verification
def do_face_detect(self, test_data):
video_path = os.path.join(face_detect_data_dir, test_data.video_file)
face_detect = FaceDetect(verbose=test_data.verbose)
task = face_detect.apply(video_file=video_path, max_frames=test_data.max_frames)
return task
# Test on some known videos
def test_face_detect(self):
print "Testing face detection..."
#TestFaceDetect.TestData('demoFaceDetect.avi', 1138, 200, 54),
test_data = [
TestFaceDetect.TestData('officeEntry.mp4', frames=81, max_frames=0, number_of_faces=4),
TestFaceDetect.TestData('officeEntry.mp4', frames=81, max_frames=20, number_of_faces=0)
]
for this_test in test_data:
print "** Video File {0} w **".format(this_test.video_file)
task = self.do_face_detect(this_test)
self.assert_(task['analytic'], "face_detect")
self.assertTrue(task['complete'])
self.assertEqual(task['number_of_faces'], this_test.number_of_faces)
if this_test.max_frames == 0:
this_test.max_frames = this_test.frames
self.assertEqual(task['frames_processed'], this_test.max_frames)
class TestFaceLog(unittest.TestCase):
class TestData:
def __init__(self, video_file, frames, max_frames, number_of_sightings, min_certainty=1):
self.video_file = video_file
self.frames = frames
self.max_frames = max_frames
self.number_of_sightings = number_of_sightings
self.min_certainty = min_certainty
self.verbose = True
# Do the actual alarm verification
def do_face_log(self, test_data):
video_path = os.path.join(face_detect_data_dir, test_data.video_file)
face_log = FaceLog(verbose=True)
task = face_log.apply(video_file=video_path, max_frames=test_data.max_frames, min_certainty=test_data.min_certainty)
return task
# Test on some known videos
def test_face_detect(self):
print "Testing face detection..."
test_data = [
TestFaceLog.TestData(video_file='officeEntry.mp4', frames=81, max_frames=0, number_of_sightings=1, min_certainty=0),
TestFaceLog.TestData(video_file='officeEntry.mp4', frames=81, max_frames=20, number_of_sightings=0)
]
for this_test in test_data:
print "** Testing {0} **".format(this_test.video_file)
task = self.do_face_log(this_test)
self.assert_(task['analytic'], "face_detect")
self.assertTrue(task['complete'])
self.assertEqual(task['number_of_sightings'], this_test.number_of_sightings)
if this_test.max_frames == 0:
this_test.max_frames = this_test.frames
self.assertEqual(task['frames_processed'], this_test.max_frames)
if __name__ == '__main__':
unittest.main()