[e8481a]: / tests / test_fall_prediction.py

Download this file

118 lines (79 with data), 3.2 kB

  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
import sys
import os
sys.path.append(os.path.abspath('.'))
from PIL import Image
from fall_prediction import Fall_prediction
def _get_image(file_name=None):
assert file_name
img = Image.open(file_name)
return img
def test_fall_detetcion_with_two_images_case_1():
"Expected to not detect a fall with two consecutive frames"
img1 = _get_image(file_name='Images/fall_img_1.png')
img2 = _get_image(file_name='Images/fall_img_2.png')
result = Fall_prediction(img1, img2)
assert result is None
def test_fall_detetcion_with_two_images_case_2():
"Expected to detect a fall with two consecutive frames"
img1 = _get_image(file_name='Images/fall_img_1.png')
img2 = _get_image(file_name='Images/fall_img_3.png')
result = Fall_prediction(img1, img2)
assert result
confidence = result['confidence']
angle = result['angle']
keypoint_corr = result['keypoint_corr']
assert keypoint_corr
assert confidence > 0.3
assert angle > 60
def test_fall_detetcion_with_three_images_case_1():
"""
Expected to detect a fall from the first and third frame by given three consecutive frames.
"""
img1 = _get_image(file_name='Images/fall_img_1.png')
img2 = _get_image(file_name='Images/fall_img_2.png')
img3 = _get_image(file_name='Images/fall_img_3.png')
result = Fall_prediction(img1, img2, img3)
assert result
confidence = result['confidence']
angle = result['angle']
keypoint_corr = result['keypoint_corr']
assert keypoint_corr
assert confidence > 0.3
assert angle > 60
def test_fall_detetcion_with_three_images_case_2():
"""
Expected to detect a fall from the first and second frame by given three consecutive frames.
"""
img1 = _get_image(file_name='Images/fall_img_1.png')
img2 = _get_image(file_name='Images/fall_img_3.png')
img3 = _get_image(file_name='Images/fall_img_4.png')
result = Fall_prediction(img1, img2, img3)
assert result
confidence = result['confidence']
angle = result['angle']
keypoint_corr = result['keypoint_corr']
assert keypoint_corr
assert confidence > 0.3
assert angle > 60
def test_fall_detetcion_with_three_images_case_3():
"""
Expected to detect a fall from the second and third frame by given three consecutive frames.
"""
img1 = _get_image(file_name='Images/background.jpg')
img2 = _get_image(file_name='Images/fall_img_8.png')
img3 = _get_image(file_name='Images/fall_img_9.png')
result = Fall_prediction(img1, img2, img3)
assert result
confidence = result['confidence']
angle = result['angle']
keypoint_corr = result['keypoint_corr']
assert keypoint_corr
assert confidence > 0.3
assert angle > 60
def test_fall_detetcion_with_three_images_case_4():
"Expected to not detect a fall with three consecutive frames"
img1 = _get_image(file_name='Images/background.jpg')
img2 = _get_image(file_name='Images/fall_img_5.png')
img3 = _get_image(file_name='Images/fall_img_6.png')
result = Fall_prediction(img1, img2, img3)
assert result is None