vitallens 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. vitallens-0.1.2/.github/workflows/main.yml +42 -0
  2. vitallens-0.1.2/.gitignore +163 -0
  3. vitallens-0.1.2/LICENSE +21 -0
  4. vitallens-0.1.2/MANIFEST.in +6 -0
  5. vitallens-0.1.2/PKG-INFO +168 -0
  6. vitallens-0.1.2/README.md +142 -0
  7. vitallens-0.1.2/examples/sample_video_1.mp4 +0 -0
  8. vitallens-0.1.2/examples/sample_video_2.mp4 +0 -0
  9. vitallens-0.1.2/examples/sample_vitals_1.csv +355 -0
  10. vitallens-0.1.2/examples/sample_vitals_2.csv +361 -0
  11. vitallens-0.1.2/examples/test.py +78 -0
  12. vitallens-0.1.2/pyproject.toml +41 -0
  13. vitallens-0.1.2/setup.cfg +4 -0
  14. vitallens-0.1.2/setup.py +3 -0
  15. vitallens-0.1.2/tests/.DS_Store +0 -0
  16. vitallens-0.1.2/tests/conftest.py +66 -0
  17. vitallens-0.1.2/tests/test_client.py +59 -0
  18. vitallens-0.1.2/tests/test_simple_rppg_method.py +84 -0
  19. vitallens-0.1.2/tests/test_ssd.py +151 -0
  20. vitallens-0.1.2/tests/test_utils.py +154 -0
  21. vitallens-0.1.2/tests/test_vitallens.py +165 -0
  22. vitallens-0.1.2/vitallens/__init__.py +21 -0
  23. vitallens-0.1.2/vitallens/client.py +185 -0
  24. vitallens-0.1.2/vitallens/configs/__init__.py +19 -0
  25. vitallens-0.1.2/vitallens/configs/chrom.yaml +41 -0
  26. vitallens-0.1.2/vitallens/configs/g.yaml +41 -0
  27. vitallens-0.1.2/vitallens/configs/pos.yaml +41 -0
  28. vitallens-0.1.2/vitallens/configs/vitallens.yaml +41 -0
  29. vitallens-0.1.2/vitallens/constants.py +33 -0
  30. vitallens-0.1.2/vitallens/errors.py +37 -0
  31. vitallens-0.1.2/vitallens/methods/__init__.py +19 -0
  32. vitallens-0.1.2/vitallens/methods/chrom.py +95 -0
  33. vitallens-0.1.2/vitallens/methods/g.py +75 -0
  34. vitallens-0.1.2/vitallens/methods/pos.py +98 -0
  35. vitallens-0.1.2/vitallens/methods/rppg_method.py +31 -0
  36. vitallens-0.1.2/vitallens/methods/simple_rppg_method.py +95 -0
  37. vitallens-0.1.2/vitallens/methods/vitallens.py +179 -0
  38. vitallens-0.1.2/vitallens/models/.DS_Store +0 -0
  39. vitallens-0.1.2/vitallens/models/Ultra-Light-Fast-Generic-Face-Detector-1MB/.DS_Store +0 -0
  40. vitallens-0.1.2/vitallens/models/Ultra-Light-Fast-Generic-Face-Detector-1MB/LICENSE +21 -0
  41. vitallens-0.1.2/vitallens/models/Ultra-Light-Fast-Generic-Face-Detector-1MB/__init__.py +0 -0
  42. vitallens-0.1.2/vitallens/models/Ultra-Light-Fast-Generic-Face-Detector-1MB/model_rfb_320.onnx +0 -0
  43. vitallens-0.1.2/vitallens/models/__init__.py +19 -0
  44. vitallens-0.1.2/vitallens/signal.py +36 -0
  45. vitallens-0.1.2/vitallens/ssd.py +270 -0
  46. vitallens-0.1.2/vitallens/utils.py +210 -0
  47. vitallens-0.1.2/vitallens.egg-info/PKG-INFO +168 -0
  48. vitallens-0.1.2/vitallens.egg-info/SOURCES.txt +49 -0
  49. vitallens-0.1.2/vitallens.egg-info/dependency_links.txt +1 -0
  50. vitallens-0.1.2/vitallens.egg-info/requires.txt +10 -0
  51. vitallens-0.1.2/vitallens.egg-info/top_level.txt +1 -0
@@ -0,0 +1,42 @@
1
+ name: Tests
2
+
3
+ on:
4
+ push:
5
+ branches: ["main"]
6
+ pull_request:
7
+ branches: ["main"]
8
+
9
+ jobs:
10
+ build:
11
+
12
+ runs-on: [ubuntu-latest]
13
+ strategy:
14
+ matrix:
15
+ python-version: ["3.8", "3.9", "3.10"]
16
+
17
+ steps:
18
+ - name: Set up Python ${{ matrix.python-version }}
19
+ uses: actions/setup-python@v4
20
+ with:
21
+ python-version: ${{ matrix.python-version }}
22
+ - name: Install ffmpeg
23
+ uses: Iamshankhadeep/setup-ffmpeg@v1.2
24
+ with:
25
+ version: "4.4"
26
+ token: ${{ secrets.GITHUB_TOKEN }}
27
+ - name: Checkout vitallens-python
28
+ uses: actions/checkout@v3
29
+ with:
30
+ token: ${{ secrets.GITHUB_TOKEN }}
31
+ - name: Install vitallens-python and dependencies
32
+ run: |
33
+ python -m pip install --upgrade pip
34
+ python -m pip install ".[test]"
35
+ - name: Lint with flake8
36
+ run: |
37
+ flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
38
+ - name: Test with pytest
39
+ env:
40
+ VITALLENS_DEV_API_KEY: ${{ secrets.VITALLENS_DEV_API_KEY }}
41
+ run: |
42
+ pytest
@@ -0,0 +1,163 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/#use-with-ide
110
+ .pdm.toml
111
+
112
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
+ __pypackages__/
114
+
115
+ # Celery stuff
116
+ celerybeat-schedule
117
+ celerybeat.pid
118
+
119
+ # SageMath parsed files
120
+ *.sage.py
121
+
122
+ # Environments
123
+ .env
124
+ .venv
125
+ env/
126
+ venv/
127
+ ENV/
128
+ env.bak/
129
+ venv.bak/
130
+
131
+ # Spyder project settings
132
+ .spyderproject
133
+ .spyproject
134
+
135
+ # Rope project settings
136
+ .ropeproject
137
+
138
+ # mkdocs documentation
139
+ /site
140
+
141
+ # mypy
142
+ .mypy_cache/
143
+ .dmypy.json
144
+ dmypy.json
145
+
146
+ # Pyre type checker
147
+ .pyre/
148
+
149
+ # pytype static type analyzer
150
+ .pytype/
151
+
152
+ # Cython debug symbols
153
+ cython_debug/
154
+
155
+ # PyCharm
156
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
159
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
160
+ #.idea/
161
+
162
+ # OS X .DS_Store
163
+ **/.DS_Store
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Rouast Labs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,6 @@
1
+ include README.md
2
+ recursive-include vitallens/configs *
3
+ recursive-include vitallens/methods *
4
+ recursive-include vitallens/models *
5
+ recursive-include tests *
6
+ prune **/__pycache__
@@ -0,0 +1,168 @@
1
+ Metadata-Version: 2.1
2
+ Name: vitallens
3
+ Version: 0.1.2
4
+ Summary: Vital sign estimation from facial video
5
+ Author-email: Philipp Rouast <philipp@rouast.com>
6
+ License: MIT License
7
+ Project-URL: Repository, https://github.com/Rouast-Labs/vitallens-python.git
8
+ Project-URL: Issues, https://github.com/Rouast-Labs/vitallens-python/issues
9
+ Keywords: python,rppg,vital signs monitoring,heart rate,pulse,respiration
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Development Status :: 4 - Beta
14
+ Requires-Python: >=3.8
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: importlib_resources
18
+ Requires-Dist: numpy
19
+ Requires-Dist: onnxruntime
20
+ Requires-Dist: prpy[ffmpeg,numpy_min]>=0.2.7
21
+ Requires-Dist: pyyaml
22
+ Requires-Dist: requests
23
+ Provides-Extra: test
24
+ Requires-Dist: pytest; extra == "test"
25
+ Requires-Dist: flake8; extra == "test"
26
+
27
+ # vitallens-python
28
+
29
+ [![Tests](https://github.com/Rouast-Labs/vitallens-python/actions/workflows/main.yml/badge.svg)](https://github.com/Rouast-Labs/vitallens-python/actions/workflows/main.yml)
30
+ [![PyPI Downloads](https://static.pepy.tech/personalized-badge/prpy?period=total&units=international_system&left_color=grey&right_color=blue&left_text=pip%20downloads)](https://pypi.org/project/prpy/)
31
+ [![Website](https://img.shields.io/badge/Website-rouast.com/api-blue.svg?logo=data:image/svg%2bxml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFRE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AtODQuMTExLDcuMDMgLTgxLjg0LDExLjIyQy03MS45NTUsMjkuNDQ2IC02OS4yMDIsMzMuNzM1IC02NC44NDYsMzMuOTc1Qy02NC42NjEsMzMuOTg1IC02NC40OCwzMy45ODkgLTY0LjMwNSwzMy45ODlDLTU4LjA2NCwzMy45ODkgLTU3LjY2MiwyNy4zMDQgLTU1LjkxNywtMS43ODdDLTU1LjYzMSwtNi41MyAtNTUuMywtMTIuMDcgLTU0LjkyNywtMTYuOTQ4Qy01NC41MTIsLTE1Ljg1MiAtNTQuMTI5LC0xNC44MjkgLTUzLjgwMywtMTMuOTU1Qy01MS4wNTYsLTYuNTk0IC01MC4xODcsLTQuNDExIC00OC40NzMsLTMuMDQyQy00NS44NywtMC45NjIgLTQzLjE0OSwtMS4zNjkgLTQxLjczNywtMS42MjhDLTQwLjYwMiwwLjMyOSAtMzguNjY0LDQuMjcxIC0zNy4xNjksNy4zMDZDLTI4LjgyNSwyNC4yNjQgLTI1LjE2OCwzMC42NzMgLTE5LjgxMiwzMC42NzNDLTEzLjE1NSwzMC42NzMgLTEyLjM2MiwyMi42NjYgLTEwLjI0NCwxLjI3MkMtOS42NjMsLTQuNjA2IC04Ljg4MiwtMTIuNDk2IC03Ljk5NiwtMTcuODMxQy02Ljk2MywtMTUuNzI5IC01Ljk1NCwtMTMuMzUgLTUuMzA3LC0xMS44MkMtMy4xNDUsLTYuNzIxIC0yLjAxNywtNC4yMDkgMCwtMi44MjgiIHN0eWxlPSJmaWxsOnJnYigwLDE2NCwyMjQpO2ZpbGwtcnVsZTpub256ZXJvOyIvPgogICAgPC9nPgo8L3N2Zz4K)](https://www.rouast.com/api/)
32
+ [![DOI](http://img.shields.io/:DOI-10.48550/arXiv.2312.06892-blue.svg?style=flat&logo=arxiv)](https://doi.org/10.48550/arXiv.2312.06892)
33
+
34
+ Estimate vital signs such as heart rate and respiratory rate from video.
35
+
36
+ `vitallens-python` is a Python client for the [**VitalLens API**](https://www.rouast.com/vitallens/), using the same neural net for inference as our [free iOS app VitalLens](https://apps.apple.com/us/app/vitallens/id6472757649).
37
+ Furthermore, it includes fast implementations of several other heart rate estimation methods from video such as `G`, `CHROM`, and `POS`.
38
+
39
+ - Accepts as input either a video filepath or an in-memory video as `np.ndarray`
40
+ - Performs fast face detection if required - you can also pass existing detections
41
+ - `vitallens.Method.VITALLENS` supports *heart rate*, *respiratory rate*, *pulse waveform*, and *respiratory waveform* estimation. In addition, it returns an estimation confidence for each vital. We are working to support more vital signs in the future.
42
+ - `vitallens.Method.{G/CHROM/POS}` support faster, but less accurate *heart rate* and *pulse waveform* estimation.
43
+ - While `VITALLENS` requires an API Key, `G`, `CHROM`, and `POS` do not. [Register on our website to get a free API Key.](https://www.rouast.com/api/)
44
+
45
+ Estimate vitals in a few lines of code:
46
+
47
+ ```python
48
+ from vitallens import VitalLens, Method
49
+
50
+ vl = VitalLens(method=Method.VITALLENS, api_key="YOUR_API_KEY")
51
+ result = vl("video.mp4")
52
+ print(result)
53
+ ```
54
+
55
+ ### Disclaimer
56
+
57
+ `vitallens-python` provides vital sign estimates for general wellness purposes only. It is not intended for medical use. Always consult with your doctor for any health concerns or for medically precise measurement.
58
+
59
+ See also our [Terms of Service for the VitalLens API](https://www.rouast.com/vitallens/api/terms) and our [Privacy Policy](https://www.rouast.com/vitallens/privacy).
60
+
61
+ ## Installation
62
+
63
+ General prerequisites are `python>=3.8` and `ffmpeg` installed and accessible via the `$PATH` environment variable.
64
+
65
+ The easiest way to install the latest version of `vitallens-python` and its Python dependencies:
66
+
67
+ ```
68
+ pip install vitallens
69
+ ```
70
+
71
+ Alternatively, it can be done by cloning the source:
72
+
73
+ ```
74
+ git clone https://github.com/Rouast-Labs/vitallens-python.git
75
+ pip install ./vitallens-python
76
+ ```
77
+
78
+ ## How to use
79
+
80
+ To start using `vitallens-python`, first create an instance of `vitallens.VitalLens`.
81
+ It can be configured using the following parameters:
82
+
83
+ | Parameter | Description | Default |
84
+ |----------------|------------------------------------------------------------------------------------|--------------------|
85
+ | method | Inference method. {`Method.VITALLENS`, `Method.POS`, `Method.CHROM` or `Method.G`} | `Method.VITALLENS` |
86
+ | api_key | Usage key for the VitalLens API (required for `Method.VITALLENS`) | `None` |
87
+ | detect_faces | `True` if faces need to be detected, otherwise `False`. | `True` |
88
+ | fdet_max_faces | The maximum number of faces to detect (if necessary). | `2` |
89
+ | fdet_fs | Frequency [Hz] at which faces should be scanned - otherwise linearly interpolated. | `1.0` |
90
+
91
+ Once instantiated, `vitallens.VitalLens` can be called to estimate vitals.
92
+ This can also be configured using the following parameters:
93
+
94
+ | Parameter | Description | Default |
95
+ |---------------------|---------------------------------------------------------------------------------------|---------|
96
+ | video | The video to analyze. Either a path to a video file or `np.ndarray`. [More info here.](https://github.com/Rouast-Labs/vitallens-python/blob/ddcf48f29a2765fd98a7029c0f10075a33e44247/vitallens/client.py#L98) | |
97
+ | faces | Face detections. Ignored unless `detect_faces=False`. [More info here.](https://github.com/Rouast-Labs/vitallens-python/blob/ddcf48f29a2765fd98a7029c0f10075a33e44247/vitallens/client.py#L101) | `None` |
98
+ | fps | Sampling frequency of the input video. Required if video is `np.ndarray`. | `None` |
99
+ | override_fps_target | Target frequency for inference (optional - use methods's default otherwise). | `None` |
100
+
101
+ The estimation results are returned as a `list`. It contains a `dict` for each distinct face, with the following structure:
102
+
103
+ ```
104
+ [
105
+ {
106
+ 'face': <face coords for each frame as np.ndarray of shape (n_frames, 4)>,
107
+ 'pulse': {
108
+ 'val': <estimated pulse waveform val for each frame as np.ndarray of shape (n_frames,)>,
109
+ 'conf': <estimation confidence for each frame as np.ndarray of shape (n_frames,)>,
110
+ },
111
+ 'resp': {
112
+ 'val': <estimated respiration waveform val for each frame as np.ndarray of shape (n_frames,)>,
113
+ 'conf': <estimation confidence for each frame as np.ndarray of shape (n_frames,)>,
114
+ },
115
+ 'hr': {
116
+ 'val': <estimated heart rate as float scalar>,
117
+ 'conf': <estimation confidence as float scalar>,
118
+ },
119
+ 'rr': {
120
+ 'val': <estimated respiratory rate as float scalar>,
121
+ 'conf': <estimation confidence as float scalar>,
122
+ },
123
+ 'live': <liveness estimation for each frame as np.ndarray of shape (n_frames,)>,
124
+ },
125
+ {
126
+ <same structure for face 2 if present>
127
+ },
128
+ ...
129
+ ]
130
+ ```
131
+
132
+ ### Example: Use VitalLens API to estimate vitals from a video file
133
+
134
+ ```python
135
+ from vitallens import VitalLens, Method
136
+
137
+ vl = VitalLens(method=Method.VITALLENS, api_key="YOUR_API_KEY")
138
+ result = vl("video.mp4")
139
+ ```
140
+
141
+ ### Example: Use POS method on an `np.ndarray` of video frames
142
+
143
+ ```python
144
+ from vitallens import VitalLens, Method
145
+
146
+ my_video_arr = ...
147
+ my_video_fps = 30
148
+ vl = VitalLens(method=Method.POS)
149
+ result = vl(my_video_arr, fps=my_video_fps)
150
+ ```
151
+
152
+ ## Linting and tests
153
+
154
+ Before running tests, please make sure that you have an environment variable `VITALLENS_DEV_API_KEY` set to a valid API Key.
155
+ To lint and run tests:
156
+
157
+ ```
158
+ flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
159
+ pytest
160
+ ```
161
+
162
+ ## Build
163
+
164
+ To build:
165
+
166
+ ```
167
+ python -m build
168
+ ```
@@ -0,0 +1,142 @@
1
+ # vitallens-python
2
+
3
+ [![Tests](https://github.com/Rouast-Labs/vitallens-python/actions/workflows/main.yml/badge.svg)](https://github.com/Rouast-Labs/vitallens-python/actions/workflows/main.yml)
4
+ [![PyPI Downloads](https://static.pepy.tech/personalized-badge/prpy?period=total&units=international_system&left_color=grey&right_color=blue&left_text=pip%20downloads)](https://pypi.org/project/prpy/)
5
+ [![Website](https://img.shields.io/badge/Website-rouast.com/api-blue.svg?logo=data:image/svg%2bxml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93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IC04OC44MTMsLTEuMTU3Qy04Ny4wNCwxLjYyOSAtODQuMTExLDcuMDMgLTgxLjg0LDExLjIyQy03MS45NTUsMjkuNDQ2IC02OS4yMDIsMzMuNzM1IC02NC44NDYsMzMuOTc1Qy02NC42NjEsMzMuOTg1IC02NC40OCwzMy45ODkgLTY0LjMwNSwzMy45ODlDLTU4LjA2NCwzMy45ODkgLTU3LjY2MiwyNy4zMDQgLTU1LjkxNywtMS43ODdDLTU1LjYzMSwtNi41MyAtNTUuMywtMTIuMDcgLTU0LjkyNywtMTYuOTQ4Qy01NC41MTIsLTE1Ljg1MiAtNTQuMTI5LC0xNC44MjkgLTUzLjgwMywtMTMuOTU1Qy01MS4wNTYsLTYuNTk0IC01MC4xODcsLTQuNDExIC00OC40NzMsLTMuMDQyQy00NS44NywtMC45NjIgLTQzLjE0OSwtMS4zNjkgLTQxLjczNywtMS42MjhDLTQwLjYwMiwwLjMyOSAtMzguNjY0LDQuMjcxIC0zNy4xNjksNy4zMDZDLTI4LjgyNSwyNC4yNjQgLTI1LjE2OCwzMC42NzMgLTE5LjgxMiwzMC42NzNDLTEzLjE1NSwzMC42NzMgLTEyLjM2MiwyMi42NjYgLTEwLjI0NCwxLjI3MkMtOS42NjMsLTQuNjA2IC04Ljg4MiwtMTIuNDk2IC03Ljk5NiwtMTcuODMxQy02Ljk2MywtMTUuNzI5IC01Ljk1NCwtMTMuMzUgLTUuMzA3LC0xMS44MkMtMy4xNDUsLTYuNzIxIC0yLjAxNywtNC4yMDkgMCwtMi44MjgiIHN0eWxlPSJmaWxsOnJnYigwLDE2NCwyMjQpO2ZpbGwtcnVsZTpub256ZXJvOyIvPgogICAgPC9nPgo8L3N2Zz4K)](https://www.rouast.com/api/)
6
+ [![DOI](http://img.shields.io/:DOI-10.48550/arXiv.2312.06892-blue.svg?style=flat&logo=arxiv)](https://doi.org/10.48550/arXiv.2312.06892)
7
+
8
+ Estimate vital signs such as heart rate and respiratory rate from video.
9
+
10
+ `vitallens-python` is a Python client for the [**VitalLens API**](https://www.rouast.com/vitallens/), using the same neural net for inference as our [free iOS app VitalLens](https://apps.apple.com/us/app/vitallens/id6472757649).
11
+ Furthermore, it includes fast implementations of several other heart rate estimation methods from video such as `G`, `CHROM`, and `POS`.
12
+
13
+ - Accepts as input either a video filepath or an in-memory video as `np.ndarray`
14
+ - Performs fast face detection if required - you can also pass existing detections
15
+ - `vitallens.Method.VITALLENS` supports *heart rate*, *respiratory rate*, *pulse waveform*, and *respiratory waveform* estimation. In addition, it returns an estimation confidence for each vital. We are working to support more vital signs in the future.
16
+ - `vitallens.Method.{G/CHROM/POS}` support faster, but less accurate *heart rate* and *pulse waveform* estimation.
17
+ - While `VITALLENS` requires an API Key, `G`, `CHROM`, and `POS` do not. [Register on our website to get a free API Key.](https://www.rouast.com/api/)
18
+
19
+ Estimate vitals in a few lines of code:
20
+
21
+ ```python
22
+ from vitallens import VitalLens, Method
23
+
24
+ vl = VitalLens(method=Method.VITALLENS, api_key="YOUR_API_KEY")
25
+ result = vl("video.mp4")
26
+ print(result)
27
+ ```
28
+
29
+ ### Disclaimer
30
+
31
+ `vitallens-python` provides vital sign estimates for general wellness purposes only. It is not intended for medical use. Always consult with your doctor for any health concerns or for medically precise measurement.
32
+
33
+ See also our [Terms of Service for the VitalLens API](https://www.rouast.com/vitallens/api/terms) and our [Privacy Policy](https://www.rouast.com/vitallens/privacy).
34
+
35
+ ## Installation
36
+
37
+ General prerequisites are `python>=3.8` and `ffmpeg` installed and accessible via the `$PATH` environment variable.
38
+
39
+ The easiest way to install the latest version of `vitallens-python` and its Python dependencies:
40
+
41
+ ```
42
+ pip install vitallens
43
+ ```
44
+
45
+ Alternatively, it can be done by cloning the source:
46
+
47
+ ```
48
+ git clone https://github.com/Rouast-Labs/vitallens-python.git
49
+ pip install ./vitallens-python
50
+ ```
51
+
52
+ ## How to use
53
+
54
+ To start using `vitallens-python`, first create an instance of `vitallens.VitalLens`.
55
+ It can be configured using the following parameters:
56
+
57
+ | Parameter | Description | Default |
58
+ |----------------|------------------------------------------------------------------------------------|--------------------|
59
+ | method | Inference method. {`Method.VITALLENS`, `Method.POS`, `Method.CHROM` or `Method.G`} | `Method.VITALLENS` |
60
+ | api_key | Usage key for the VitalLens API (required for `Method.VITALLENS`) | `None` |
61
+ | detect_faces | `True` if faces need to be detected, otherwise `False`. | `True` |
62
+ | fdet_max_faces | The maximum number of faces to detect (if necessary). | `2` |
63
+ | fdet_fs | Frequency [Hz] at which faces should be scanned - otherwise linearly interpolated. | `1.0` |
64
+
65
+ Once instantiated, `vitallens.VitalLens` can be called to estimate vitals.
66
+ This can also be configured using the following parameters:
67
+
68
+ | Parameter | Description | Default |
69
+ |---------------------|---------------------------------------------------------------------------------------|---------|
70
+ | video | The video to analyze. Either a path to a video file or `np.ndarray`. [More info here.](https://github.com/Rouast-Labs/vitallens-python/blob/ddcf48f29a2765fd98a7029c0f10075a33e44247/vitallens/client.py#L98) | |
71
+ | faces | Face detections. Ignored unless `detect_faces=False`. [More info here.](https://github.com/Rouast-Labs/vitallens-python/blob/ddcf48f29a2765fd98a7029c0f10075a33e44247/vitallens/client.py#L101) | `None` |
72
+ | fps | Sampling frequency of the input video. Required if video is `np.ndarray`. | `None` |
73
+ | override_fps_target | Target frequency for inference (optional - use methods's default otherwise). | `None` |
74
+
75
+ The estimation results are returned as a `list`. It contains a `dict` for each distinct face, with the following structure:
76
+
77
+ ```
78
+ [
79
+ {
80
+ 'face': <face coords for each frame as np.ndarray of shape (n_frames, 4)>,
81
+ 'pulse': {
82
+ 'val': <estimated pulse waveform val for each frame as np.ndarray of shape (n_frames,)>,
83
+ 'conf': <estimation confidence for each frame as np.ndarray of shape (n_frames,)>,
84
+ },
85
+ 'resp': {
86
+ 'val': <estimated respiration waveform val for each frame as np.ndarray of shape (n_frames,)>,
87
+ 'conf': <estimation confidence for each frame as np.ndarray of shape (n_frames,)>,
88
+ },
89
+ 'hr': {
90
+ 'val': <estimated heart rate as float scalar>,
91
+ 'conf': <estimation confidence as float scalar>,
92
+ },
93
+ 'rr': {
94
+ 'val': <estimated respiratory rate as float scalar>,
95
+ 'conf': <estimation confidence as float scalar>,
96
+ },
97
+ 'live': <liveness estimation for each frame as np.ndarray of shape (n_frames,)>,
98
+ },
99
+ {
100
+ <same structure for face 2 if present>
101
+ },
102
+ ...
103
+ ]
104
+ ```
105
+
106
+ ### Example: Use VitalLens API to estimate vitals from a video file
107
+
108
+ ```python
109
+ from vitallens import VitalLens, Method
110
+
111
+ vl = VitalLens(method=Method.VITALLENS, api_key="YOUR_API_KEY")
112
+ result = vl("video.mp4")
113
+ ```
114
+
115
+ ### Example: Use POS method on an `np.ndarray` of video frames
116
+
117
+ ```python
118
+ from vitallens import VitalLens, Method
119
+
120
+ my_video_arr = ...
121
+ my_video_fps = 30
122
+ vl = VitalLens(method=Method.POS)
123
+ result = vl(my_video_arr, fps=my_video_fps)
124
+ ```
125
+
126
+ ## Linting and tests
127
+
128
+ Before running tests, please make sure that you have an environment variable `VITALLENS_DEV_API_KEY` set to a valid API Key.
129
+ To lint and run tests:
130
+
131
+ ```
132
+ flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
133
+ pytest
134
+ ```
135
+
136
+ ## Build
137
+
138
+ To build:
139
+
140
+ ```
141
+ python -m build
142
+ ```