-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
733 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Copyright (c) 2024 Philipp Rouast | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
import os | ||
from prpy.ffmpeg.probe import probe_video | ||
from prpy.ffmpeg.readwrite import read_video_from_path | ||
import pytest | ||
|
||
import sys | ||
sys.path.append('../vitallens-python') | ||
|
||
from vitallens.ssd import FaceDetector | ||
|
||
# TODO: Select a better test video | ||
TEST_VIDEO_PATH = "examples/test.mp4" | ||
|
||
@pytest.fixture(scope='session') | ||
def test_video_path(): | ||
return TEST_VIDEO_PATH | ||
|
||
@pytest.fixture(scope='session') | ||
def test_video_ndarray(): | ||
video, _ = read_video_from_path(path=TEST_VIDEO_PATH, pix_fmt='rgb24') | ||
return video | ||
|
||
@pytest.fixture(scope='session') | ||
def test_video_fps(): | ||
fps, *_ = probe_video(TEST_VIDEO_PATH) | ||
return fps | ||
|
||
@pytest.fixture(scope='session') | ||
def test_video_faces(request): | ||
det = FaceDetector( | ||
max_faces=1, fs=1.0, iou_threshold=0.45, score_threshold=0.9) | ||
test_video_ndarray = request.getfixturevalue('test_video_ndarray') | ||
test_video_fps = request.getfixturevalue('test_video_fps') | ||
boxes, _ = det(test_video_ndarray, fps=test_video_fps) | ||
boxes = (boxes * [test_video_ndarray.shape[2], test_video_ndarray.shape[1], test_video_ndarray.shape[2], test_video_ndarray.shape[1]]).astype(int) | ||
return boxes[:,0] | ||
|
||
@pytest.fixture(scope='session') | ||
def test_dev_api_key(): | ||
api_key = os.getenv('VITALLENS_DEV_API_KEY') | ||
if not api_key: | ||
raise pytest.UsageError( | ||
"VITALLENS_DEV_API_KEY environment variable is not set. Please set this variable " | ||
"to a valid VitalLens API Key to run the tests. You can do this by exporting the " | ||
"variable in your shell or adding it to your conda environment configuration." | ||
) | ||
return api_key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Copyright (c) 2024 Philipp Rouast | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
import sys | ||
sys.path.append('../vitallens-python') | ||
|
||
from vitallens.client import VitalLens, Method | ||
|
||
@pytest.mark.parametrize("method", [Method.G, Method.CHROM, Method.POS]) | ||
@pytest.mark.parametrize("detect_faces", [True, False]) | ||
@pytest.mark.parametrize("file", [True, False]) | ||
def test_VitalLens(request, method, detect_faces, file): | ||
vl = VitalLens(method=method, detect_faces=detect_faces) | ||
if file: | ||
test_video_path = request.getfixturevalue('test_video_path') | ||
result = vl(test_video_path, faces = None if detect_faces else [425, 116, 671, 433]) | ||
else: | ||
test_video_ndarray = request.getfixturevalue('test_video_ndarray') | ||
test_video_fps = request.getfixturevalue('test_video_fps') | ||
result = vl(test_video_ndarray, fps=test_video_fps, faces = None if detect_faces else [425, 116, 671, 433]) | ||
assert len(result) == 1 | ||
assert result[0]['face'].shape == (139, 4) | ||
assert result[0]['pulse']['val'].shape == (139,) | ||
np.testing.assert_allclose(result[0]['hr']['val'], 71.5, atol=2) | ||
|
||
def test_VitalLens_API(request): | ||
api_key = request.getfixturevalue('test_dev_api_key') | ||
vl = VitalLens(method=Method.VITALLENS, api_key=api_key, detect_faces=True) | ||
test_video_ndarray = request.getfixturevalue('test_video_ndarray') | ||
test_video_fps = request.getfixturevalue('test_video_fps') | ||
result = vl(test_video_ndarray, fps=test_video_fps, faces=None) | ||
assert len(result) == 1 | ||
assert result[0]['face'].shape == (139, 4) | ||
assert result[0]['pulse']['val'].shape == (139,) | ||
assert result[0]['pulse']['conf'].shape == (139,) | ||
assert result[0]['resp']['val'].shape == (139,) | ||
assert result[0]['resp']['conf'].shape == (139,) | ||
np.testing.assert_allclose(result[0]['hr']['val'], 73, atol=0.5) | ||
np.testing.assert_allclose(result[0]['rr']['val'], 15, atol=0.5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# Copyright (c) 2024 Philipp Rouast | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
import sys | ||
sys.path.append('../vitallens-python') | ||
|
||
from vitallens.methods.chrom import CHROMRPPGMethod | ||
from vitallens.methods.g import GRPPGMethod | ||
from vitallens.methods.pos import POSRPPGMethod | ||
from vitallens.utils import load_config | ||
|
||
@pytest.mark.parametrize("override_fps_target", [None, 15]) | ||
def test_CHROMRPPGMethod(request, override_fps_target): | ||
config = load_config("chrom.yaml") | ||
method = CHROMRPPGMethod(config) | ||
res = method.algorithm(np.random.rand(100, 3), fps=30.) | ||
assert res.shape == (100,) | ||
res = method.pulse_filter(res, fps=30.) | ||
assert res.shape == (100,) | ||
test_video_ndarray = request.getfixturevalue('test_video_ndarray') | ||
test_video_fps = request.getfixturevalue('test_video_fps') | ||
test_video_faces = request.getfixturevalue('test_video_faces') | ||
sig, conf, live = method( | ||
frames=test_video_ndarray, faces=test_video_faces, | ||
fps=test_video_fps, override_fps_target=override_fps_target) | ||
assert sig.shape == (1, test_video_ndarray.shape[0]) | ||
np.testing.assert_equal(conf, np.ones((1, test_video_ndarray.shape[0]), np.float32)) | ||
np.testing.assert_equal(live, np.ones((test_video_ndarray.shape[0],), np.float32)) | ||
|
||
@pytest.mark.parametrize("override_fps_target", [None, 15]) | ||
def test_GRPPGMethod(request, override_fps_target): | ||
config = load_config("g.yaml") | ||
method = GRPPGMethod(config) | ||
res = method.algorithm(np.random.rand(100, 3), fps=30.) | ||
assert res.shape == (100,) | ||
res = method.pulse_filter(res, fps=30.) | ||
assert res.shape == (100,) | ||
test_video_ndarray = request.getfixturevalue('test_video_ndarray') | ||
test_video_fps = request.getfixturevalue('test_video_fps') | ||
test_video_faces = request.getfixturevalue('test_video_faces') | ||
sig, conf, live = method( | ||
frames=test_video_ndarray, faces=test_video_faces, | ||
fps=test_video_fps, override_fps_target=override_fps_target) | ||
assert sig.shape == (1, test_video_ndarray.shape[0]) | ||
np.testing.assert_equal(conf, np.ones((1, test_video_ndarray.shape[0]), np.float32)) | ||
np.testing.assert_equal(live, np.ones((test_video_ndarray.shape[0],), np.float32)) | ||
|
||
@pytest.mark.parametrize("override_fps_target", [None, 15]) | ||
def test_POSRPPGMethod(request, override_fps_target): | ||
config = load_config("pos.yaml") | ||
method = POSRPPGMethod(config) | ||
res = method.algorithm(np.random.rand(100, 3), fps=30.) | ||
assert res.shape == (100,) | ||
res = method.pulse_filter(res, fps=30.) | ||
assert res.shape == (100,) | ||
test_video_ndarray = request.getfixturevalue('test_video_ndarray') | ||
test_video_fps = request.getfixturevalue('test_video_fps') | ||
test_video_faces = request.getfixturevalue('test_video_faces') | ||
sig, conf, live = method( | ||
frames=test_video_ndarray, faces=test_video_faces, | ||
fps=test_video_fps, override_fps_target=override_fps_target) | ||
assert sig.shape == (1, test_video_ndarray.shape[0]) | ||
np.testing.assert_equal(conf, np.ones((1, test_video_ndarray.shape[0]), np.float32)) | ||
np.testing.assert_equal(live, np.ones((test_video_ndarray.shape[0],), np.float32)) |
Oops, something went wrong.