├── .gitattributes ├── .gitignore ├── LICENSE ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── Taskfile.yml ├── example └── simple_sample.py ├── hooks └── commit-msg ├── k4a ├── __init__.py ├── pyk4a.py └── pyk4abt.py └── setup.py /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 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 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 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 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2021, Hexops Contributors (given via the Git commit history). 2 | 3 | Licensed under the Apache License, Version 2.0 (see LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0) 4 | or the MIT license (see LICENSE-MIT or http://opensource.org/licenses/MIT), at 5 | your option. All files in the project without exclusions may not be copied, 6 | modified, or distributed except according to those terms. 7 | -------------------------------------------------------------------------------- /LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2021 Hexops Contributors (given via the Git commit history). 2 | 3 | Permission is hereby granted, free of charge, to any 4 | person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the 6 | Software without restriction, including without 7 | limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software 10 | is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice 14 | shall be included in all copies or substantial portions 15 | of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 18 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 19 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 24 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Azure-Kinect-Python 2 | 3 | Python 3 bindings for the Azure Kinect SDK 4 | 5 | ## Changelog 6 | 7 | - v1.1.0: Updated supported SDK and firmware versions to latest 8 | - v1.0.0: Initial release 9 | 10 | ## Setup 11 | 12 | Install the Kinect SDKs, update device firmware version if needed: 13 | 14 | * [Sensor SDK v1.4.1](https://github.com/microsoft/Azure-Kinect-Sensor-SDK/blob/develop/docs/usage.md#installation) 15 | * [Body tracking SDK v1.0.1](https://docs.microsoft.com/en-us/azure/kinect-dk/body-sdk-download) 16 | * Device firmware version must be at least 1.6.110079014 or higher. 17 | 18 | If on Linux, ensure the relevant `k4a.so` and `k4abt.so` dynamic libraries are on your path. 19 | 20 | ## Feature support 21 | 22 | Currently only body tracking is wrapped, but adding further wrappings should be easy and PRs would be appreciated! 23 | 24 | ## Examples 25 | 26 | There is a very simple example you can run via: 27 | 28 | ```sh 29 | py -3 example/simple_sample.py 30 | ``` 31 | 32 | ## Demos 33 | 34 | We are using it to develop an Azure Kinect plugin for [Blender](https://blender.org), which you can see a very early demo of here: 35 | 36 | [![Azure Kinect for Blender](https://img.youtube.com/vi/jFVq6SdOdHw/0.jpg)](https://www.youtube.com/watch?v=jFVq6SdOdHw) 37 | 38 | The plugin is available for early access and will be open-sourced soon, please email stephen@hexops.com to gain early access. 39 | 40 | ## Troubleshooting 41 | 42 | ### Do NOT use Python from the Windows Store 43 | 44 | If you get the error: 45 | 46 | ``` 47 | [2021-01-18 14:05:28.307] [error] [t=6336] [K4ABT] D:\a\1\s\src\TrackerHost\TrackerHost.cpp (157): Create(). Find onnxruntime.dll at C:\Program Files\Azure Kinect Body Tracking SDK\tools\onnxruntime.dll but it doesn't load correctly! 48 | ``` 49 | 50 | It is because the Windows Store installs Python to a restricted user directory which cannot access external DLLs. 51 | -------------------------------------------------------------------------------- /Taskfile.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | tasks: 4 | default: 5 | cmds: 6 | - git config core.hooksPath hooks 7 | -------------------------------------------------------------------------------- /example/simple_sample.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | This is a python port of the simple-sample project from. 4 | https://github.com/microsoft/Azure-Kinect-Samples/blob/bf2f8cf95d969dcc7842c4c450052fe5a943c756/body-tracking-samples/simple_sample/main.c 5 | """ 6 | 7 | import traceback 8 | import sys 9 | import ctypes 10 | import os 11 | 12 | # Add .. to the import path 13 | sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) 14 | 15 | import k4a 16 | 17 | def VERIFY(result, error): 18 | if result != k4a.K4A_RESULT_SUCCEEDED: 19 | print(error) 20 | traceback.print_stack() 21 | sys.exit(1) 22 | 23 | def print_body_information(body): 24 | print("Body ID: {}".format(body.id)) 25 | for i in range(k4a.K4ABT_JOINT_COUNT): 26 | position = body.skeleton.joints[i].position 27 | orientation = body.skeleton.joints[i].orientation 28 | confidence_level = body.skeleton.joints[i].confidence_level 29 | print("Joint[{}]: Position[mm] ( {}, {}, {} ); Orientation ( {}, {}, {}, {}); Confidence Level ({})".format( 30 | i, position.v[0], position.v[1], position.v[2], orientation.v[0], orientation.v[1], orientation.v[2], orientation.v[3], confidence_level 31 | )) 32 | 33 | def print_body_index_map_middle_line(body_index_map): 34 | print("print_body_index_map_middle_line not implemented") 35 | """ 36 | uint8_t* body_index_map_buffer = k4a_image_get_buffer(body_index_map); 37 | 38 | // Given body_index_map pixel type should be uint8, the stride_byte should be the same as width 39 | // TODO: Since there is no API to query the byte-per-pixel information, we have to compare the width and stride to 40 | // know the information. We should replace this assert with proper byte-per-pixel query once the API is provided by 41 | // K4A SDK. 42 | assert(k4a_image_get_stride_bytes(body_index_map) == k4a_image_get_width_pixels(body_index_map)); 43 | 44 | int middle_line_num = k4a_image_get_height_pixels(body_index_map) / 2; 45 | body_index_map_buffer = body_index_map_buffer + middle_line_num * k4a_image_get_width_pixels(body_index_map); 46 | 47 | printf("BodyIndexMap at Line %d:\n", middle_line_num); 48 | for (int i = 0; i < k4a_image_get_width_pixels(body_index_map); i++) 49 | { 50 | printf("%u, ", *body_index_map_buffer); 51 | body_index_map_buffer++; 52 | } 53 | printf("\n"); 54 | """ 55 | 56 | if __name__ == "__main__": 57 | device_config = k4a.K4A_DEVICE_CONFIG_INIT_DISABLE_ALL 58 | device_config.depth_mode = k4a.K4A_DEPTH_MODE_NFOV_UNBINNED 59 | 60 | device = k4a.k4a_device_t() 61 | VERIFY(k4a.k4a_device_open(0, ctypes.byref(device)), "Open K4A Device failed!") 62 | VERIFY(k4a.k4a_device_start_cameras(device, ctypes.byref(device_config)), "Start K4A cameras failed!") 63 | 64 | sensor_calibration = k4a.k4a_calibration_t() 65 | VERIFY(k4a.k4a_device_get_calibration(device, device_config.depth_mode, k4a.K4A_COLOR_RESOLUTION_OFF, ctypes.byref(sensor_calibration)), "Get depth camera calibration failed!") 66 | 67 | tracker = k4a.k4abt_tracker_t() 68 | tracker_config = k4a.K4ABT_TRACKER_CONFIG_DEFAULT 69 | VERIFY(k4a.k4abt_tracker_create(ctypes.byref(sensor_calibration), tracker_config, ctypes.byref(tracker)), "Body tracker initialization failed!") 70 | 71 | frame_count = 0 72 | while frame_count < 100: 73 | sensor_capture = k4a.k4a_capture_t() 74 | get_capture_result = k4a.k4a_device_get_capture(device, ctypes.byref(sensor_capture), k4a.K4A_WAIT_INFINITE) 75 | 76 | if get_capture_result == k4a.K4A_WAIT_RESULT_SUCCEEDED: 77 | frame_count += 1 78 | 79 | print("Start processing frame {}".format(frame_count)) 80 | 81 | queue_capture_result = k4a.k4abt_tracker_enqueue_capture(tracker, sensor_capture, k4a.K4A_WAIT_INFINITE) 82 | 83 | k4a.k4a_capture_release(sensor_capture) 84 | 85 | if queue_capture_result == k4a.K4A_WAIT_RESULT_TIMEOUT: 86 | # It should never hit timeout when K4A_WAIT_INFINITE is set. 87 | print("Error! Add capture to tracker process queue timeout!") 88 | break 89 | elif queue_capture_result == k4a.K4A_WAIT_RESULT_FAILED: 90 | print("Error! Add capture to tracker process queue failed!") 91 | break 92 | 93 | body_frame = k4a.k4abt_frame_t() 94 | pop_frame_result = k4a.k4abt_tracker_pop_result(tracker, ctypes.byref(body_frame), k4a.K4A_WAIT_INFINITE) 95 | if pop_frame_result == k4a.K4A_WAIT_RESULT_SUCCEEDED: 96 | num_bodies = k4a.k4abt_frame_get_num_bodies(body_frame) 97 | print("{} bodies are detected!".format(num_bodies)) 98 | 99 | for i in range(num_bodies): 100 | body = k4a.k4abt_body_t() 101 | VERIFY(k4a.k4abt_frame_get_body_skeleton(body_frame, i, ctypes.byref(body.skeleton)), "Get body from body frame failed!") 102 | body.id = k4a.k4abt_frame_get_body_id(body_frame, i) 103 | 104 | print_body_information(body) 105 | 106 | body_index_map = k4a.k4abt_frame_get_body_index_map(body_frame) 107 | if body_index_map: 108 | print_body_index_map_middle_line(body_index_map) 109 | k4a.k4a_image_release(body_index_map) 110 | else: 111 | print("Error: Fail to generate bodyindex map!") 112 | 113 | k4a.k4abt_frame_release(body_frame) 114 | elif pop_frame_result == k4a.K4A_WAIT_RESULT_TIMEOUT: 115 | # It should never hit timeout when K4A_WAIT_INFINITE is set. 116 | print("Error! Pop body frame result timeout!") 117 | break 118 | else: 119 | print("Pop body frame result failed!") 120 | break 121 | elif get_capture_result == k4a.K4A_WAIT_RESULT_TIMEOUT: 122 | # It should never hit timeout when K4A_WAIT_INFINITE is set. 123 | print("Error! Get depth frame time out!") 124 | break 125 | else: 126 | print("Get depth capture returned error: {}".format(get_capture_result)) 127 | 128 | print("Finished body tracking processing!") 129 | 130 | k4a.k4abt_tracker_shutdown(tracker) 131 | k4a.k4abt_tracker_destroy(tracker) 132 | k4a.k4a_device_stop_cameras(device) 133 | k4a.k4a_device_close(device) 134 | 135 | -------------------------------------------------------------------------------- /hooks/commit-msg: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Helper Git commit hook to ensure the DCO sign-off is present, to avoid 4 | # creating multiple commits without the DCO sign-off which is annoying to fix 5 | # and is required. 6 | # 7 | 8 | if ! grep -qE '^Signed-off-by: ' "$1"; then 9 | echo "Your commit message is not signed off with the DCO." >&2 10 | echo "" >&2 11 | echo "Please read and agree to the DCO: https://developercertificate.org/" >&2 12 | echo "" >&2 13 | echo "Hint: Use 'git commit -s' flag to sign your commits" >&2 14 | echo "" >&2 15 | echo "Hint: Use 'git commit -seF .git/COMMIT_EDITMSG' to recover your commit message and sign." >&2 16 | exit 1 17 | fi -------------------------------------------------------------------------------- /k4a/__init__.py: -------------------------------------------------------------------------------- 1 | from .pyk4a import * 2 | from .pyk4abt import * -------------------------------------------------------------------------------- /k4a/pyk4a.py: -------------------------------------------------------------------------------- 1 | import ctypes 2 | import enum 3 | import sys 4 | import os 5 | 6 | try: 7 | dirPath = os.path.dirname(os.path.abspath(__file__))+r'/../vendor/azure_kinect/windows/amd64/' 8 | print(dirPath) 9 | _k4a = ctypes.CDLL(dirPath+r'k4a.dll') 10 | os.environ['PATH'] = dirPath+';'+os.environ['PATH'] 11 | except Exception as e1: 12 | try: 13 | dirPath = r'C:/Program Files/Azure Kinect SDK v1.4.1/sdk/windows-desktop/amd64/release/bin/' 14 | _k4a = ctypes.CDLL(dirPath+r'k4a.dll') 15 | os.environ['PATH'] = dirPath+';'+os.environ['PATH'] 16 | except Exception as e2: 17 | try: 18 | _k4a = ctypes.CDLL('k4a.so') 19 | except Exception as e3: 20 | print("Failed to load library", e1, e2, e3) 21 | sys.exit(1) 22 | 23 | # K4A_DECLARE_HANDLE(k4a_device_t); 24 | class _handle_k4a_device_t(ctypes.Structure): 25 | _fields_= [ 26 | ("_rsvd", ctypes.c_size_t), 27 | ] 28 | k4a_device_t = ctypes.POINTER(_handle_k4a_device_t) 29 | 30 | # K4A_DECLARE_HANDLE(k4a_capture_t); 31 | class _handle_k4a_capture_t(ctypes.Structure): 32 | _fields_= [ 33 | ("_rsvd", ctypes.c_size_t), 34 | ] 35 | k4a_capture_t = ctypes.POINTER(_handle_k4a_capture_t) 36 | 37 | # K4A_DECLARE_HANDLE(k4a_image_t); 38 | class _handle_k4a_image_t(ctypes.Structure): 39 | _fields_= [ 40 | ("_rsvd", ctypes.c_size_t), 41 | ] 42 | k4a_image_t = ctypes.POINTER(_handle_k4a_image_t) 43 | 44 | # K4A_DECLARE_HANDLE(k4a_transformation_t); 45 | class _handle_k4a_transformation_t(ctypes.Structure): 46 | _fields_= [ 47 | ("_rsvd", ctypes.c_size_t), 48 | ] 49 | k4a_transformation_t = ctypes.POINTER(_handle_k4a_transformation_t) 50 | 51 | #class k4a_result_t(CtypeIntEnum): 52 | K4A_RESULT_SUCCEEDED = 0 53 | K4A_RESULT_FAILED = 1 54 | 55 | #class k4a_buffer_result_t(CtypeIntEnum): 56 | K4A_BUFFER_RESULT_SUCCEEDED = 0 57 | K4A_BUFFER_RESULT_FAILED = 1 58 | K4A_BUFFER_RESULT_TOO_SMALL = 2 59 | 60 | #class k4a_wait_result_t(CtypeIntEnum): 61 | K4A_WAIT_RESULT_SUCCEEDED = 0 62 | K4A_WAIT_RESULT_FAILED = 1 63 | K4A_WAIT_RESULT_TIMEOUT = 2 64 | 65 | #class k4a_log_level_t(CtypeIntEnum): 66 | K4A_LOG_LEVEL_CRITICAL = 0 67 | K4A_LOG_LEVEL_ERROR = 1 68 | K4A_LOG_LEVEL_WARNING = 2 69 | K4A_LOG_LEVEL_INFO = 3 70 | K4A_LOG_LEVEL_TRACE = 4 71 | K4A_LOG_LEVEL_OFF = 5 72 | 73 | #class k4a_depth_mode_t(CtypeIntEnum): 74 | K4A_DEPTH_MODE_OFF = 0 75 | K4A_DEPTH_MODE_NFOV_2X2BINNED = 1 76 | K4A_DEPTH_MODE_NFOV_UNBINNED = 2 77 | K4A_DEPTH_MODE_WFOV_2X2BINNED = 3 78 | K4A_DEPTH_MODE_WFOV_UNBINNED = 4 79 | K4A_DEPTH_MODE_PASSIVE_IR = 5 80 | 81 | #class k4a_color_resolution_t(CtypeIntEnum): 82 | K4A_COLOR_RESOLUTION_OFF = 0 83 | K4A_COLOR_RESOLUTION_720P = 1 84 | K4A_COLOR_RESOLUTION_1080P = 2 85 | K4A_COLOR_RESOLUTION_1440P = 3 86 | K4A_COLOR_RESOLUTION_1536P = 4 87 | K4A_COLOR_RESOLUTION_2160P = 5 88 | K4A_COLOR_RESOLUTION_3072P = 6 89 | 90 | #class k4a_image_format_t(CtypeIntEnum): 91 | K4A_IMAGE_FORMAT_COLOR_MJPG = 0 92 | K4A_IMAGE_FORMAT_COLOR_NV12 = 1 93 | K4A_IMAGE_FORMAT_COLOR_YUY2 = 2 94 | K4A_IMAGE_FORMAT_COLOR_BGRA32 = 3 95 | K4A_IMAGE_FORMAT_DEPTH16 = 4 96 | K4A_IMAGE_FORMAT_IR16 = 5 97 | K4A_IMAGE_FORMAT_CUSTOM8 = 6 98 | K4A_IMAGE_FORMAT_CUSTOM16 = 7 99 | K4A_IMAGE_FORMAT_CUSTOM = 8 100 | 101 | #class k4a_transformation_interpolation_type_t(CtypeIntEnum): 102 | K4A_TRANSFORMATION_INTERPOLATION_TYPE_NEAREST = 0 103 | K4A_TRANSFORMATION_INTERPOLATION_TYPE_LINEAR = 1 104 | 105 | #class k4a_fps_t(CtypeIntEnum): 106 | K4A_FRAMES_PER_SECOND_5 = 0 107 | K4A_FRAMES_PER_SECOND_15 = 1 108 | K4A_FRAMES_PER_SECOND_30 = 2 109 | 110 | #class k4a_color_control_command_t(CtypeIntEnum): 111 | K4A_COLOR_CONTROL_EXPOSURE_TIME_ABSOLUTE = 0 112 | K4A_COLOR_CONTROL_AUTO_EXPOSURE_PRIORITY = 1 113 | K4A_COLOR_CONTROL_BRIGHTNESS = 2 114 | K4A_COLOR_CONTROL_CONTRAST = 3 115 | K4A_COLOR_CONTROL_SATURATION = 4 116 | K4A_COLOR_CONTROL_SHARPNESS = 5 117 | K4A_COLOR_CONTROL_WHITEBALANCE = 6 118 | K4A_COLOR_CONTROL_BACKLIGHT_COMPENSATION = 7 119 | K4A_COLOR_CONTROL_GAIN = 8 120 | K4A_COLOR_CONTROL_POWERLINE_FREQUENCY = 9 121 | 122 | #class k4a_color_control_mode_t(CtypeIntEnum): 123 | K4A_COLOR_CONTROL_MODE_AUTO = 0 124 | K4A_COLOR_CONTROL_MODE_MANUAL = 1 125 | 126 | 127 | #class k4a_wired_sync_mode_t(CtypeIntEnum): 128 | K4A_WIRED_SYNC_MODE_STANDALONE = 0 129 | K4A_WIRED_SYNC_MODE_MASTER = 1 130 | K4A_WIRED_SYNC_MODE_SUBORDINATE = 2 131 | 132 | #class k4a_calibration_type_t(CtypeIntEnum): 133 | K4A_CALIBRATION_TYPE_UNKNOWN = -1 134 | K4A_CALIBRATION_TYPE_DEPTH = 0 135 | K4A_CALIBRATION_TYPE_COLOR = 1 136 | K4A_CALIBRATION_TYPE_GYRO = 2 137 | K4A_CALIBRATION_TYPE_ACCEL = 3 138 | K4A_CALIBRATION_TYPE_NUM = 4 139 | 140 | #class k4a_calibration_model_type_t(CtypeIntEnum): 141 | K4A_CALIBRATION_LENS_DISTORTION_MODEL_UNKNOWN = 0 142 | K4A_CALIBRATION_LENS_DISTORTION_MODEL_THETA = 1 143 | K4A_CALIBRATION_LENS_DISTORTION_MODEL_POLYNOMIAL_3K = 2 144 | K4A_CALIBRATION_LENS_DISTORTION_MODEL_RATIONAL_6KT = 3 145 | K4A_CALIBRATION_LENS_DISTORTION_MODEL_BROWN_CONRADY = 4 146 | 147 | #class k4a_firmware_build_t(CtypeIntEnum): 148 | K4A_FIRMWARE_BUILD_RELEASE = 0 149 | K4A_FIRMWARE_BUILD_DEBUG = 1 150 | 151 | #class k4a_firmware_signature_t(CtypeIntEnum): 152 | K4A_FIRMWARE_SIGNATURE_MSFT = 0 153 | K4A_FIRMWARE_SIGNATURE_TEST = 1 154 | K4A_FIRMWARE_SIGNATURE_UNSIGNED = 2 155 | 156 | #define K4A_SUCCEEDED(_result_) (_result_ == K4A_RESULT_SUCCEEDED) 157 | def K4A_SUCCEEDED(result): 158 | return result == K4A_RESULT_SUCCEEDED 159 | 160 | #define K4A_FAILED(_result_) (!K4A_SUCCEEDED(_result_)) 161 | def K4A_FAILED(result): 162 | return not K4A_SUCCEEDED(result) 163 | 164 | # TODO(Andoryuuta): Callbacks, are these needed? 165 | """ 166 | typedef void(k4a_logging_message_cb_t)(void *context, 167 | k4a_log_level_t level, 168 | const char *file, 169 | const int line, 170 | const char *message); 171 | 172 | typedef void(k4a_memory_destroy_cb_t)(void *buffer, void *context); 173 | typedef uint8_t *(k4a_memory_allocate_cb_t)(int size, void **context); 174 | """ 175 | 176 | class _k4a_device_configuration_t(ctypes.Structure): 177 | _fields_= [ 178 | ("color_format", ctypes.c_int), 179 | ("color_resolution", ctypes.c_int), 180 | ("depth_mode", ctypes.c_int), 181 | ("camera_fps", ctypes.c_int), 182 | ("synchronized_images_only", ctypes.c_bool), 183 | ("depth_delay_off_color_usec", ctypes.c_int32), 184 | ("wired_sync_mode", ctypes.c_int), 185 | ("subordinate_delay_off_master_usec", ctypes.c_uint32), 186 | ("disable_streaming_indicator", ctypes.c_bool), 187 | ] 188 | 189 | k4a_device_configuration_t = _k4a_device_configuration_t 190 | 191 | class _k4a_calibration_extrinsics_t(ctypes.Structure): 192 | _fields_= [ 193 | ("rotation", ctypes.c_float * 9), 194 | ("translation", ctypes.c_float * 3), 195 | ] 196 | k4a_calibration_extrinsics_t = _k4a_calibration_extrinsics_t 197 | 198 | class _param(ctypes.Structure): 199 | _fields_ = [ 200 | ("cx", ctypes.c_float), 201 | ("cy", ctypes.c_float), 202 | ("fx", ctypes.c_float), 203 | ("fy", ctypes.c_float), 204 | ("k1", ctypes.c_float), 205 | ("k2", ctypes.c_float), 206 | ("k3", ctypes.c_float), 207 | ("k4", ctypes.c_float), 208 | ("k5", ctypes.c_float), 209 | ("k6", ctypes.c_float), 210 | ("codx", ctypes.c_float), 211 | ("cody", ctypes.c_float), 212 | ("p2", ctypes.c_float), 213 | ("p1", ctypes.c_float), 214 | ("metric_radius", ctypes.c_float), 215 | ] 216 | 217 | class k4a_calibration_intrinsic_parameters_t(ctypes.Union): 218 | _fields_= [ 219 | ("param", _param), 220 | ("v", ctypes.c_float * 15), 221 | ] 222 | 223 | class _k4a_calibration_intrinsics_t(ctypes.Structure): 224 | _fields_= [ 225 | ("type", ctypes.c_int), 226 | ("parameter_count", ctypes.c_uint), 227 | ("parameters", k4a_calibration_intrinsic_parameters_t), 228 | ] 229 | 230 | k4a_calibration_intrinsics_t = _k4a_calibration_intrinsics_t 231 | 232 | class _k4a_calibration_camera_t(ctypes.Structure): 233 | _fields_= [ 234 | ("extrinsics", k4a_calibration_extrinsics_t), 235 | ("intrinsics", k4a_calibration_intrinsics_t), 236 | ("resolution_width", ctypes.c_int), 237 | ("resolution_height", ctypes.c_int), 238 | ("metric_radius", ctypes.c_float), 239 | ] 240 | k4a_calibration_camera_t = _k4a_calibration_camera_t 241 | 242 | class _k4a_calibration_t(ctypes.Structure): 243 | _fields_= [ 244 | ("depth_camera_calibration", k4a_calibration_camera_t), 245 | ("color_camera_calibration", k4a_calibration_camera_t), 246 | ("extrinsics", (k4a_calibration_extrinsics_t * K4A_CALIBRATION_TYPE_NUM) * K4A_CALIBRATION_TYPE_NUM), 247 | ("depth_mode", ctypes.c_int), 248 | ("color_resolution", ctypes.c_int), 249 | ] 250 | k4a_calibration_t = _k4a_calibration_t 251 | 252 | class _k4a_version_t(ctypes.Structure): 253 | _fields_= [ 254 | ("major", ctypes.c_uint32), 255 | ("minor", ctypes.c_uint32), 256 | ("iteration", ctypes.c_uint32), 257 | ] 258 | k4a_version_t = _k4a_version_t 259 | 260 | 261 | class _k4a_hardware_version_t(ctypes.Structure): 262 | _fields_= [ 263 | ("rgb", k4a_version_t), 264 | ("depth", k4a_version_t), 265 | ("audio", k4a_version_t), 266 | ("depth_sensor", k4a_version_t), 267 | ("firmware_build", ctypes.c_int), 268 | ("firmware_signature", ctypes.c_int), 269 | ] 270 | k4a_hardware_version_t = _k4a_hardware_version_t 271 | 272 | class _xy(ctypes.Structure): 273 | _fields_= [ 274 | ("x", ctypes.c_float), 275 | ("y", ctypes.c_float), 276 | ] 277 | 278 | class k4a_float2_t(ctypes.Union): 279 | _fields_= [ 280 | ("xy", _xy), 281 | ("v", ctypes.c_float * 2) 282 | ] 283 | 284 | class _xyz(ctypes.Structure): 285 | _fields_= [ 286 | ("x", ctypes.c_float), 287 | ("y", ctypes.c_float), 288 | ("z", ctypes.c_float), 289 | ] 290 | 291 | class k4a_float3_t(ctypes.Union): 292 | _fields_= [ 293 | ("xyz", _xyz), 294 | ("v", ctypes.c_float * 3) 295 | ] 296 | 297 | class _k4a_imu_sample_t(ctypes.Structure): 298 | _fields_= [ 299 | ("temperature", ctypes.c_float), 300 | ("acc_sample", k4a_float3_t), 301 | ("acc_timestamp_usec", ctypes.c_uint64), 302 | ("gyro_sample", k4a_float3_t), 303 | ("gyro_timestamp_usec", ctypes.c_uint64), 304 | ] 305 | k4a_imu_sample_t = _k4a_imu_sample_t 306 | 307 | K4A_DEVICE_DEFAULT = 0 308 | K4A_WAIT_INFINITE = -1 309 | 310 | # TODO(Andoryuuta): Not sure if a single instance of the default config like this will work, might need a creation function. 311 | K4A_DEVICE_CONFIG_INIT_DISABLE_ALL = k4a_device_configuration_t() 312 | K4A_DEVICE_CONFIG_INIT_DISABLE_ALL.color_format = K4A_IMAGE_FORMAT_COLOR_MJPG 313 | K4A_DEVICE_CONFIG_INIT_DISABLE_ALL.color_resolution = K4A_COLOR_RESOLUTION_OFF 314 | K4A_DEVICE_CONFIG_INIT_DISABLE_ALL.depth_mode = K4A_DEPTH_MODE_OFF 315 | K4A_DEVICE_CONFIG_INIT_DISABLE_ALL.camera_fps = K4A_FRAMES_PER_SECOND_30 316 | K4A_DEVICE_CONFIG_INIT_DISABLE_ALL.synchronized_images_only = False 317 | K4A_DEVICE_CONFIG_INIT_DISABLE_ALL.depth_delay_off_color_usec = 0 318 | K4A_DEVICE_CONFIG_INIT_DISABLE_ALL.wired_sync_mode = K4A_WIRED_SYNC_MODE_STANDALONE 319 | K4A_DEVICE_CONFIG_INIT_DISABLE_ALL.subordinate_delay_off_master_usec = 0 320 | K4A_DEVICE_CONFIG_INIT_DISABLE_ALL.disable_streaming_indicator = False 321 | 322 | # Functions 323 | #K4A_EXPORT k4a_result_t k4a_device_open(uint32_t index, k4a_device_t *device_handle); 324 | k4a_device_open = _k4a.k4a_device_open 325 | k4a_device_open.restype=ctypes.c_int 326 | k4a_device_open.argtypes=(ctypes.c_uint32, ctypes.POINTER(k4a_device_t)) 327 | 328 | #K4A_EXPORT k4a_result_t k4a_device_start_cameras(k4a_device_t device_handle, const k4a_device_configuration_t *config); 329 | k4a_device_start_cameras = _k4a.k4a_device_start_cameras 330 | k4a_device_start_cameras.restype=ctypes.c_int 331 | k4a_device_start_cameras.argtypes=(k4a_device_t, ctypes.POINTER(k4a_device_configuration_t)) 332 | 333 | """ 334 | K4A_EXPORT k4a_result_t k4a_device_get_calibration(k4a_device_t device_handle, 335 | const k4a_depth_mode_t depth_mode, 336 | const k4a_color_resolution_t color_resolution, 337 | k4a_calibration_t *calibration); 338 | """ 339 | k4a_device_get_calibration = _k4a.k4a_device_get_calibration 340 | k4a_device_get_calibration.restype=ctypes.c_int 341 | k4a_device_get_calibration.argtypes=(k4a_device_t, ctypes.c_int, ctypes.c_int, ctypes.POINTER(k4a_calibration_t)) 342 | 343 | """ 344 | K4A_EXPORT k4a_wait_result_t k4a_device_get_capture(k4a_device_t device_handle, 345 | k4a_capture_t *capture_handle, 346 | int32_t timeout_in_ms); 347 | """ 348 | k4a_device_get_capture = _k4a.k4a_device_get_capture 349 | k4a_device_get_capture.restype=ctypes.c_int 350 | k4a_device_get_capture.argtypes=(k4a_device_t, ctypes.POINTER(k4a_capture_t), ctypes.c_int32) 351 | 352 | #K4A_EXPORT void k4a_capture_release(k4a_capture_t capture_handle); 353 | k4a_capture_release = _k4a.k4a_capture_release 354 | k4a_capture_release.argtypes=(k4a_capture_t,) 355 | 356 | #K4A_EXPORT void k4a_image_release(k4a_image_t image_handle); 357 | k4a_image_release = _k4a.k4a_image_release 358 | k4a_image_release.argtypes=(k4a_image_t,) 359 | 360 | #K4A_EXPORT void k4a_device_stop_cameras(k4a_device_t device_handle); 361 | k4a_device_stop_cameras = _k4a.k4a_device_stop_cameras 362 | k4a_device_stop_cameras.argtypes=(k4a_device_t,) 363 | 364 | #K4A_EXPORT void k4a_device_close(k4a_device_t device_handle); 365 | k4a_device_close = _k4a.k4a_device_close 366 | k4a_device_close.argtypes=(k4a_device_t,) 367 | -------------------------------------------------------------------------------- /k4a/pyk4abt.py: -------------------------------------------------------------------------------- 1 | import ctypes 2 | import enum 3 | import sys 4 | import os 5 | 6 | from .pyk4a import k4a_float3_t, k4a_calibration_t, k4a_capture_t, k4a_image_t 7 | 8 | try: 9 | dirPath = os.path.dirname(os.path.abspath(__file__))+r'/../vendor/azure_kinect/windows/amd64/' 10 | _k4abt = ctypes.CDLL(dirPath+r'k4abt.dll') 11 | os.environ['PATH'] = dirPath+';'+os.environ['PATH'] 12 | except Exception as e1: 13 | try: 14 | dirPath = r'C:/Program Files/Azure Kinect Body Tracking SDK/tools/' 15 | _k4abt = ctypes.CDLL(dirPath+r'k4abt.dll') 16 | os.environ['PATH'] = dirPath+';'+os.environ['PATH'] 17 | except Exception as e2: 18 | try: 19 | _k4abt = ctypes.CDLL('k4abt.so') 20 | except Exception as e3: 21 | print("Failed to load library", e1, e2, e3) 22 | sys.exit(1) 23 | 24 | # K4A_DECLARE_HANDLE(k4abt_tracker_t); 25 | class _handle_k4abt_tracker_t(ctypes.Structure): 26 | _fields_= [ 27 | ("_rsvd", ctypes.c_size_t), 28 | ] 29 | k4abt_tracker_t = ctypes.POINTER(_handle_k4abt_tracker_t) 30 | 31 | # K4A_DECLARE_HANDLE(k4abt_frame_t); 32 | class _handle_k4abt_frame_t(ctypes.Structure): 33 | _fields_= [ 34 | ("_rsvd", ctypes.c_size_t), 35 | ] 36 | k4abt_frame_t = ctypes.POINTER(_handle_k4abt_frame_t) 37 | 38 | #class k4abt_joint_id_t(CtypeIntEnum): 39 | K4ABT_JOINT_PELVIS = 0 40 | K4ABT_JOINT_SPINE_NAVEL = 1 41 | K4ABT_JOINT_SPINE_CHEST = 2 42 | K4ABT_JOINT_NECK = 3 43 | K4ABT_JOINT_CLAVICLE_LEFT = 4 44 | K4ABT_JOINT_SHOULDER_LEFT = 5 45 | K4ABT_JOINT_ELBOW_LEFT = 6 46 | K4ABT_JOINT_WRIST_LEFT = 7 47 | K4ABT_JOINT_HAND_LEFT = 8 48 | K4ABT_JOINT_HANDTIP_LEFT = 9 49 | K4ABT_JOINT_THUMB_LEFT = 10 50 | K4ABT_JOINT_CLAVICLE_RIGHT = 11 51 | K4ABT_JOINT_SHOULDER_RIGHT = 12 52 | K4ABT_JOINT_ELBOW_RIGHT = 13 53 | K4ABT_JOINT_WRIST_RIGHT = 14 54 | K4ABT_JOINT_HAND_RIGHT = 15 55 | K4ABT_JOINT_HANDTIP_RIGHT = 16 56 | K4ABT_JOINT_THUMB_RIGHT = 17 57 | K4ABT_JOINT_HIP_LEFT = 18 58 | K4ABT_JOINT_KNEE_LEFT = 19 59 | K4ABT_JOINT_ANKLE_LEFT = 20 60 | K4ABT_JOINT_FOOT_LEFT = 21 61 | K4ABT_JOINT_HIP_RIGHT = 22 62 | K4ABT_JOINT_KNEE_RIGHT = 23 63 | K4ABT_JOINT_ANKLE_RIGHT = 24 64 | K4ABT_JOINT_FOOT_RIGHT = 25 65 | K4ABT_JOINT_HEAD = 26 66 | K4ABT_JOINT_NOSE = 27 67 | K4ABT_JOINT_EYE_LEFT = 28 68 | K4ABT_JOINT_EAR_LEFT = 29 69 | K4ABT_JOINT_EYE_RIGHT = 30 70 | K4ABT_JOINT_EAR_RIGHT = 31 71 | K4ABT_JOINT_COUNT = 33 72 | 73 | #class k4abt_sensor_orientation_t(CtypeIntEnum): 74 | K4ABT_SENSOR_ORIENTATION_DEFAULT = 0 75 | K4ABT_SENSOR_ORIENTATION_CLOCKWISE90 = 1 76 | K4ABT_SENSOR_ORIENTATION_COUNTERCLOCKWISE90 = 2 77 | K4ABT_SENSOR_ORIENTATION_FLIP180 = 3 78 | 79 | #class k4abt_tracker_processing_mode_t(CtypeIntEnum): 80 | K4ABT_TRACKER_PROCESSING_MODE_GPU = 0 81 | K4ABT_TRACKER_PROCESSING_MODE_CPU = 1 82 | 83 | class _k4abt_tracker_configuration_t(ctypes.Structure): 84 | _fields_= [ 85 | ("sensor_orientation", ctypes.c_int), 86 | ("processing_mode", ctypes.c_int), 87 | ("gpu_device_id", ctypes.c_int32), 88 | ] 89 | k4abt_tracker_configuration_t = _k4abt_tracker_configuration_t 90 | 91 | class _wxyz(ctypes.Structure): 92 | _fields_= [ 93 | ("w", ctypes.c_float), 94 | ("x", ctypes.c_float), 95 | ("y", ctypes.c_float), 96 | ("z", ctypes.c_float), 97 | ] 98 | 99 | class k4a_quaternion_t(ctypes.Union): 100 | _fields_= [ 101 | ("wxyz", _wxyz), 102 | ("v", ctypes.c_float * 4) 103 | ] 104 | 105 | #class k4abt_joint_confidence_level_t(CtypeIntEnum): 106 | K4ABT_JOINT_CONFIDENCE_NONE = 0 107 | K4ABT_JOINT_CONFIDENCE_LOW = 1 108 | K4ABT_JOINT_CONFIDENCE_MEDIUM = 2 109 | K4ABT_JOINT_CONFIDENCE_HIGH = 3 110 | K4ABT_JOINT_CONFIDENCE_LEVELS_COUNT = 4 111 | 112 | 113 | class _k4abt_joint_t(ctypes.Structure): 114 | _fields_= [ 115 | ("position", k4a_float3_t), 116 | ("orientation", k4a_quaternion_t), 117 | ("confidence_level", ctypes.c_int), 118 | ] 119 | k4abt_joint_t = _k4abt_joint_t 120 | 121 | class k4abt_skeleton_t(ctypes.Structure): 122 | _fields_= [ 123 | ("joints", _k4abt_joint_t * K4ABT_JOINT_COUNT), 124 | ] 125 | 126 | class k4abt_body_t(ctypes.Structure): 127 | _fields_= [ 128 | ("id", ctypes.c_uint32), 129 | ("skeleton", k4abt_skeleton_t), 130 | ] 131 | 132 | K4ABT_BODY_INDEX_MAP_BACKGROUND = 255 133 | K4ABT_INVALID_BODY_ID = 0xFFFFFFFF 134 | K4ABT_DEFAULT_TRACKER_SMOOTHING_FACTOR = 0.0 135 | 136 | # TODO(Andoryuuta): Not sure if a single instance of the default config like this will work, might need a creation function. 137 | K4ABT_TRACKER_CONFIG_DEFAULT = k4abt_tracker_configuration_t() 138 | K4ABT_TRACKER_CONFIG_DEFAULT.sensor_orientation = K4ABT_SENSOR_ORIENTATION_DEFAULT 139 | K4ABT_TRACKER_CONFIG_DEFAULT.processing_mode = K4ABT_TRACKER_PROCESSING_MODE_GPU 140 | K4ABT_TRACKER_CONFIG_DEFAULT.gpu_device_id = 0 141 | 142 | # Functions 143 | k4abt_tracker_create = _k4abt.k4abt_tracker_create 144 | k4abt_tracker_create.restype=ctypes.c_int 145 | k4abt_tracker_create.argtypes=(ctypes.POINTER(k4a_calibration_t), k4abt_tracker_configuration_t, ctypes.POINTER(k4abt_tracker_t)) 146 | 147 | k4abt_tracker_destroy = _k4abt.k4abt_tracker_destroy 148 | k4abt_tracker_destroy.argtypes=(k4abt_tracker_t,) 149 | 150 | k4abt_tracker_set_temporal_smoothing = _k4abt.k4abt_tracker_set_temporal_smoothing 151 | k4abt_tracker_set_temporal_smoothing.argtypes=(k4abt_tracker_t, ctypes.c_float) 152 | 153 | k4abt_tracker_enqueue_capture = _k4abt.k4abt_tracker_enqueue_capture 154 | k4abt_tracker_enqueue_capture.restype=ctypes.c_int 155 | k4abt_tracker_enqueue_capture.argtypes=(k4abt_tracker_t, k4a_capture_t, ctypes.c_int32) 156 | 157 | k4abt_tracker_pop_result = _k4abt.k4abt_tracker_pop_result 158 | k4abt_tracker_pop_result.restype=ctypes.c_int 159 | k4abt_tracker_pop_result.argtypes=(k4abt_tracker_t, ctypes.POINTER(k4abt_frame_t), ctypes.c_int32) 160 | 161 | k4abt_tracker_shutdown = _k4abt.k4abt_tracker_shutdown 162 | k4abt_tracker_shutdown.argtypes=(k4abt_tracker_t,) 163 | 164 | k4abt_frame_release = _k4abt.k4abt_frame_release 165 | k4abt_frame_release.argtypes=(k4abt_frame_t,) 166 | 167 | k4abt_frame_reference = _k4abt.k4abt_frame_reference 168 | k4abt_frame_reference.argtypes=(k4abt_frame_t,) 169 | 170 | k4abt_frame_get_num_bodies = _k4abt.k4abt_frame_get_num_bodies 171 | k4abt_frame_get_num_bodies.restype=ctypes.c_uint32 172 | k4abt_frame_get_num_bodies.argtypes=(k4abt_frame_t,) 173 | 174 | k4abt_frame_get_body_skeleton = _k4abt.k4abt_frame_get_body_skeleton 175 | k4abt_frame_get_body_skeleton.restype=ctypes.c_int 176 | k4abt_frame_get_body_skeleton.argtypes=(k4abt_frame_t, ctypes.c_uint32, ctypes.POINTER(k4abt_skeleton_t)) 177 | 178 | k4abt_frame_get_body_id = _k4abt.k4abt_frame_get_body_id 179 | k4abt_frame_get_body_id.restype=ctypes.c_uint32 180 | k4abt_frame_get_body_id.argtypes=(k4abt_frame_t, ctypes.c_uint32) 181 | 182 | k4abt_frame_get_device_timestamp_usec = _k4abt.k4abt_frame_get_device_timestamp_usec 183 | k4abt_frame_get_device_timestamp_usec.restype=ctypes.c_uint64 184 | k4abt_frame_get_device_timestamp_usec.argtypes=(k4abt_frame_t,) 185 | 186 | k4abt_frame_get_body_index_map = _k4abt.k4abt_frame_get_body_index_map 187 | k4abt_frame_get_body_index_map.restype=k4a_image_t 188 | k4abt_frame_get_body_index_map.argtypes=(k4abt_frame_t,) 189 | 190 | k4abt_frame_get_capture = _k4abt.k4abt_frame_get_capture 191 | k4abt_frame_get_capture.restype=k4a_capture_t 192 | k4abt_frame_get_capture.argtypes=(k4abt_frame_t,) 193 | 194 | if __name__ == "__main__": 195 | print("Main called okay.") 196 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import setuptools 2 | 3 | with open("README.md", "r") as fh: 4 | long_description = fh.read() 5 | 6 | setuptools.setup( 7 | name="k4a", 8 | version="1.1.0", 9 | author="The HexOps Authors", 10 | author_email="stephen.gutekanst@gmail.com", 11 | description="Python 3 bindings for the Azure Kinect SDK", 12 | long_description=long_description, 13 | long_description_content_type="text/markdown", 14 | url="https://github.com/hexops/Azure-Kinect-Python", 15 | packages=setuptools.find_packages(), 16 | classifiers=[ 17 | "Programming Language :: Python :: 3", 18 | "License :: OSI Approved :: MIT License", 19 | "License :: OSI Approved :: Apache Software License", 20 | "Operating System :: OS Independent", 21 | ], 22 | python_requires='>=3.6', 23 | ) --------------------------------------------------------------------------------