def test_fall_detection_2_frame_back_case_2(): """ Expected to detect a fall using frame[t] and frame[t-2]. frame[t-2] : A person is in standing position. frame[t-1] : A person is mid-way of fall. frame[t] : A person is fall down. """ config = _fall_detect_config() result = None def sample_callback(image=None, inference_result=None, **kwargs): nonlocal result result = inference_result fall_detector = FallDetector(**config) output = _OutPipeElement(sample_callback=sample_callback) fall_detector.connect_to_next_element(output) # A frame at t-2 timestamp when person is in standing position. img_1 = _get_image(file_name='fall_img_1.png') # A frame at t-1 timestamp when person is mid-way of fall. img_2 = _get_image(file_name='fall_img_2_2.png') # A frame at t timestamp when person falls down. img_3 = _get_image(file_name='fall_img_2.png') fall_detector.min_time_between_frames = 0.01 fall_detector.max_time_between_frames = 15 fall_detector.receive_next_sample(image=img_1) time.sleep(fall_detector.min_time_between_frames) fall_detector.receive_next_sample(image=img_2) time.sleep(fall_detector.min_time_between_frames) assert not result fall_detector.receive_next_sample(image=img_3) assert result assert len(result) == 1 category = result[0]['label'] confidence = result[0]['confidence'] angle = result[0]['leaning_angle'] keypoint_corr = result[0]['keypoint_corr'] assert keypoint_corr assert category == 'FALL' assert confidence > 0.7 assert angle > 60
def test_fall_detection_2_frame_back_case_3(): """ Expected to not detect a fall using frame[t],frame[t-1] and frame[t-2]. frame[t-2] : A person is in walking postion. frame[t-1] : A person is in walking postion. frame[t] : A person is slight in lean postion but no fall. """ config = _fall_detect_config() result = None def sample_callback(image=None, inference_result=None, **kwargs): nonlocal result result = inference_result fall_detector = FallDetector(**config) output = _OutPipeElement(sample_callback=sample_callback) fall_detector.connect_to_next_element(output) # A frame at t-2 timestamp when person is in walking postion. img_1 = _get_image(file_name="fall_img_15.png") # A frame at t-1 timestamp when person is in walking postion. img_2 = _get_image(file_name="fall_img_16.png") # A frame at t timestamp when person is slight in lean postion but no fall. img_3 = _get_image(file_name="fall_img_17.png") fall_detector.min_time_between_frames = 0.01 fall_detector.receive_next_sample(image=img_1) time.sleep(fall_detector.min_time_between_frames) fall_detector.receive_next_sample(image=img_2) time.sleep(fall_detector.min_time_between_frames) assert not result fall_detector.receive_next_sample(image=img_3) assert not result