├── .github └── workflows │ └── main.yml ├── .gitignore ├── CHANGELOG.md ├── CONTRIBUTING.md ├── DCO ├── LICENSE ├── README.md ├── examples ├── seekcamera-opencv.py ├── seekcamera-opencv_record.py └── seekcamera-simple.py ├── pyproject.toml ├── requirements.examples.txt ├── requirements.txt ├── seekcamera ├── __init__.py ├── _clib.py ├── camera.py ├── error.py └── version.py └── setup.py /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | # This workflow will install Python dependencies, run tests and lint with a variety of Python versions 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions 3 | 4 | name: main 5 | 6 | on: 7 | push: 8 | branches: [ main ] 9 | pull_request: 10 | branches: [ main ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | strategy: 17 | fail-fast: false 18 | matrix: 19 | python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] 20 | 21 | steps: 22 | - uses: actions/checkout@v2 23 | - name: Set up Python ${{ matrix.python-version }} 24 | uses: actions/setup-python@v2 25 | with: 26 | python-version: ${{ matrix.python-version }} 27 | - name: Install dependencies 28 | run: | 29 | python -m pip install --upgrade pip 30 | python -m pip install flake8 black 31 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 32 | - name: Lint with flake8 33 | run: | 34 | # stop the build if there are Python syntax errors or undefined names 35 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 36 | - name: Lint with black 37 | run: | 38 | # run formatting checks 39 | black --check . -------------------------------------------------------------------------------- /.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 | 131 | # VSCode 132 | .vscode/ 133 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # CHANGELOG 2 | 3 | # v1.3.0 4 | 5 | Fourth stable release of the Python language bindings for the Seek Thermal SDK 4.X. 6 | 7 | Released on 06/06/2023. 8 | 9 | Highlights 10 | * New APIs to wrap Pipeline APIs added to the C SDK (Seek Vision, Legacy, Lite) 11 | * Adjust API to wrap Linear AGC Min & Max APIs modified in the C SDK 12 | * New API to wrap the Sharpening Filter added to the C SDK 13 | * New API to wrap the HistEQ ROI APIs added to the C SDK 14 | * New example added which includes Video Recording 15 | 16 | ## v1.2.0 17 | 18 | Third stable release of the Python language bindings for the Seek Thermal SDK 4.X. 19 | 20 | Released on 07/06/2022 21 | 22 | Highlights 23 | * New APIs to wrap AGC APIs added to the C SDK (HistEQ, Linear) 24 | * New APIs to wrap frame locking APIs added to the C SDK 25 | * Bug fix for `cseekcamera_store_app_resources` which did not match the C API signature 26 | * Bug fix for `cseekcamera_load_app_resources` which did not match the C API signature 27 | * Bug fix for `SeekFrame.is_empty` API which accessed invalid `.value` attribute for bool type 28 | 29 | ## v1.1.1 30 | 31 | Stable patch release for v1.1.X. 32 | 33 | Released on 06/24/2021. 34 | 35 | Highlights 36 | * Bug fix for invalid argtypes assignment in seekcamera_set_temperature_unit CDLL stub. 37 | * Bug fix for missing conversions of enumerated integers to higher-level SeekCamera objects. 38 | 39 | ## v1.1.0 40 | 41 | Second stable release of the Python language bindings for the Seek Thermal SDK 4.X. 42 | 43 | Released on 06/01/2021. 44 | 45 | Highlights 46 | * New feature for creating user-defined color palettes 47 | * Bug fixes and improvements released in 4.1; see SDK release notes for more 48 | 49 | ## v1.0.0 50 | 51 | First stable release of the Python language bindings for the Seek Thermal SDK 4.X. 52 | 53 | Released on 05/20/2021. 54 | 55 | Highlights 56 | * Asynchronous event driven API that is fast and responsive 57 | * Ability to use multiple cameras in one SDK instance 58 | * Common set of APIs for both Mosaic and Micro Core cameras 59 | * Robust error handling and logging interface 60 | * Numerous frame output formats 61 | * Example applications to learn and get started 62 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contribution Guide 2 | 3 | This is the official guide for contributing to the `seekcamera-python` project. 4 | 5 | This project was created in the spirit of growing the Seek Thermal software ecosystem in an organic, positive way. 6 | Anyone wishing to contribute to the project should read this document first. 7 | 8 | ## What we are looking for 9 | 10 | All kinds of things! 11 | We are always looking for contributions. 12 | 13 | Find an issue, think of a new feature, or have an improvement? We courage you to submit a pull request. 14 | Not a developer? We like help with testing and documentation too. 15 | 16 | ## Note on authoring changes 17 | 18 | We use the Developer Certificate of Origin (DCO) in lieu of a Contributor License Agreement for all contributions to Seek Thermal’s open source projects. 19 | Please make sure you understand the terms of the [DCO](./DCO) before contributiing. 20 | 21 | ## Versioning 22 | 23 | We use a three digit versioning scheme. 24 | At the moment, there is not a set release cadence -- as this project grows, we will consider setting one. 25 | 26 | ```txt 27 | [major].[minor].[patch] 28 | ``` 29 | 30 | Releases generally increment the `minor` version number. 31 | The `major` version number is only incremented for major changes. 32 | The `patch` version number is incremented for patched releases that do not introduce new features. 33 | 34 | ## Branching 35 | 36 | The top-of-tree branch is `main`. 37 | Release tags are created on this branch. 38 | 39 | If you are submitting a pull request, please submit it to `main`. 40 | 41 | ### Creating a branch 42 | 43 | The first step in making a code change is to create a new branch. 44 | 45 | ```bash 46 | # Use main as the starting branch 47 | git checkout main 48 | 49 | # Create a branch 50 | git checkout -b feature-my-change 51 | ``` 52 | 53 | ### Making commits 54 | 55 | Commit messages should be clear and use imperative language. 56 | 57 | Note that we use the [Protobot DCO](https://github.com/apps/dco) GitHub app to check for DCO signoffs of every commit. 58 | The Protobot DCO app will provide instructions on how to ammend your commits if it catches an issue; to stay ahead of the curve please sign all commits with the `-s` flag. 59 | 60 | ```txt 61 | git commit -s 62 | ``` 63 | 64 | ### Keeping the branch up to date 65 | 66 | The starting branch may change while making a change. 67 | If you have a long lived branch, it is recommended to keep it up to date. 68 | Use no fast-forward merging to create a merge commit. 69 | 70 | ```bash 71 | git pull 72 | 73 | git checkout feature-my-change 74 | 75 | git merge --no-ff origin/main 76 | ``` 77 | 78 | ### Pushing to the remote 79 | 80 | ```bash 81 | git push -u origin feature-my-change 82 | ``` 83 | 84 | ## Pull requests 85 | 86 | The mechanism to get a code change merged is via pull requests (PRs). 87 | The following guidelines should be followed when submitting a PR: 88 | * Clear and imperative description of what is being changed and why 89 | * This helps save time in reviewing; it also helps others navigate the history. 90 | * Doc strings for public methods 91 | * This is how we document our APIs. 92 | * Testing of all sample applications 93 | * We require all changes be thoroughly tested before submitting a PR. 94 | We understand that you may have limited hardware -- that is okay. 95 | Test with what you have and let us know what tests were run and on what hardware. 96 | * Any additional unit testing 97 | * We are always thrilled to see more tests! 98 | * Passing of all CI actions 99 | * GitHub will warn you in the PR page if any fail. 100 | * Sign off all commits as in compliance with the [DCO](./DCO) 101 | * No merge conflicts 102 | * If you are unsure of how to resolve a conflict we can help. 103 | 104 | ## Style guide 105 | 106 | We use [black](https://pypi.org/project/black/) for code formatting. 107 | One of the GitHub Actions will check formatting when opening a PR. 108 | 109 | ```txt 110 | # Install black 111 | pip3 install black 112 | 113 | # Run black in the current directory 114 | black . 115 | ``` -------------------------------------------------------------------------------- /DCO: -------------------------------------------------------------------------------- 1 | We use the Developer Certificate of Origin (DCO) in lieu of a Contributor License Agreement for all contributions to Seek Thermal’s open source projects. 2 | We request that contributors agree to the terms of the DCO and indicate that agreement by signing all commits made to Seek Thermal projects by adding a line with your name and email address to every Git commit message contributed: 3 | 4 | Signed-off-by: Jane Doe 5 | 6 | You can sign your commit automatically with Git by using git commit -s if you have your user.name and user.email set as part of your Git configuration. 7 | 8 | We ask that you use your real name (please no anonymous contributions or pseudonyms). 9 | By signing your commit you are certifying that you have the right have the right to submit it under the open source license used by that particular Seek Thermal project. 10 | You must use your real name (no pseudonyms or anonymous contributions are allowed.) 11 | 12 | We use the Probot DCO GitHub app to check for DCO signoffs of every commit. 13 | 14 | If you forget to sign your commits, the DCO bot will remind you and give you detailed instructions for how to amend your commits to add a signature. -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # seekcamera-python 2 | 3 | [![main Actions Status](https://github.com/seekthermal/seekcamera-python/workflows/main/badge.svg)](https://github.com/seekthermal/seekcamera-python/actions) 4 | ![GitHub](https://img.shields.io/github/license/seekthermal/seekcamera-python) 5 | 6 | Welcome! :wave: 7 | 8 | This is the official home of the Python language bindings for the Seek Thermal SDK. :snake: 9 | 10 | ## About :scroll: 11 | 12 | In general, the Seek Thermal SDK allows customers to develop applications that interface with our thermal camera cores easily, flexibly, and efficiently. 13 | In addition, examples are provided to demonstrate the use of several functional areas and can be a starting point for your own projects. 14 | 15 | The Python language bindings supplement and extend the SDK's traditional C interface in a higher-level language. 16 | They require the Seek Thermal SDK 4.X to be pre-installed on the system; they also require a Seek Thermal OEM core to be physically attached to the system. 17 | 18 | Visit our [website](https://thermal.com) for more information and to get your [Starter Kit](https://www.thermal.com/oem.html). 19 | 20 | ## Features :test_tube: 21 | 22 | The Python language bindings mirror all the major functionality in our SDK. 23 | 24 | ### Highlights :confetti_ball: 25 | 26 | * Asynchronous event driven API that is fast and responsive 27 | * Ability to use multiple cameras in one SDK instance 28 | * Common set of APIs for both Mosaic and Micro Core cameras 29 | * Robust error handling and logging interface 30 | * Numerous frame output formats 31 | * Example applications to learn and get started 32 | 33 | ### Supported platforms :electric_plug: 34 | 35 | The Python language bindings will run on a wide variety of common processors and Linux/Windows OSs. 36 | 37 | The requirements are 38 | * Python 3.X 39 | * [numpy](https://numpy.org) >= 1 40 | * Host architecture supported by the SDK 41 | * See the official SDK documentation for more information 42 | 43 | The optional dependencies are 44 | * [opencv-python](https://github.com/opencv/opencv-python) >=4 45 | * Only for the seekcamera-opencv sample 46 | 47 | ## Getting started :book: 48 | 49 | We recommend that you jump right in by checking out one of the sample applications. 50 | The sample applications demonstrate how to use the most common APIs and features in the SDK. 51 | 52 | ### Sample applications :bulb: 53 | 54 | * seekcamera-opencv 55 | * Demonstrates how to image and display thermal frames to the screen using OpenCV's drawing functions. 56 | * seekcamera-simple 57 | * Demonstrates how to export frame pixel values to disk as a CSV file. 58 | 59 | Run the samples 60 | 61 | ```txt 62 | cd seekcamera-python 63 | python3 examples/seekcamera-opencv.py 64 | ``` 65 | 66 | ### API documentation :brain: 67 | 68 | API documentation is provided as standard Python docstrings. 69 | Please refer to the more complete Seek Thermal SDK C Programming Guide which is provided with the SDK for more in-depth documentation. 70 | 71 | ## Installation :open_file_folder: 72 | 73 | The Python language bindings are developed using Python 3.X. 74 | We recommended Python 3.6+ since we test against those versions; older versions may work as well but we have not tested against them. 75 | 76 | You can download Python from the official [website](https://wwww.python.org/downloads/). 77 | 78 | The recommended method of installation is via the package on pypi 79 | 80 | ```txt 81 | pip3 install seekcamera-python 82 | ``` 83 | 84 | Alternatively, you can install manually. To do so, after installing Python, clone this repository 85 | 86 | ```txt 87 | git clone https://github.com/seekthermal/seekcamera-python.git 88 | ``` 89 | 90 | Change directories into the cloned repository 91 | 92 | ```txt 93 | cd seekcamera-python 94 | ``` 95 | 96 | Install via [pip](https://pypi.org/project/pip) 97 | 98 | ```txt 99 | pip3 install -e . 100 | ``` 101 | 102 | ### Dependencies :floppy_disk: 103 | 104 | #### Python dependencies 105 | 106 | Additional Python dependencies (required for some of the samples) can be installed via [pip](https://pypi.org/project/pip/). 107 | 108 | ```txt 109 | pip3 install -r requirements.examples.txt 110 | ``` 111 | 112 | #### Other dependencies 113 | 114 | The Python language bindings require the Seek Thermal SDK to be installed. 115 | It is recommended, but not required, to use one of the SDK installers. 116 | We provide Debian installers (`.deb`) for Linux and zipfile archives (`.zip`) for Windows. 117 | 118 | On Windows, the SDK library (`seekcamera.dll`) should be located in one of the following places in order of precedence: 119 | 120 | ```txt 121 | %SEEKTHERMAL_LIB_DIR%/ 122 | C:/Program Files/Seek Thermal/Seek Thermal SDK/4.X.X/x64-windows/lib 123 | ``` 124 | 125 | On Linux, the SDK library (`libseekcamera.so`) should be located in one of the following places in order of precedence: 126 | 127 | ```txt 128 | $SEEKTHERMAL_LIB_DIR/ 129 | $LD_LIBRARY_PATH/ 130 | /lib/ 131 | /lib64/ 132 | /usr/lib/ 133 | /usr/lib64/ 134 | ``` 135 | 136 | --- 137 | 138 | **NOTE** 139 | 140 | `%SEEKTHERMAL_LIB_DIR%` is Windows environment variable and is (optionally) set by the user. 141 | 142 | `$SEEKTHERMAL_LIB_DIR` is a Linux environment variable and is (optionally) set by the user. 143 | 144 | --- 145 | 146 | The minimum SDK runtime version for each stable release of the Python language bindings is shown below: 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 |
seekcamera-pythonMinimum SDK runtime version
1.0.04.0.0
1.1.04.1.0
1.1.14.1.0
1.2.04.2.0
174 | 175 | ## License :balance_scale: 176 | 177 | The project is licensed under the Apache 2.0 License. 178 | Please see the [LICENSE](./LICENSE) for more information. 179 | 180 | Copyright (c) 2021 Seek Thermal. 181 | 182 | ## Contributing :hammer: 183 | 184 | We are excited about contributions! 185 | 186 | Please see our [contributing guide](./CONTRIBUTING.md) for more information. 187 | -------------------------------------------------------------------------------- /examples/seekcamera-opencv.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Copyright 2021 Seek Thermal Inc. 3 | # 4 | # Original author: Michael S. Mead 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | from threading import Condition 19 | 20 | import cv2 21 | 22 | from seekcamera import ( 23 | SeekCameraIOType, 24 | SeekCameraColorPalette, 25 | SeekCameraManager, 26 | SeekCameraManagerEvent, 27 | SeekCameraFrameFormat, 28 | SeekCamera, 29 | SeekFrame, 30 | ) 31 | 32 | 33 | class Renderer: 34 | """Contains camera and image data required to render images to the screen.""" 35 | 36 | def __init__(self): 37 | self.busy = False 38 | self.frame = SeekFrame() 39 | self.camera = SeekCamera() 40 | self.frame_condition = Condition() 41 | self.first_frame = True 42 | 43 | 44 | def on_frame(_camera, camera_frame, renderer): 45 | """Async callback fired whenever a new frame is available. 46 | 47 | Parameters 48 | ---------- 49 | _camera: SeekCamera 50 | Reference to the camera for which the new frame is available. 51 | camera_frame: SeekCameraFrame 52 | Reference to the class encapsulating the new frame (potentially 53 | in multiple formats). 54 | renderer: Renderer 55 | User defined data passed to the callback. This can be anything 56 | but in this case it is a reference to the renderer object. 57 | """ 58 | 59 | # Acquire the condition variable and notify the main thread 60 | # that a new frame is ready to render. This is required since 61 | # all rendering done by OpenCV needs to happen on the main thread. 62 | with renderer.frame_condition: 63 | renderer.frame = camera_frame.color_argb8888 64 | renderer.frame_condition.notify() 65 | 66 | 67 | def on_event(camera, event_type, event_status, renderer): 68 | """Async callback fired whenever a camera event occurs. 69 | 70 | Parameters 71 | ---------- 72 | camera: SeekCamera 73 | Reference to the camera on which an event occurred. 74 | event_type: SeekCameraManagerEvent 75 | Enumerated type indicating the type of event that occurred. 76 | event_status: Optional[SeekCameraError] 77 | Optional exception type. It will be a non-None derived instance of 78 | SeekCameraError if the event_type is SeekCameraManagerEvent.ERROR. 79 | renderer: Renderer 80 | User defined data passed to the callback. This can be anything 81 | but in this case it is a reference to the Renderer object. 82 | """ 83 | print("{}: {}".format(str(event_type), camera.chipid)) 84 | 85 | if event_type == SeekCameraManagerEvent.CONNECT: 86 | if renderer.busy: 87 | return 88 | 89 | # Claim the renderer. 90 | # This is required in case of multiple cameras. 91 | renderer.busy = True 92 | renderer.camera = camera 93 | 94 | # Indicate the first frame has not come in yet. 95 | # This is required to properly resize the rendering window. 96 | renderer.first_frame = True 97 | 98 | # Set a custom color palette. 99 | # Other options can set in a similar fashion. 100 | camera.color_palette = SeekCameraColorPalette.TYRIAN 101 | 102 | # Start imaging and provide a custom callback to be called 103 | # every time a new frame is received. 104 | camera.register_frame_available_callback(on_frame, renderer) 105 | camera.capture_session_start(SeekCameraFrameFormat.COLOR_ARGB8888) 106 | 107 | elif event_type == SeekCameraManagerEvent.DISCONNECT: 108 | # Check that the camera disconnecting is one actually associated with 109 | # the renderer. This is required in case of multiple cameras. 110 | if renderer.camera == camera: 111 | # Stop imaging and reset all the renderer state. 112 | camera.capture_session_stop() 113 | renderer.camera = None 114 | renderer.frame = None 115 | renderer.busy = False 116 | 117 | elif event_type == SeekCameraManagerEvent.ERROR: 118 | print("{}: {}".format(str(event_status), camera.chipid)) 119 | 120 | elif event_type == SeekCameraManagerEvent.READY_TO_PAIR: 121 | return 122 | 123 | 124 | def main(): 125 | window_name = "Seek Thermal - Python OpenCV Sample" 126 | cv2.namedWindow(window_name, cv2.WINDOW_NORMAL) 127 | 128 | # Create a context structure responsible for managing all connected USB cameras. 129 | # Cameras with other IO types can be managed by using a bitwise or of the 130 | # SeekCameraIOType enum cases. 131 | with SeekCameraManager(SeekCameraIOType.USB) as manager: 132 | # Start listening for events. 133 | renderer = Renderer() 134 | manager.register_event_callback(on_event, renderer) 135 | 136 | while True: 137 | # Wait a maximum of 150ms for each frame to be received. 138 | # A condition variable is used to synchronize the access to the renderer; 139 | # it will be notified by the user defined frame available callback thread. 140 | with renderer.frame_condition: 141 | if renderer.frame_condition.wait(150.0 / 1000.0): 142 | img = renderer.frame.data 143 | 144 | # Resize the rendering window. 145 | if renderer.first_frame: 146 | (height, width, _) = img.shape 147 | cv2.resizeWindow(window_name, width * 2, height * 2) 148 | renderer.first_frame = False 149 | 150 | # Render the image to the window. 151 | cv2.imshow(window_name, img) 152 | 153 | # Process key events. 154 | key = cv2.waitKey(1) 155 | if key == ord("q"): 156 | break 157 | 158 | # Check if the window has been closed manually. 159 | if not cv2.getWindowProperty(window_name, cv2.WND_PROP_VISIBLE): 160 | break 161 | 162 | cv2.destroyWindow(window_name) 163 | 164 | 165 | if __name__ == "__main__": 166 | main() 167 | -------------------------------------------------------------------------------- /examples/seekcamera-opencv_record.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Copyright 2021 Seek Thermal Inc. 3 | # 4 | # Original author: Michael S. Mead 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | from threading import Condition 19 | 20 | import cv2 21 | import numpy 22 | import PIL.Image 23 | import os 24 | import glob 25 | 26 | from PIL import Image, ImageFont, ImageDraw 27 | 28 | from seekcamera import ( 29 | SeekCameraIOType, 30 | SeekCameraColorPalette, 31 | SeekCameraManager, 32 | SeekCameraManagerEvent, 33 | SeekCameraFrameFormat, 34 | SeekCameraShutterMode, 35 | SeekCamera, 36 | SeekFrame, 37 | ) 38 | 39 | 40 | class Renderer: 41 | """Contains camera and image data required to render images to the screen.""" 42 | 43 | def __init__(self): 44 | self.busy = False 45 | self.frame = SeekFrame() 46 | self.camera = SeekCamera() 47 | self.frame_condition = Condition() 48 | self.first_frame = True 49 | 50 | 51 | def on_frame(_camera, camera_frame, renderer): 52 | """Async callback fired whenever a new frame is available. 53 | 54 | Parameters 55 | ---------- 56 | _camera: SeekCamera 57 | Reference to the camera for which the new frame is available. 58 | camera_frame: SeekCameraFrame 59 | Reference to the class encapsulating the new frame (potentially 60 | in multiple formats). 61 | renderer: Renderer 62 | User defined data passed to the callback. This can be anything 63 | but in this case it is a reference to the renderer object. 64 | """ 65 | 66 | # Acquire the condition variable and notify the main thread 67 | # that a new frame is ready to render. This is required since 68 | # all rendering done by OpenCV needs to happen on the main thread. 69 | with renderer.frame_condition: 70 | renderer.frame = camera_frame.color_argb8888 71 | renderer.frame_condition.notify() 72 | 73 | 74 | def on_event(camera, event_type, event_status, renderer): 75 | """Async callback fired whenever a camera event occurs. 76 | 77 | Parameters 78 | ---------- 79 | camera: SeekCamera 80 | Reference to the camera on which an event occurred. 81 | event_type: SeekCameraManagerEvent 82 | Enumerated type indicating the type of event that occurred. 83 | event_status: Optional[SeekCameraError] 84 | Optional exception type. It will be a non-None derived instance of 85 | SeekCameraError if the event_type is SeekCameraManagerEvent.ERROR. 86 | renderer: Renderer 87 | User defined data passed to the callback. This can be anything 88 | but in this case it is a reference to the Renderer object. 89 | """ 90 | print("{}: {}".format(str(event_type), camera.chipid)) 91 | 92 | if event_type == SeekCameraManagerEvent.CONNECT: 93 | if renderer.busy: 94 | return 95 | 96 | # Claim the renderer. 97 | # This is required in case of multiple cameras. 98 | renderer.busy = True 99 | renderer.camera = camera 100 | 101 | # Indicate the first frame has not come in yet. 102 | # This is required to properly resize the rendering window. 103 | renderer.first_frame = True 104 | 105 | # Set a custom color palette. 106 | # Other options can set in a similar fashion. 107 | camera.color_palette = SeekCameraColorPalette.TYRIAN 108 | 109 | # Start imaging and provide a custom callback to be called 110 | # every time a new frame is received. 111 | camera.register_frame_available_callback(on_frame, renderer) 112 | camera.capture_session_start(SeekCameraFrameFormat.COLOR_ARGB8888) 113 | 114 | elif event_type == SeekCameraManagerEvent.DISCONNECT: 115 | # Check that the camera disconnecting is one actually associated with 116 | # the renderer. This is required in case of multiple cameras. 117 | if renderer.camera == camera: 118 | # Stop imaging and reset all the renderer state. 119 | camera.capture_session_stop() 120 | renderer.camera = None 121 | renderer.frame = None 122 | renderer.busy = False 123 | 124 | elif event_type == SeekCameraManagerEvent.ERROR: 125 | print("{}: {}".format(str(event_status), camera.chipid)) 126 | 127 | elif event_type == SeekCameraManagerEvent.READY_TO_PAIR: 128 | return 129 | 130 | 131 | def bgra2rgb(bgra): 132 | row, col, ch = bgra.shape 133 | 134 | assert ch == 4, "ARGB image has 4 channels." 135 | 136 | rgb = numpy.zeros((row, col, 3), dtype="uint8") 137 | # convert to rgb expected to generate the jpeg image 138 | rgb[:, :, 0] = bgra[:, :, 2] 139 | rgb[:, :, 1] = bgra[:, :, 1] 140 | rgb[:, :, 2] = bgra[:, :, 0] 141 | 142 | return rgb 143 | 144 | 145 | def main(): 146 | window_name = "Seek Thermal - Python OpenCV Sample" 147 | cv2.namedWindow(window_name, cv2.WINDOW_NORMAL) 148 | fileName = "image" 149 | counter = 100000 150 | capture = False 151 | record = False 152 | ts_first = 0 153 | ts_last = 0 154 | frame_count = 0 155 | 156 | from PIL import Image 157 | from pathlib import Path 158 | 159 | for f in glob.glob(fileName + "*.jpg"): 160 | os.remove(f) 161 | 162 | print("\nuser controls:") 163 | print("c: capture") 164 | print("r: record") 165 | print("q: quit") 166 | 167 | # Create a context structure responsible for managing all connected USB cameras. 168 | # Cameras with other IO types can be managed by using a bitwise or of the 169 | # SeekCameraIOType enum cases. 170 | with SeekCameraManager(SeekCameraIOType.USB) as manager: 171 | # Start listening for events. 172 | renderer = Renderer() 173 | manager.register_event_callback(on_event, renderer) 174 | 175 | while True: 176 | # Wait a maximum of 150ms for each frame to be received. 177 | # A condition variable is used to synchronize the access to the renderer; 178 | # it will be notified by the user defined frame available callback thread. 179 | with renderer.frame_condition: 180 | if renderer.frame_condition.wait(150.0 / 1000.0): 181 | img = renderer.frame.data 182 | 183 | # Resize the rendering window. 184 | if renderer.first_frame: 185 | (height, width, _) = img.shape 186 | cv2.resizeWindow(window_name, width * 2, height * 2) 187 | renderer.first_frame = False 188 | 189 | # Render the image to the window. 190 | cv2.imshow(window_name, img) 191 | 192 | # if capture or recording, convert the frame image 193 | # to RGB and generate the file. 194 | # Currently counter is a big number to allow easy ordering 195 | # of frames when recording. 196 | if capture or record: 197 | rgbimg = bgra2rgb(img) 198 | frame_count += 1 199 | im = Image.fromarray(rgbimg).convert("RGB") 200 | jpgName = Path(".", fileName + str(counter)).with_suffix(".jpg") 201 | im.save(jpgName) 202 | counter += 1 203 | capture = False 204 | if record: 205 | ts_last = renderer.frame.header.timestamp_utc_ns 206 | if ts_first == 0: 207 | ts_first = renderer.frame.header.timestamp_utc_ns 208 | # Process key events. 209 | key = cv2.waitKey(1) 210 | if key == ord("q"): 211 | break 212 | 213 | if key == ord("c"): 214 | capture = True 215 | 216 | if key == ord("r"): 217 | if record == False: 218 | record = True 219 | renderer.camera.shutter_mode = SeekCameraShutterMode.MANUAL 220 | print("\nRecording! Press 'r' to stop recording") 221 | print( 222 | "Note: shutter is disabled while recording...so keep the videos relatively short" 223 | ) 224 | else: 225 | # Stop the recording and squish all the jpeg files together 226 | # and generate the .avi file. 227 | record = False 228 | renderer.camera.shutter_mode = SeekCameraShutterMode.AUTO 229 | 230 | time_s = (ts_last - ts_first) / 1000000000 231 | 232 | print("\nRecording stopped and video is in myVideo.avi") 233 | img_array = [] 234 | for filename in glob.glob("image*.jpg"): 235 | img = cv2.imread(filename) 236 | height, width, layers = img.shape 237 | size = (width, height) 238 | img_array.append(img) 239 | out = cv2.VideoWriter( 240 | "myVideo.avi", 241 | cv2.VideoWriter_fourcc(*"DIVX"), 242 | frame_count / time_s, 243 | size, 244 | ) 245 | 246 | frame_count = ts_first = ts_last = 0 247 | 248 | for i in range(len(img_array)): 249 | out.write(img_array[i]) 250 | out.release() 251 | 252 | # Check if the window has been closed manually. 253 | if not cv2.getWindowProperty(window_name, cv2.WND_PROP_VISIBLE): 254 | break 255 | 256 | cv2.destroyWindow(window_name) 257 | 258 | 259 | if __name__ == "__main__": 260 | main() 261 | -------------------------------------------------------------------------------- /examples/seekcamera-simple.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Copyright 2021 Seek Thermal Inc. 3 | # 4 | # Original author: Michael S. Mead 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | from time import sleep 19 | 20 | import numpy as np 21 | 22 | from seekcamera import ( 23 | SeekCameraIOType, 24 | SeekCameraManager, 25 | SeekCameraManagerEvent, 26 | SeekCameraFrameFormat, 27 | ) 28 | 29 | 30 | def on_frame(camera, camera_frame, file): 31 | """Async callback fired whenever a new frame is available. 32 | 33 | Parameters 34 | ---------- 35 | camera: SeekCamera 36 | Reference to the camera for which the new frame is available. 37 | camera_frame: SeekCameraFrame 38 | Reference to the class encapsulating the new frame (potentially 39 | in multiple formats). 40 | file: TextIOWrapper 41 | User defined data passed to the callback. This can be anything 42 | but in this case it is a reference to the open CSV file to which 43 | to log data. 44 | """ 45 | frame = camera_frame.thermography_float 46 | 47 | print( 48 | "frame available: {cid} (size: {w}x{h})".format( 49 | cid=camera.chipid, w=frame.width, h=frame.height 50 | ) 51 | ) 52 | 53 | # Append the frame to the CSV file. 54 | np.savetxt(file, frame.data, fmt="%.1f") 55 | 56 | 57 | def on_event(camera, event_type, event_status, _user_data): 58 | """Async callback fired whenever a camera event occurs. 59 | 60 | Parameters 61 | ---------- 62 | camera: SeekCamera 63 | Reference to the camera on which an event occurred. 64 | event_type: SeekCameraManagerEvent 65 | Enumerated type indicating the type of event that occurred. 66 | event_status: Optional[SeekCameraError] 67 | Optional exception type. It will be a non-None derived instance of 68 | SeekCameraError if the event_type is SeekCameraManagerEvent.ERROR. 69 | _user_data: None 70 | User defined data passed to the callback. This can be anything 71 | but in this case it is None. 72 | """ 73 | print("{}: {}".format(str(event_type), camera.chipid)) 74 | 75 | if event_type == SeekCameraManagerEvent.CONNECT: 76 | # Open a new CSV file with the unique camera chip ID embedded. 77 | try: 78 | file = open("thermography-" + camera.chipid + ".csv", "w") 79 | except OSError as e: 80 | print("Failed to open file: %s" % str(e)) 81 | return 82 | 83 | # Start streaming data and provide a custom callback to be called 84 | # every time a new frame is received. 85 | camera.register_frame_available_callback(on_frame, file) 86 | camera.capture_session_start(SeekCameraFrameFormat.THERMOGRAPHY_FLOAT) 87 | 88 | elif event_type == SeekCameraManagerEvent.DISCONNECT: 89 | camera.capture_session_stop() 90 | 91 | elif event_type == SeekCameraManagerEvent.ERROR: 92 | print("{}: {}".format(str(event_status), camera.chipid)) 93 | 94 | elif event_type == SeekCameraManagerEvent.READY_TO_PAIR: 95 | return 96 | 97 | 98 | def main(): 99 | # Create a context structure responsible for managing all connected USB cameras. 100 | # Cameras with other IO types can be managed by using a bitwise or of the 101 | # SeekCameraIOType enum cases. 102 | with SeekCameraManager(SeekCameraIOType.USB) as manager: 103 | # Start listening for events. 104 | manager.register_event_callback(on_event) 105 | 106 | while True: 107 | sleep(1.0) 108 | 109 | 110 | if __name__ == "__main__": 111 | main() 112 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = [ 3 | "setuptools>=42", 4 | "wheel" 5 | ] 6 | build-backend = "setuptools.build_meta" -------------------------------------------------------------------------------- /requirements.examples.txt: -------------------------------------------------------------------------------- 1 | opencv-python>=4 -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | numpy>=1 -------------------------------------------------------------------------------- /seekcamera/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Seek Thermal Inc. 2 | # 3 | # Original author: Michael S. Mead 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | from seekcamera.camera import ( 18 | SeekCameraManagerEvent, 19 | SeekCameraIOType, 20 | SeekCameraFirmwareVersion, 21 | SeekCameraAppResourcesRegion, 22 | SeekCameraColorPalette, 23 | SeekCameraColorPaletteData, 24 | SeekCameraPipelineMode, 25 | SeekCameraAGCMode, 26 | SeekCameraLinearAGCLockMode, 27 | SeekCameraShutterMode, 28 | SeekCameraTemperatureUnit, 29 | SeekCameraUSBIOProperties, 30 | SeekCameraSPIIOProperties, 31 | SeekCameraIOProperties, 32 | SeekCameraFilter, 33 | SeekCameraFilterState, 34 | SeekCameraHistEQAGCGainLimitFactorMode, 35 | SeekCameraHistEQAGCPlateauRedistributionMode, 36 | SeekCameraFlatSceneCorrectionID, 37 | SeekCameraManager, 38 | SeekCamera, 39 | SeekCameraFrame, 40 | SeekCameraFrameFormat, 41 | SeekCameraFrameHeader, 42 | SeekFrame, 43 | ) 44 | 45 | from seekcamera.error import ( 46 | SeekCameraError, 47 | SeekCameraDeviceCommunicationError, 48 | SeekCameraInvalidParameterError, 49 | SeekCameraPermissionsError, 50 | SeekCameraNoDeviceError, 51 | SeekCameraDeviceNotFoundError, 52 | SeekCameraDeviceBusyError, 53 | SeekCameraTimeoutError, 54 | SeekCameraOverflowError, 55 | SeekCameraUnknownRequestError, 56 | SeekCameraInterruptedError, 57 | SeekCameraOutOfMemoryError, 58 | SeekCameraNotSupportedError, 59 | SeekCameraOtherError, 60 | SeekCameraCannotPerformRequestError, 61 | SeekCameraFlashAccessFailure, 62 | SeekCameraImplementationError, 63 | SeekCameraRequestPendingError, 64 | SeekCameraInvalidFirmwareImageError, 65 | SeekCameraInvalidKeyError, 66 | SeekCameraSensorCommunicationError, 67 | SeekCameraOutOfRangeError, 68 | SeekCameraVerifyFailedError, 69 | SeekCameraSystemCallFailedError, 70 | SeekCameraFileDoesNotExistError, 71 | SeekCameraDirectoryDoesNotExistError, 72 | SeekCameraFileReadFailedError, 73 | SeekCameraFileWriteFailedError, 74 | SeekCameraNotImplementedError, 75 | SeekCameraNotPairedError, 76 | ) 77 | 78 | from seekcamera.version import ( 79 | SeekCameraVersion, 80 | ) 81 | -------------------------------------------------------------------------------- /seekcamera/_clib.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Seek Thermal Inc. 2 | # 3 | # Original author: Michael S. Mead 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | import ctypes 18 | import os 19 | 20 | 21 | # DLL handle 22 | _cdll = None 23 | 24 | # seekcamera_frame_available_callback_t 25 | _SEEKCAMERA_FRAME_AVAILABLE_CALLBACK_T = ctypes.CFUNCTYPE( 26 | ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.py_object 27 | ) 28 | 29 | # seekcamera_memory_access_callback_t 30 | _SEEKCAMERA_MEMORY_ACCESS_CALLBACK_T = ctypes.CFUNCTYPE( 31 | ctypes.c_void_p, ctypes.c_size_t, ctypes.py_object 32 | ) 33 | 34 | # seekcamera_manager_event_callback_t 35 | _SEEKCAMERA_MANAGER_EVENT_CALLBACK_T = ctypes.CFUNCTYPE( 36 | ctypes.c_void_p, ctypes.c_void_p, ctypes.c_int, ctypes.c_int, ctypes.py_object 37 | ) 38 | 39 | 40 | def configure_dll(): 41 | global _cdll 42 | 43 | if _cdll is not None: 44 | return 45 | 46 | min_runtime_version_major = 4 47 | min_runtime_version_minor = 2 48 | min_runtime_version_patch = 0 49 | 50 | if os.name == "nt": 51 | lib = "seekcamera.dll" 52 | 53 | if "SEEKTHERMAL_LIB_DIR" in os.environ: 54 | path = os.path.join(os.environ["SEEKTHERMAL_LIB_DIR"], lib) 55 | try: 56 | _cdll = ctypes.CDLL(path) 57 | except Exception: 58 | raise RuntimeError("Failed to load %s from %s" % (lib, path)) 59 | else: 60 | basedir = os.path.join( 61 | "C:\\", "Program Files", "Seek Thermal", "Seek Thermal SDK" 62 | ) 63 | 64 | versions = [] 65 | subdirs = [d for d in os.scandir(basedir) if d.is_dir()] 66 | for d in subdirs: 67 | parts = d.name.split(".") 68 | if len(parts) == 3: 69 | try: 70 | major = int(parts[0]) 71 | minor = int(parts[1]) 72 | patch = int(parts[2]) 73 | except ValueError: 74 | pass 75 | else: 76 | versions.append("%i.%i.%i" % (major, minor, patch)) 77 | 78 | versions.sort() 79 | version = versions[-1] 80 | 81 | min_runtime_version = "%i.%i.%i" % ( 82 | min_runtime_version_major, 83 | min_runtime_version_minor, 84 | min_runtime_version_patch, 85 | ) 86 | 87 | if version < min_runtime_version: 88 | raise RuntimeError("Failed to locate suitable installed SDK version") 89 | 90 | path = os.path.join(basedir, version, "x64-windows", "lib", lib) 91 | 92 | try: 93 | _cdll = ctypes.CDLL(path) 94 | except Exception: 95 | raise RuntimeError("Failed to load %s from %s" % (lib, path)) 96 | else: 97 | lib = "libseekcamera.so" 98 | 99 | if "SEEKTHERMAL_LIB_DIR" in os.environ: 100 | path = os.path.join(os.environ["SEEKTHERMAL_LIB_DIR"], lib) 101 | try: 102 | _cdll = ctypes.CDLL(path) 103 | except Exception: 104 | raise RuntimeError("Failed to import %s from %s" % (lib, path)) 105 | else: 106 | try: 107 | _cdll = ctypes.CDLL(lib) 108 | except Exception: 109 | raise RuntimeError("Failed to load %s from default system paths" % lib) 110 | 111 | # seekcamera_version_get_major 112 | _cdll.seekcamera_version_get_major.restype = ctypes.c_uint32 113 | _cdll.seekcamera_version_get_major.argtypes = [] 114 | 115 | # seekcamera_version_get_minor 116 | _cdll.seekcamera_version_get_minor.restype = ctypes.c_uint32 117 | _cdll.seekcamera_version_get_minor.argtypes = [] 118 | 119 | # seekcamera_version_get_patch 120 | _cdll.seekcamera_version_get_patch.restype = ctypes.c_uint32 121 | _cdll.seekcamera_version_get_patch.argtypes = [] 122 | 123 | # seekcamera_version_get_internal 124 | _cdll.seekcamera_version_get_internal.restype = ctypes.c_uint32 125 | _cdll.seekcamera_version_get_internal.argtypes = [] 126 | 127 | # seekcamera_version_get_qualifier 128 | _cdll.seekcamera_version_get_qualifier.restype = ctypes.c_char_p 129 | _cdll.seekcamera_version_get_qualifier.argtypes = [] 130 | 131 | def assert_runtime_version_met(version, min_version, name): 132 | if version < min_version: 133 | raise RuntimeError( 134 | "Library runtime %s version is insufficient (minimum: %i, got: %i)" 135 | % (name, min_version, version) 136 | ) 137 | 138 | assert_runtime_version_met( 139 | cseekcamera_version_get_major(), min_runtime_version_major, "major" 140 | ) 141 | 142 | assert_runtime_version_met( 143 | cseekcamera_version_get_minor(), min_runtime_version_minor, "minor" 144 | ) 145 | 146 | assert_runtime_version_met( 147 | cseekcamera_version_get_patch(), min_runtime_version_patch, "patch" 148 | ) 149 | 150 | # seekcamera_manager_create 151 | _cdll.seekcamera_manager_create.restype = ctypes.c_int32 152 | _cdll.seekcamera_manager_create.argtypes = [ 153 | ctypes.POINTER(ctypes.c_void_p), 154 | ctypes.c_uint32, 155 | ] 156 | 157 | # seekcamera_manager_destroy 158 | _cdll.seekcamera_manager_destroy.restype = ctypes.c_int32 159 | _cdll.seekcamera_manager_destroy.argtypes = [ctypes.POINTER(ctypes.c_void_p)] 160 | 161 | # seekcamera_manager_get_event_str 162 | _cdll.seekcamera_manager_get_event_str.restype = ctypes.c_char_p 163 | _cdll.seekcamera_manager_get_event_str.argtypes = [ctypes.c_int32] 164 | 165 | # seekcamera_error_get_str 166 | _cdll.seekcamera_error_get_str.restype = ctypes.c_char_p 167 | _cdll.seekcamera_error_get_str.argtypes = [ctypes.c_int32] 168 | 169 | # seekcamera_get_io_type 170 | _cdll.seekcamera_get_io_type.restype = ctypes.c_int32 171 | _cdll.seekcamera_get_io_type.argtypes = [ 172 | ctypes.c_void_p, 173 | ctypes.POINTER(ctypes.c_int32), 174 | ] 175 | 176 | # seekcamera_get_io_properties 177 | _cdll.seekcamera_get_io_properties.restype = ctypes.c_int32 178 | _cdll.seekcamera_get_io_properties.argtypes = [ 179 | ctypes.c_void_p, 180 | ctypes.POINTER(CSeekCameraIOProperties), 181 | ] 182 | 183 | # seekcamera_get_chipid 184 | _cdll.seekcamera_get_chipid.restype = ctypes.c_int32 185 | _cdll.seekcamera_get_chipid.argtypes = [ 186 | ctypes.c_void_p, 187 | ctypes.POINTER(ctypes.c_char * 16), 188 | ] 189 | 190 | # seekcamera_get_serial_number 191 | _cdll.seekcamera_get_serial_number.restype = ctypes.c_int32 192 | _cdll.seekcamera_get_serial_number.argtypes = [ 193 | ctypes.c_void_p, 194 | ctypes.POINTER(ctypes.c_char * 16), 195 | ] 196 | 197 | # seekcamera_get_core_part_number 198 | _cdll.seekcamera_get_core_part_number.restype = ctypes.c_int32 199 | _cdll.seekcamera_get_core_part_number.argtypes = [ 200 | ctypes.c_void_p, 201 | ctypes.POINTER(ctypes.c_char * 32), 202 | ] 203 | 204 | # seekcamera_get_firmware_version 205 | _cdll.seekcamera_get_firmware_version.restype = ctypes.c_int32 206 | _cdll.seekcamera_get_firmware_version.argtypes = [ 207 | ctypes.c_void_p, 208 | ctypes.POINTER(CSeekCameraFirmwareVersion), 209 | ] 210 | 211 | # seekcamera_get_thermography_window 212 | _cdll.seekcamera_get_thermography_window.restype = ctypes.c_int32 213 | _cdll.seekcamera_get_thermography_window.argtypes = [ 214 | ctypes.c_void_p, 215 | ctypes.POINTER(ctypes.c_size_t), 216 | ctypes.POINTER(ctypes.c_size_t), 217 | ctypes.POINTER(ctypes.c_size_t), 218 | ctypes.POINTER(ctypes.c_size_t), 219 | ] 220 | 221 | # seekcamera_set_thermography_window 222 | _cdll.seekcamera_set_thermography_window.restype = ctypes.c_int32 223 | _cdll.seekcamera_set_thermography_window.argtypes = [ 224 | ctypes.c_void_p, 225 | ctypes.c_size_t, 226 | ctypes.c_size_t, 227 | ctypes.c_size_t, 228 | ctypes.c_size_t, 229 | ] 230 | 231 | # seekcamera_update_firmware 232 | _cdll.seekcamera_update_firmware.restype = ctypes.c_int32 233 | _cdll.seekcamera_update_firmware.argtypes = [ 234 | ctypes.c_void_p, 235 | ctypes.c_char_p, 236 | _SEEKCAMERA_MEMORY_ACCESS_CALLBACK_T, 237 | ctypes.py_object, 238 | ] 239 | 240 | # seekcamera_store_calibration_data 241 | _cdll.seekcamera_store_calibration_data.restype = ctypes.c_int32 242 | _cdll.seekcamera_store_calibration_data.argtypes = [ 243 | ctypes.c_void_p, 244 | ctypes.c_char_p, 245 | _SEEKCAMERA_MEMORY_ACCESS_CALLBACK_T, 246 | ctypes.py_object, 247 | ] 248 | 249 | # seekcamera_store_flat_scene_correction 250 | _cdll.seekcamera_store_flat_scene_correction.restype = ctypes.c_int32 251 | _cdll.seekcamera_store_flat_scene_correction.argtypes = [ 252 | ctypes.c_void_p, 253 | ctypes.c_int32, 254 | _SEEKCAMERA_MEMORY_ACCESS_CALLBACK_T, 255 | ctypes.py_object, 256 | ] 257 | 258 | # seekcamera_delete_flat_scene_correction 259 | _cdll.seekcamera_delete_flat_scene_correction.restype = ctypes.c_int32 260 | _cdll.seekcamera_delete_flat_scene_correction.argtypes = [ 261 | ctypes.c_void_p, 262 | ctypes.c_int32, 263 | _SEEKCAMERA_MEMORY_ACCESS_CALLBACK_T, 264 | ctypes.py_object, 265 | ] 266 | 267 | # seekcamera_load_app_resources 268 | _cdll.seekcamera_load_app_resources.restype = ctypes.c_int32 269 | _cdll.seekcamera_load_app_resources.argtypes = [ 270 | ctypes.c_void_p, 271 | ctypes.c_int32, 272 | ctypes.POINTER(ctypes.c_void_p), 273 | ctypes.c_size_t, 274 | _SEEKCAMERA_MEMORY_ACCESS_CALLBACK_T, 275 | ctypes.py_object, 276 | ] 277 | 278 | # seekcamera_store_app_resources 279 | _cdll.seekcamera_store_app_resources.restype = ctypes.c_int32 280 | _cdll.seekcamera_store_app_resources.argtypes = [ 281 | ctypes.c_void_p, 282 | ctypes.c_int32, 283 | ctypes.POINTER(ctypes.c_void_p), 284 | ctypes.c_size_t, 285 | _SEEKCAMERA_MEMORY_ACCESS_CALLBACK_T, 286 | ctypes.py_object, 287 | ] 288 | 289 | # seekcamera_capture_session_start 290 | _cdll.seekcamera_capture_session_start.restype = ctypes.c_int32 291 | _cdll.seekcamera_capture_session_start.argtypes = [ctypes.c_void_p, ctypes.c_uint32] 292 | 293 | # seekcamera_capture_session_stop 294 | _cdll.seekcamera_capture_session_stop.restype = ctypes.c_int32 295 | _cdll.seekcamera_capture_session_stop.argtypes = [ctypes.c_void_p] 296 | 297 | # seekcamera_register_frame_available_callback 298 | _cdll.seekcamera_register_frame_available_callback.restype = ctypes.c_int32 299 | _cdll.seekcamera_register_frame_available_callback.argtypes = [ 300 | ctypes.c_void_p, 301 | _SEEKCAMERA_FRAME_AVAILABLE_CALLBACK_T, 302 | ctypes.py_object, 303 | ] 304 | 305 | # seekcamera_get_color_palette 306 | _cdll.seekcamera_get_color_palette.restype = ctypes.c_int32 307 | _cdll.seekcamera_get_color_palette.argtypes = [ 308 | ctypes.c_void_p, 309 | ctypes.POINTER(ctypes.c_int32), 310 | ] 311 | 312 | # seekcamera_set_color_palette 313 | _cdll.seekcamera_set_color_palette.restype = ctypes.c_int32 314 | _cdll.seekcamera_set_color_palette.argtypes = [ctypes.c_void_p, ctypes.c_int32] 315 | 316 | # seekcamera_set_color_palette_data 317 | _cdll.seekcamera_set_color_palette_data.restype = ctypes.c_int32 318 | _cdll.seekcamera_set_color_palette_data.argtypes = [ 319 | ctypes.c_void_p, 320 | ctypes.c_int32, 321 | ctypes.POINTER(CSeekCameraColorPaletteDataEntry * 256), 322 | ] 323 | 324 | # seekcamera_get_pipeline_mode 325 | _cdll.seekcamera_get_pipeline_mode.restype = ctypes.c_int32 326 | _cdll.seekcamera_get_pipeline_mode.argtypes = [ 327 | ctypes.c_void_p, 328 | ctypes.POINTER(ctypes.c_int32), 329 | ] 330 | 331 | # seekcamera_set_pipeline_mode 332 | _cdll.seekcamera_set_pipeline_mode.restype = ctypes.c_int32 333 | _cdll.seekcamera_set_pipeline_mode.argtypes = [ctypes.c_void_p, ctypes.c_int32] 334 | 335 | # seekcamera_get_agc_mode 336 | _cdll.seekcamera_get_agc_mode.restype = ctypes.c_int32 337 | _cdll.seekcamera_get_agc_mode.argtypes = [ 338 | ctypes.c_void_p, 339 | ctypes.POINTER(ctypes.c_int32), 340 | ] 341 | 342 | # seekcamera_set_agc_mode 343 | _cdll.seekcamera_set_agc_mode.restype = ctypes.c_int32 344 | _cdll.seekcamera_set_agc_mode.argtypes = [ctypes.c_void_p, ctypes.c_int32] 345 | 346 | # seekcamera_get_histeq_agc_plateau 347 | _cdll.seekcamera_get_histeq_agc_plateau.restype = ctypes.c_int32 348 | _cdll.seekcamera_get_histeq_agc_plateau.argtypes = [ 349 | ctypes.c_void_p, 350 | ctypes.POINTER(ctypes.c_float), 351 | ] 352 | 353 | # seekcamera_set_histeq_agc_plateau 354 | _cdll.seekcamera_set_histeq_agc_plateau.restype = ctypes.c_int32 355 | _cdll.seekcamera_set_histeq_agc_plateau.argtypes = [ctypes.c_void_p, ctypes.c_float] 356 | 357 | # seekcamera_get_histeq_agc_plateau_redistribution_mode 358 | _cdll.seekcamera_get_histeq_agc_plateau_redistribution_mode.restype = ctypes.c_int32 359 | _cdll.seekcamera_get_histeq_agc_plateau_redistribution_mode.argtypes = [ 360 | ctypes.c_void_p, 361 | ctypes.POINTER(ctypes.c_int32), 362 | ] 363 | 364 | # seekcamera_set_histeq_agc_plateau_redistribution_mode 365 | _cdll.seekcamera_set_histeq_agc_plateau_redistribution_mode.restype = ctypes.c_int32 366 | _cdll.seekcamera_set_histeq_agc_plateau_redistribution_mode.argtypes = [ 367 | ctypes.c_void_p, 368 | ctypes.c_int32, 369 | ] 370 | 371 | # seekcamera_get_histeq_agc_gain_limit 372 | _cdll.seekcamera_get_histeq_agc_gain_limit.restype = ctypes.c_int32 373 | _cdll.seekcamera_get_histeq_agc_gain_limit.argtypes = [ 374 | ctypes.c_void_p, 375 | ctypes.POINTER(ctypes.c_float), 376 | ] 377 | 378 | # seekcamera_set_histeq_agc_gain_limit 379 | _cdll.seekcamera_set_histeq_agc_gain_limit.restype = ctypes.c_int32 380 | _cdll.seekcamera_set_histeq_agc_gain_limit.argtypes = [ 381 | ctypes.c_void_p, 382 | ctypes.c_float, 383 | ] 384 | 385 | # seekcamera_get_histeq_agc_gain_limit_factor_mode 386 | _cdll.seekcamera_get_histeq_agc_gain_limit_factor_mode.restype = ctypes.c_int32 387 | _cdll.seekcamera_get_histeq_agc_gain_limit_factor_mode.argtypes = [ 388 | ctypes.c_void_p, 389 | ctypes.POINTER(ctypes.c_int32), 390 | ] 391 | 392 | # seekcamera_set_histeq_agc_gain_limit_factor_mode 393 | _cdll.seekcamera_set_histeq_agc_gain_limit_factor_mode.restype = ctypes.c_int32 394 | _cdll.seekcamera_set_histeq_agc_gain_limit_factor_mode.argtypes = [ 395 | ctypes.c_void_p, 396 | ctypes.c_int32, 397 | ] 398 | 399 | # seekcamera_get_histeq_agc_gain_limit_factor_xmax 400 | _cdll.seekcamera_get_histeq_agc_gain_limit_factor_xmax.restype = ctypes.c_int32 401 | _cdll.seekcamera_get_histeq_agc_gain_limit_factor_xmax.argtypes = [ 402 | ctypes.c_void_p, 403 | ctypes.POINTER(ctypes.c_uint32), 404 | ] 405 | 406 | # seekcamera_set_histeq_agc_gain_limit_factor_xmax 407 | _cdll.seekcamera_set_histeq_agc_gain_limit_factor_xmax.restype = ctypes.c_int32 408 | _cdll.seekcamera_set_histeq_agc_gain_limit_factor_xmax.argtypes = [ 409 | ctypes.c_void_p, 410 | ctypes.c_uint32, 411 | ] 412 | 413 | # seekcamera_get_histeq_agc_gain_limit_factor_ymin 414 | _cdll.seekcamera_get_histeq_agc_gain_limit_factor_ymin.restype = ctypes.c_int32 415 | _cdll.seekcamera_get_histeq_agc_gain_limit_factor_ymin.argtypes = [ 416 | ctypes.c_void_p, 417 | ctypes.POINTER(ctypes.c_float), 418 | ] 419 | 420 | # seekcamera_set_histeq_agc_gain_limit_factor_ymin 421 | _cdll.seekcamera_set_histeq_agc_gain_limit_factor_ymin.restype = ctypes.c_int32 422 | _cdll.seekcamera_set_histeq_agc_gain_limit_factor_ymin.argtypes = [ 423 | ctypes.c_void_p, 424 | ctypes.c_float, 425 | ] 426 | 427 | # seekcamera_get_histeq_agc_alpha_time_seconds 428 | _cdll.seekcamera_get_histeq_agc_alpha_time_seconds.restype = ctypes.c_int32 429 | _cdll.seekcamera_get_histeq_agc_alpha_time_seconds.argtypes = [ 430 | ctypes.c_void_p, 431 | ctypes.POINTER(ctypes.c_float), 432 | ] 433 | 434 | # seekcamera_set_histeq_agc_alpha_time_seconds 435 | _cdll.seekcamera_set_histeq_agc_alpha_time_seconds.restype = ctypes.c_int32 436 | _cdll.seekcamera_set_histeq_agc_alpha_time_seconds.argtypes = [ 437 | ctypes.c_void_p, 438 | ctypes.c_float, 439 | ] 440 | 441 | # seekcamera_get_histeq_agc_trim_left 442 | _cdll.seekcamera_get_histeq_agc_trim_left.restype = ctypes.c_int32 443 | _cdll.seekcamera_get_histeq_agc_trim_left.argtypes = [ 444 | ctypes.c_void_p, 445 | ctypes.POINTER(ctypes.c_float), 446 | ] 447 | 448 | # seekcamera_set_histeq_agc_trim_left 449 | _cdll.seekcamera_set_histeq_agc_trim_left.restype = ctypes.c_int32 450 | _cdll.seekcamera_set_histeq_agc_trim_left.argtypes = [ 451 | ctypes.c_void_p, 452 | ctypes.c_float, 453 | ] 454 | 455 | # seekcamera_get_histeq_agc_trim_right 456 | _cdll.seekcamera_get_histeq_agc_trim_right.restype = ctypes.c_int32 457 | _cdll.seekcamera_get_histeq_agc_trim_right.argtypes = [ 458 | ctypes.c_void_p, 459 | ctypes.POINTER(ctypes.c_float), 460 | ] 461 | 462 | # seekcamera_set_histeq_agc_trim_right 463 | _cdll.seekcamera_set_histeq_agc_trim_right.restype = ctypes.c_int32 464 | _cdll.seekcamera_set_histeq_agc_trim_right.argtypes = [ 465 | ctypes.c_void_p, 466 | ctypes.c_float, 467 | ] 468 | 469 | # seekcamera_get_histeq_agc_roi_left 470 | _cdll.seekcamera_get_histeq_agc_roi_left.restype = ctypes.c_int32 471 | _cdll.seekcamera_get_histeq_agc_roi_left.argtypes = [ 472 | ctypes.c_void_p, 473 | ctypes.POINTER(ctypes.c_int32), 474 | ] 475 | 476 | # seekcamera_set_histeq_agc_roi_left 477 | _cdll.seekcamera_set_histeq_agc_roi_left.restype = ctypes.c_int32 478 | _cdll.seekcamera_set_histeq_agc_roi_left.argtypes = [ 479 | ctypes.c_void_p, 480 | ctypes.c_int32, 481 | ] 482 | 483 | # seekcamera_get_histeq_agc_roi_top 484 | _cdll.seekcamera_get_histeq_agc_roi_top.restype = ctypes.c_int32 485 | _cdll.seekcamera_get_histeq_agc_roi_top.argtypes = [ 486 | ctypes.c_void_p, 487 | ctypes.POINTER(ctypes.c_int32), 488 | ] 489 | 490 | # seekcamera_set_histeq_agc_roi_top 491 | _cdll.seekcamera_set_histeq_agc_roi_top.restype = ctypes.c_int32 492 | _cdll.seekcamera_set_histeq_agc_roi_top.argtypes = [ 493 | ctypes.c_void_p, 494 | ctypes.c_int32, 495 | ] 496 | 497 | # seekcamera_get_histeq_agc_roi_width 498 | _cdll.seekcamera_get_histeq_agc_roi_width.restype = ctypes.c_int32 499 | _cdll.seekcamera_get_histeq_agc_roi_width.argtypes = [ 500 | ctypes.c_void_p, 501 | ctypes.POINTER(ctypes.c_int32), 502 | ] 503 | 504 | # seekcamera_set_histeq_agc_roi_width 505 | _cdll.seekcamera_set_histeq_agc_roi_width.restype = ctypes.c_int32 506 | _cdll.seekcamera_set_histeq_agc_roi_width.argtypes = [ 507 | ctypes.c_void_p, 508 | ctypes.c_int32, 509 | ] 510 | 511 | # seekcamera_get_histeq_agc_roi_height 512 | _cdll.seekcamera_get_histeq_agc_roi_height.restype = ctypes.c_int32 513 | _cdll.seekcamera_get_histeq_agc_roi_height.argtypes = [ 514 | ctypes.c_void_p, 515 | ctypes.POINTER(ctypes.c_int32), 516 | ] 517 | 518 | # seekcamera_set_histeq_agc_roi_height 519 | _cdll.seekcamera_set_histeq_agc_roi_height.restype = ctypes.c_int32 520 | _cdll.seekcamera_set_histeq_agc_roi_height.argtypes = [ 521 | ctypes.c_void_p, 522 | ctypes.c_int32, 523 | ] 524 | 525 | # seekcamera_get_histeq_agc_roi_enable 526 | _cdll.seekcamera_get_histeq_agc_roi_enable.restype = ctypes.c_int32 527 | _cdll.seekcamera_get_histeq_agc_roi_enable.argtypes = [ 528 | ctypes.c_void_p, 529 | ctypes.POINTER(ctypes.c_bool), 530 | ] 531 | 532 | # seekcamera_set_histeq_agc_roi_enable 533 | _cdll.seekcamera_set_histeq_agc_roi_enable.restype = ctypes.c_int32 534 | _cdll.seekcamera_set_histeq_agc_roi_enable.argtypes = [ 535 | ctypes.c_void_p, 536 | ctypes.c_bool, 537 | ] 538 | 539 | # seekcamera_get_linear_agc_lock_mode 540 | _cdll.seekcamera_get_linear_agc_lock_mode.restype = ctypes.c_int32 541 | _cdll.seekcamera_get_linear_agc_lock_mode.argtypes = [ 542 | ctypes.c_void_p, 543 | ctypes.POINTER(ctypes.c_int32), 544 | ] 545 | 546 | # seekcamera_set_linear_agc_lock_mode 547 | _cdll.seekcamera_set_linear_agc_lock_mode.restype = ctypes.c_int32 548 | _cdll.seekcamera_set_linear_agc_lock_mode.argtypes = [ 549 | ctypes.c_void_p, 550 | ctypes.c_int32, 551 | ] 552 | 553 | # seekcamera_get_linear_agc_lock_min 554 | _cdll.seekcamera_get_linear_agc_lock_min.restype = ctypes.c_int32 555 | _cdll.seekcamera_get_linear_agc_lock_min.argtypes = [ 556 | ctypes.c_void_p, 557 | ctypes.POINTER(ctypes.c_float), 558 | ] 559 | 560 | # seekcamera_set_linear_agc_lock_min 561 | _cdll.seekcamera_set_linear_agc_lock_min.restype = ctypes.c_int32 562 | _cdll.seekcamera_set_linear_agc_lock_min.argtypes = [ 563 | ctypes.c_void_p, 564 | ctypes.c_float, 565 | ] 566 | 567 | # seekcamera_get_linear_agc_lock_max 568 | _cdll.seekcamera_get_linear_agc_lock_max.restype = ctypes.c_int32 569 | _cdll.seekcamera_get_linear_agc_lock_max.argtypes = [ 570 | ctypes.c_void_p, 571 | ctypes.POINTER(ctypes.c_float), 572 | ] 573 | 574 | # seekcamera_set_linear_agc_lock_max 575 | _cdll.seekcamera_set_linear_agc_lock_max.restype = ctypes.c_int32 576 | _cdll.seekcamera_set_linear_agc_lock_max.argtypes = [ 577 | ctypes.c_void_p, 578 | ctypes.c_float, 579 | ] 580 | 581 | # seekcamera_get_shutter_mode 582 | _cdll.seekcamera_get_shutter_mode.restype = ctypes.c_int32 583 | _cdll.seekcamera_get_shutter_mode.argtypes = [ 584 | ctypes.c_void_p, 585 | ctypes.POINTER(ctypes.c_int32), 586 | ] 587 | 588 | # seekcamera_set_shutter_mode 589 | _cdll.seekcamera_set_shutter_mode.restype = ctypes.c_int32 590 | _cdll.seekcamera_set_shutter_mode.argtypes = [ctypes.c_void_p, ctypes.c_int32] 591 | 592 | # seekcamera_get_temperature_unit 593 | _cdll.seekcamera_get_temperature_unit.restype = ctypes.c_int32 594 | _cdll.seekcamera_get_temperature_unit.argtypes = [ 595 | ctypes.c_void_p, 596 | ctypes.POINTER(ctypes.c_int32), 597 | ] 598 | 599 | # seekcamera_set_temperature_unit 600 | _cdll.seekcamera_set_temperature_unit.restype = ctypes.c_int32 601 | _cdll.seekcamera_set_temperature_unit.argtypes = [ctypes.c_void_p, ctypes.c_int32] 602 | 603 | # seekcamera_shutter_trigger 604 | _cdll.seekcamera_shutter_trigger.restype = ctypes.c_int32 605 | _cdll.seekcamera_shutter_trigger.argtypes = [ctypes.c_void_p] 606 | 607 | # seekcamera_get_scene_emissivity 608 | _cdll.seekcamera_get_scene_emissivity.restype = ctypes.c_int32 609 | _cdll.seekcamera_get_scene_emissivity.argtypes = [ 610 | ctypes.c_void_p, 611 | ctypes.POINTER(ctypes.c_float), 612 | ] 613 | 614 | # seekcamera_set_scene_emissivity 615 | _cdll.seekcamera_set_scene_emissivity.restype = ctypes.c_int32 616 | _cdll.seekcamera_set_scene_emissivity.argtypes = [ctypes.c_void_p, ctypes.c_float] 617 | 618 | # seekcamera_get_thermography_offset 619 | _cdll.seekcamera_get_thermography_offset.restype = ctypes.c_int32 620 | _cdll.seekcamera_get_thermography_offset.argtypes = [ 621 | ctypes.c_void_p, 622 | ctypes.POINTER(ctypes.c_float), 623 | ] 624 | 625 | # seekcamera_set_thermography_offset 626 | _cdll.seekcamera_set_thermography_offset.restype = ctypes.c_int32 627 | _cdll.seekcamera_set_thermography_offset.argtypes = [ 628 | ctypes.c_void_p, 629 | ctypes.c_float, 630 | ] 631 | 632 | # seekcamera_set_filter_state 633 | _cdll.seekcamera_set_filter_state.restype = ctypes.c_int32 634 | _cdll.seekcamera_set_filter_state.argtypes = [ 635 | ctypes.c_void_p, 636 | ctypes.c_int32, 637 | ctypes.c_int32, 638 | ] 639 | 640 | # seekcamera_get_filter_state 641 | _cdll.seekcamera_get_filter_state.restype = ctypes.c_int32 642 | _cdll.seekcamera_get_filter_state.argtypes = [ 643 | ctypes.c_void_p, 644 | ctypes.c_int32, 645 | ctypes.POINTER(ctypes.c_int32), 646 | ] 647 | 648 | # seekcamera_frame_frame_by_format 649 | _cdll.seekcamera_frame_get_frame_by_format.restype = ctypes.c_int32 650 | _cdll.seekcamera_frame_get_frame_by_format.argtypes = [ 651 | ctypes.c_void_p, 652 | ctypes.c_int32, 653 | ctypes.POINTER(ctypes.c_void_p), 654 | ] 655 | 656 | # seekcamera_frame_lock 657 | _cdll.seekcamera_frame_lock.restype = ctypes.c_int32 658 | _cdll.seekcamera_frame_lock.argtypes = [ctypes.c_void_p] 659 | 660 | # seekcamera_frame_unlock 661 | _cdll.seekcamera_frame_unlock.restype = ctypes.c_int32 662 | _cdll.seekcamera_frame_unlock.argtypes = [ctypes.c_void_p] 663 | 664 | # seekframe_get_width 665 | _cdll.seekframe_get_width.restype = ctypes.c_size_t 666 | _cdll.seekframe_get_width.argtypes = [ctypes.c_void_p] 667 | 668 | # seekframe_get_height 669 | _cdll.seekframe_get_height.restype = ctypes.c_size_t 670 | _cdll.seekframe_get_height.argtypes = [ctypes.c_void_p] 671 | 672 | # seekframe_get_channels 673 | _cdll.seekframe_get_channels.restype = ctypes.c_size_t 674 | _cdll.seekframe_get_channels.argtypes = [ctypes.c_void_p] 675 | 676 | # seekframe_get_pixel_depth 677 | _cdll.seekframe_get_pixel_depth.restype = ctypes.c_size_t 678 | _cdll.seekframe_get_pixel_depth.argtypes = [ctypes.c_void_p] 679 | 680 | # seekframe_get_pixel_padding 681 | _cdll.seekframe_get_pixel_padding.restype = ctypes.c_size_t 682 | _cdll.seekframe_get_pixel_padding.argtypes = [ctypes.c_void_p] 683 | 684 | # seekframe_get_line_stride 685 | _cdll.seekframe_get_line_stride.restype = ctypes.c_size_t 686 | _cdll.seekframe_get_line_stride.argtypes = [ctypes.c_void_p] 687 | 688 | # seekframe_get_line_padding 689 | _cdll.seekframe_get_line_padding.restype = ctypes.c_size_t 690 | _cdll.seekframe_get_line_padding.argtypes = [ctypes.c_void_p] 691 | 692 | # seekframe_get_data_size 693 | _cdll.seekframe_get_data_size.restype = ctypes.c_size_t 694 | _cdll.seekframe_get_data_size.argtypes = [ctypes.c_void_p] 695 | 696 | # seekframe_get_data 697 | _cdll.seekframe_get_data.restype = ctypes.c_void_p 698 | _cdll.seekframe_get_data.argtypes = [ctypes.c_void_p] 699 | 700 | # seekframe_get_row 701 | _cdll.seekframe_get_row.restype = ctypes.c_void_p 702 | _cdll.seekframe_get_row.argtypes = [ctypes.c_void_p, ctypes.c_size_t] 703 | 704 | # seekframe_get_pixel 705 | _cdll.seekframe_get_pixel.restype = ctypes.c_void_p 706 | _cdll.seekframe_get_pixel.argtypes = [ 707 | ctypes.c_void_p, 708 | ctypes.c_size_t, 709 | ctypes.c_size_t, 710 | ] 711 | 712 | # seekframe_is_empty 713 | _cdll.seekframe_is_empty.restype = ctypes.c_bool 714 | _cdll.seekframe_is_empty.argtypes = [ctypes.c_void_p] 715 | 716 | # seekframe_get_header_size 717 | _cdll.seekframe_get_header_size.restype = ctypes.c_size_t 718 | _cdll.seekframe_get_header_size.argtypes = [ctypes.c_void_p] 719 | 720 | # seekframe_get_header 721 | _cdll.seekframe_get_header.restype = ctypes.POINTER(CSeekCameraFrameHeader) 722 | _cdll.seekframe_get_header.argtypes = [ctypes.c_void_p] 723 | 724 | 725 | class CSeekCameraColorPaletteDataEntry(ctypes.Structure): 726 | _fields_ = [ 727 | ("b", ctypes.c_uint8), 728 | ("g", ctypes.c_uint8), 729 | ("r", ctypes.c_uint8), 730 | ("a", ctypes.c_uint8), 731 | ] 732 | 733 | 734 | class CSeekCameraFrameHeader(ctypes.Structure): 735 | _pack_ = 1 736 | _fields_ = [ 737 | ("sentinel", ctypes.c_uint32), 738 | ("version", ctypes.c_uint8), 739 | ("type", ctypes.c_uint32), 740 | ("width", ctypes.c_uint16), 741 | ("height", ctypes.c_uint16), 742 | ("channels", ctypes.c_uint8), 743 | ("pixel_depth", ctypes.c_uint8), 744 | ("pixel_padding", ctypes.c_uint8), 745 | ("line_stride", ctypes.c_uint16), 746 | ("line_padding", ctypes.c_uint16), 747 | ("header_size", ctypes.c_uint16), 748 | ("timestamp_utc_ns", ctypes.c_uint64), 749 | ("chipid", ctypes.c_char * 16), 750 | ("serial_number", ctypes.c_char * 16), 751 | ("core_part_number", ctypes.c_char * 32), 752 | ("firmware_version", ctypes.c_uint8 * 4), 753 | ("io_type", ctypes.c_uint8), 754 | ("fpa_frame_count", ctypes.c_uint32), 755 | ("fpa_diode_count", ctypes.c_uint32), 756 | ("environment_temperature", ctypes.c_float), 757 | ("thermography_min_x", ctypes.c_uint16), 758 | ("thermography_min_y", ctypes.c_uint16), 759 | ("thermography_min_value", ctypes.c_float), 760 | ("thermography_max_x", ctypes.c_uint16), 761 | ("thermography_max_y", ctypes.c_uint16), 762 | ("thermography_max_value", ctypes.c_float), 763 | ("thermography_spot_x", ctypes.c_uint16), 764 | ("thermography_spot_y", ctypes.c_uint16), 765 | ("thermography_spot_value", ctypes.c_float), 766 | ("agc_mode", ctypes.c_uint8), 767 | ("histeq_agc_num_bins", ctypes.c_uint16), 768 | ("histeq_agc_bin_width", ctypes.c_uint16), 769 | ("histeq_agc_gain_limit_factor", ctypes.c_float), 770 | ("histeq_agc_reserved", ctypes.c_uint8 * 64), 771 | ("linear_agc_min", ctypes.c_float), 772 | ("linear_agc_max", ctypes.c_float), 773 | ("linear_agc_reserved", ctypes.c_uint8 * 32), 774 | ("gradient_correction_filter_state", ctypes.c_uint8), 775 | ("flat_scene_correction_filter_state", ctypes.c_uint8), 776 | ("sharpen_correction_filter_state", ctypes.c_uint8), 777 | ("reserved", ctypes.c_uint8 * 1798), 778 | ] 779 | 780 | 781 | class CSeekCameraUSBIOProperties(ctypes.Structure): 782 | _fields_ = [("bus_number", ctypes.c_uint8), ("port_numbers", ctypes.c_uint8 * 8)] 783 | 784 | 785 | class CSeekCameraSPIIOProperties(ctypes.Structure): 786 | _fields_ = [("bus_number", ctypes.c_uint8), ("cs_number", ctypes.c_uint8)] 787 | 788 | 789 | class CSeekCameraIOProperties(ctypes.Structure): 790 | class Properties(ctypes.Union): 791 | _fields_ = [ 792 | ("usb", CSeekCameraUSBIOProperties), 793 | ("spi", CSeekCameraSPIIOProperties), 794 | ] 795 | 796 | _fields_ = [("type", ctypes.c_int32), ("properties", Properties)] 797 | 798 | 799 | class CSeekCameraFirmwareVersion(ctypes.Structure): 800 | _fields_ = [ 801 | ("product", ctypes.c_uint8), 802 | ("variant", ctypes.c_uint8), 803 | ("major", ctypes.c_uint8), 804 | ("minor", ctypes.c_uint8), 805 | ] 806 | 807 | 808 | def _default_memory_access_callback(_progress, _user_data): 809 | pass 810 | 811 | 812 | def _memory_access_callback(callback): 813 | if callback is None: 814 | return _SEEKCAMERA_MEMORY_ACCESS_CALLBACK_T(_default_memory_access_callback) 815 | return _SEEKCAMERA_MEMORY_ACCESS_CALLBACK_T(callback) 816 | 817 | 818 | class CSeekCameraManager(object): 819 | def __init__(self): 820 | self.pointer = ctypes.c_void_p() 821 | self.user_data = None 822 | self.event_callback = None 823 | self.event_callback_cdll = ctypes.CFUNCTYPE(None) 824 | self.cameras = [] 825 | 826 | 827 | class CSeekCamera(object): 828 | def __init__(self, camera): 829 | self.pointer = ctypes.c_void_p(camera) 830 | self.user_data = None 831 | self.frame_available_callback = None 832 | self.frame_available_callback_cdll = ctypes.CFUNCTYPE(None) 833 | 834 | def __eq__(self, other): 835 | this_cid, _ = cseekcamera_get_chipid(self) 836 | other_cid, _ = cseekcamera_get_chipid(other) 837 | return this_cid.value.decode("utf-8") == other_cid.value.decode("utf-8") 838 | 839 | 840 | class CSeekCameraFrame(object): 841 | def __init__(self, camera_frame): 842 | self.pointer = ctypes.c_void_p(camera_frame) 843 | 844 | 845 | class CSeekFrame(object): 846 | def __init__(self, frame): 847 | self.pointer = frame 848 | 849 | 850 | def cseekcamera_manager_create(discovery_mode): 851 | manager = CSeekCameraManager() 852 | status = _cdll.seekcamera_manager_create( 853 | ctypes.pointer(manager.pointer), ctypes.c_uint32(discovery_mode) 854 | ) 855 | return manager, status 856 | 857 | 858 | def cseekcamera_manager_destroy(manager): 859 | return _cdll.seekcamera_manager_destroy(ctypes.pointer(manager.pointer)) 860 | 861 | 862 | def cseekcamera_manager_register_event_callback(manager, callback, user_data): 863 | manager.user_data = user_data 864 | manager.event_callback = callback 865 | 866 | def _event_callback(camera, event_type, event_status, _user_data): 867 | camera_ = CSeekCamera(camera) 868 | 869 | if event_type == 0: # Connect 870 | manager.cameras.append(camera_) 871 | manager.event_callback(camera_, event_type, event_status, manager.user_data) 872 | elif event_type == 1: # Disconnect 873 | manager.event_callback(camera_, event_type, event_status, manager.user_data) 874 | manager.cameras.remove(camera_) 875 | elif event_type == 2: # Error 876 | manager.event_callback(camera_, event_type, event_status, manager.user_data) 877 | elif event_type == 3: # Ready to pair 878 | manager.cameras.append(camera_) 879 | manager.event_callback(camera_, event_type, event_status, manager.user_data) 880 | 881 | manager.event_callback_cdll = _SEEKCAMERA_MANAGER_EVENT_CALLBACK_T(_event_callback) 882 | 883 | return _cdll.seekcamera_manager_register_event_callback( 884 | manager.pointer, 885 | manager.event_callback_cdll, 886 | ctypes.py_object(manager.user_data), 887 | ) 888 | 889 | 890 | def cseekcamera_manager_get_event_str(event): 891 | c_str = _cdll.seekcamera_manager_get_event_str(ctypes.c_int(event)) 892 | return c_str 893 | 894 | 895 | def cseekcamera_error_get_str(status): 896 | return _cdll.seekcamera_error_get_str(status) 897 | 898 | 899 | def cseekcamera_get_io_type(camera): 900 | io_type = ctypes.c_int32() 901 | status = _cdll.seekcamera_get_io_type(camera.pointer, ctypes.byref(io_type)) 902 | return io_type, status 903 | 904 | 905 | def cseekcamera_get_io_properties(camera): 906 | properties = CSeekCameraIOProperties() 907 | status = _cdll.seekcamera_get_io_properties( 908 | camera.pointer, ctypes.pointer(properties) 909 | ) 910 | 911 | return properties, status 912 | 913 | 914 | def cseekcamera_get_chipid(camera): 915 | chipid = (ctypes.c_char * 16)() 916 | status = _cdll.seekcamera_get_chipid(camera.pointer, ctypes.pointer(chipid)) 917 | return chipid, status 918 | 919 | 920 | def cseekcamera_get_serial_number(camera): 921 | serial_number = (ctypes.c_char * 16)() 922 | status = _cdll.seekcamera_get_serial_number( 923 | camera.pointer, ctypes.pointer(serial_number) 924 | ) 925 | 926 | return serial_number, status 927 | 928 | 929 | def cseekcamera_get_core_part_number(camera): 930 | core_part_number = (ctypes.c_char * 32)() 931 | status = _cdll.seekcamera_get_core_part_number( 932 | camera.pointer, ctypes.pointer(core_part_number) 933 | ) 934 | return core_part_number, status 935 | 936 | 937 | def cseekcamera_get_firmware_version(camera): 938 | firmware_version = CSeekCameraFirmwareVersion() 939 | status = _cdll.seekcamera_get_firmware_version( 940 | camera.pointer, ctypes.pointer(firmware_version) 941 | ) 942 | 943 | return firmware_version, status 944 | 945 | 946 | def cseekcamera_get_thermography_window(camera): 947 | x = ctypes.c_size_t() 948 | y = ctypes.c_size_t() 949 | w = ctypes.c_size_t() 950 | h = ctypes.c_size_t() 951 | status = _cdll.seekcamera_get_thermography_window( 952 | camera.pointer, 953 | ctypes.byref(x), 954 | ctypes.byref(y), 955 | ctypes.byref(w), 956 | ctypes.byref(h), 957 | ) 958 | 959 | return x, y, w, h, status 960 | 961 | 962 | def cseekcamera_set_thermography_window(camera, x, y, w, h): 963 | status = _cdll.seekcamera_set_thermography_window( 964 | camera.pointer, 965 | ctypes.c_size_t(x), 966 | ctypes.c_size_t(y), 967 | ctypes.c_size_t(w), 968 | ctypes.c_size_t(h), 969 | ) 970 | 971 | return status 972 | 973 | 974 | def cseekcamera_update_firmware(camera, upgrade_file, callback, user_data): 975 | path = ctypes.c_char_p(upgrade_file.encode("utf-8")) 976 | return _cdll.seekcamera_update_firmware( 977 | camera.pointer, 978 | path, 979 | _memory_access_callback(callback), 980 | ctypes.py_object(user_data), 981 | ) 982 | 983 | 984 | def cseekcamera_store_calibration_data(camera, source_dir, callback, user_data): 985 | path = ctypes.c_char_p() 986 | if source_dir: 987 | path = ctypes.c_char_p(source_dir.encode("utf-8")) 988 | 989 | return _cdll.seekcamera_store_calibration_data( 990 | camera.pointer, 991 | path, 992 | _memory_access_callback(callback), 993 | ctypes.py_object(user_data), 994 | ) 995 | 996 | 997 | def cseekcamera_store_flat_scene_correction(camera, fsc_id, callback, user_data): 998 | return _cdll.seekcamera_store_flat_scene_correction( 999 | camera.pointer, 1000 | ctypes.c_int32(fsc_id), 1001 | _memory_access_callback(callback), 1002 | ctypes.py_object(user_data), 1003 | ) 1004 | 1005 | 1006 | def cseekcamera_delete_flat_scene_correction(camera, fsc_id, callback, user_data): 1007 | return _cdll.seekcamera_delete_flat_scene_correction( 1008 | camera.pointer, 1009 | ctypes.c_int32(fsc_id), 1010 | _memory_access_callback(callback), 1011 | ctypes.py_object(user_data), 1012 | ) 1013 | 1014 | 1015 | def cseekcamera_load_app_resources(camera, region, data_size, callback, user_data): 1016 | data = (ctypes.c_byte * data_size)() 1017 | data_pointer = ctypes.cast(data, ctypes.POINTER(ctypes.c_void_p)) 1018 | 1019 | status = _cdll.seekcamera_load_app_resources( 1020 | camera.pointer, 1021 | ctypes.c_int32(region), 1022 | data_pointer, 1023 | ctypes.c_size_t(data_size), 1024 | _memory_access_callback(callback), 1025 | ctypes.py_object(user_data), 1026 | ) 1027 | 1028 | return data, data_size, status 1029 | 1030 | 1031 | def cseekcamera_store_app_resources( 1032 | camera, region, data, data_size, callback, user_data 1033 | ): 1034 | data_pointer = ctypes.cast( 1035 | (ctypes.c_byte * data_size).from_buffer(data), ctypes.POINTER(ctypes.c_void_p) 1036 | ) 1037 | 1038 | return _cdll.seekcamera_store_app_resources( 1039 | camera.pointer, 1040 | ctypes.c_int32(region), 1041 | data_pointer, 1042 | ctypes.c_size_t(data_size), 1043 | _memory_access_callback(callback), 1044 | ctypes.py_object(user_data), 1045 | ) 1046 | 1047 | 1048 | def cseekcamera_capture_session_start(camera, frame_format): 1049 | return _cdll.seekcamera_capture_session_start( 1050 | camera.pointer, ctypes.c_uint32(frame_format) 1051 | ) 1052 | 1053 | 1054 | def cseekcamera_capture_session_stop(camera): 1055 | return _cdll.seekcamera_capture_session_stop(camera.pointer) 1056 | 1057 | 1058 | def cseekcamera_register_frame_available_callback(camera, callback, user_data): 1059 | camera.user_data = user_data 1060 | camera.event_callback = callback 1061 | 1062 | def _frame_available_callback(_camera, camera_frame, _user_data): 1063 | camera.event_callback(camera, CSeekCameraFrame(camera_frame), camera.user_data) 1064 | 1065 | camera.event_callback_cdll = _SEEKCAMERA_FRAME_AVAILABLE_CALLBACK_T( 1066 | _frame_available_callback 1067 | ) 1068 | 1069 | return _cdll.seekcamera_register_frame_available_callback( 1070 | camera.pointer, camera.event_callback_cdll, ctypes.py_object(camera.user_data) 1071 | ) 1072 | 1073 | 1074 | def cseekcamera_get_color_palette(camera): 1075 | palette = ctypes.c_int32() 1076 | status = _cdll.seekcamera_get_color_palette(camera.pointer, ctypes.byref(palette)) 1077 | return palette, status 1078 | 1079 | 1080 | def cseekcamera_set_color_palette(camera, palette): 1081 | return _cdll.seekcamera_set_color_palette(camera.pointer, ctypes.c_int32(palette)) 1082 | 1083 | 1084 | def cseekcamera_set_color_palette_data(camera, palette, palette_data): 1085 | return _cdll.seekcamera_set_color_palette_data( 1086 | camera.pointer, ctypes.c_int32(palette), ctypes.byref(palette_data) 1087 | ) 1088 | 1089 | 1090 | def cseekcamera_get_pipeline_mode(camera): 1091 | mode = ctypes.c_int32() 1092 | status = _cdll.seekcamera_get_pipeline_mode(camera.pointer, ctypes.byref(mode)) 1093 | return mode, status 1094 | 1095 | 1096 | def cseekcamera_set_pipeline_mode(camera, mode): 1097 | return _cdll.seekcamera_set_pipeline_mode(camera.pointer, ctypes.c_int32(mode)) 1098 | 1099 | 1100 | def cseekcamera_get_agc_mode(camera): 1101 | mode = ctypes.c_int32() 1102 | status = _cdll.seekcamera_get_agc_mode(camera.pointer, ctypes.byref(mode)) 1103 | return mode, status 1104 | 1105 | 1106 | def cseekcamera_set_agc_mode(camera, mode): 1107 | return _cdll.seekcamera_set_agc_mode(camera.pointer, ctypes.c_int32(mode)) 1108 | 1109 | 1110 | def cseekcamera_get_histeq_agc_plateau(camera): 1111 | plateau = ctypes.c_float() 1112 | status = _cdll.seekcamera_get_histeq_agc_plateau( 1113 | camera.pointer, ctypes.byref(plateau) 1114 | ) 1115 | 1116 | return plateau, status 1117 | 1118 | 1119 | def cseekcamera_set_histeq_agc_plateau(camera, plateau): 1120 | return _cdll.seekcamera_set_histeq_agc_plateau( 1121 | camera.pointer, ctypes.c_float(plateau) 1122 | ) 1123 | 1124 | 1125 | def cseekcamera_get_histeq_agc_plateau_redistribution_mode(camera): 1126 | mode = ctypes.c_int32() 1127 | status = _cdll.seekcamera_get_histeq_agc_plateau_redistribution_mode( 1128 | camera.pointer, ctypes.byref(mode) 1129 | ) 1130 | return mode, status 1131 | 1132 | 1133 | def cseekcamera_set_histeq_agc_plateau_redistribution_mode(camera, mode): 1134 | return _cdll.seekcamera_set_histeq_agc_plateau_redistribution_mode( 1135 | camera.pointer, ctypes.c_int32(mode) 1136 | ) 1137 | 1138 | 1139 | def cseekcamera_get_histeq_agc_gain_limit(camera): 1140 | limit = ctypes.c_float() 1141 | status = _cdll.seekcamera_get_histeq_agc_gain_limit( 1142 | camera.pointer, ctypes.byref(limit) 1143 | ) 1144 | return limit, status 1145 | 1146 | 1147 | def cseekcamera_set_histeq_agc_gain_limit(camera, limit): 1148 | return _cdll.seekcamera_set_histeq_agc_gain_limit( 1149 | camera.pointer, ctypes.c_float(limit) 1150 | ) 1151 | 1152 | 1153 | def cseekcamera_get_histeq_agc_gain_limit_factor_mode(camera): 1154 | mode = ctypes.c_int32() 1155 | status = _cdll.seekcamera_get_histeq_agc_gain_limit_factor_mode( 1156 | camera.pointer, ctypes.byref(mode) 1157 | ) 1158 | 1159 | return mode, status 1160 | 1161 | 1162 | def cseekcamera_set_histeq_agc_gain_limit_factor_mode(camera, mode): 1163 | return _cdll.seekcamera_set_histeq_agc_gain_limit_factor_mode( 1164 | camera.pointer, ctypes.c_int32(mode) 1165 | ) 1166 | 1167 | 1168 | def cseekcamera_get_histeq_agc_gain_limit_factor_xmax(camera): 1169 | xmax = ctypes.c_uint32() 1170 | status = _cdll.seekcamera_get_histeq_agc_gain_limit_factor_xmax( 1171 | camera.pointer, ctypes.byref(xmax) 1172 | ) 1173 | 1174 | return xmax, status 1175 | 1176 | 1177 | def cseekcamera_set_histeq_agc_gain_limit_factor_xmax(camera, xmax): 1178 | return _cdll.seekcamera_set_histeq_agc_gain_limit_factor_xmax( 1179 | camera.pointer, ctypes.c_uint32(xmax) 1180 | ) 1181 | 1182 | 1183 | def cseekcamera_get_histeq_agc_gain_limit_factor_ymin(camera): 1184 | ymin = ctypes.c_float() 1185 | status = _cdll.seekcamera_get_histeq_agc_gain_limit_factor_ymin( 1186 | camera.pointer, ctypes.byref(ymin) 1187 | ) 1188 | 1189 | return ymin, status 1190 | 1191 | 1192 | def cseekcamera_set_histeq_agc_gain_limit_factor_ymin(camera, ymin): 1193 | return _cdll.seekcamera_set_histeq_agc_gain_limit_factor_ymin( 1194 | camera.pointer, ctypes.c_float(ymin) 1195 | ) 1196 | 1197 | 1198 | def cseekcamera_get_histeq_agc_alpha_time_seconds(camera): 1199 | alpha_time = ctypes.c_float() 1200 | status = _cdll.seekcamera_get_histeq_agc_alpha_time_seconds( 1201 | camera.pointer, ctypes.byref(alpha_time) 1202 | ) 1203 | 1204 | return alpha_time, status 1205 | 1206 | 1207 | def cseekcamera_set_histeq_agc_alpha_time_seconds(camera, alpha_time): 1208 | return _cdll.seekcamera_set_histeq_agc_alpha_time_seconds( 1209 | camera.pointer, ctypes.c_float(alpha_time) 1210 | ) 1211 | 1212 | 1213 | def cseekcamera_get_histeq_agc_trim_left(camera): 1214 | trim = ctypes.c_float() 1215 | status = _cdll.seekcamera_get_histeq_agc_trim_left( 1216 | camera.pointer, ctypes.byref(trim) 1217 | ) 1218 | 1219 | return trim, status 1220 | 1221 | 1222 | def cseekcamera_set_histeq_agc_trim_left(camera, trim): 1223 | return _cdll.seekcamera_set_histeq_agc_trim_left( 1224 | camera.pointer, ctypes.c_float(trim) 1225 | ) 1226 | 1227 | 1228 | def cseekcamera_get_histeq_agc_trim_right(camera): 1229 | trim = ctypes.c_float() 1230 | status = _cdll.seekcamera_get_histeq_agc_trim_right( 1231 | camera.pointer, ctypes.byref(trim) 1232 | ) 1233 | 1234 | return trim, status 1235 | 1236 | 1237 | def cseekcamera_set_histeq_agc_trim_right(camera, trim): 1238 | return _cdll.seekcamera_set_histeq_agc_trim_right( 1239 | camera.pointer, ctypes.c_float(trim) 1240 | ) 1241 | 1242 | 1243 | def cseekcamera_set_histeq_agc_roi_left(camera, left): 1244 | return _cdll.seekcamera_set_histeq_agc_roi_left( 1245 | camera.pointer, ctypes.c_int32(left) 1246 | ) 1247 | 1248 | 1249 | def cseekcamera_get_histeq_agc_roi_left(camera): 1250 | left = ctypes.c_int32() 1251 | status = _cdll.seekcamera_get_histeq_agc_roi_left( 1252 | camera.pointer, ctypes.byref(left) 1253 | ) 1254 | 1255 | return left, status 1256 | 1257 | 1258 | def cseekcamera_set_histeq_agc_roi_top(camera, top): 1259 | return _cdll.seekcamera_set_histeq_agc_roi_top(camera.pointer, ctypes.c_int32(top)) 1260 | 1261 | 1262 | def cseekcamera_get_histeq_agc_roi_top(camera): 1263 | top = ctypes.c_int32() 1264 | status = _cdll.seekcamera_get_histeq_agc_roi_top(camera.pointer, ctypes.byref(top)) 1265 | 1266 | return top, status 1267 | 1268 | 1269 | def cseekcamera_set_histeq_agc_roi_width(camera, width): 1270 | return _cdll.seekcamera_set_histeq_agc_roi_width( 1271 | camera.pointer, ctypes.c_int32(width) 1272 | ) 1273 | 1274 | 1275 | def cseekcamera_get_histeq_agc_roi_width(camera): 1276 | width = ctypes.c_int32() 1277 | status = _cdll.seekcamera_get_histeq_agc_roi_width( 1278 | camera.pointer, ctypes.byref(width) 1279 | ) 1280 | 1281 | return width, status 1282 | 1283 | 1284 | def cseekcamera_set_histeq_agc_roi_height(camera, height): 1285 | return _cdll.seekcamera_set_histeq_agc_roi_height( 1286 | camera.pointer, ctypes.c_int32(height) 1287 | ) 1288 | 1289 | 1290 | def cseekcamera_get_histeq_agc_roi_height(camera): 1291 | height = ctypes.c_int32() 1292 | status = _cdll.seekcamera_get_histeq_agc_roi_height( 1293 | camera.pointer, ctypes.byref(height) 1294 | ) 1295 | 1296 | return height, status 1297 | 1298 | 1299 | def cseekcamera_set_histeq_agc_roi_enable(camera, enable): 1300 | return _cdll.seekcamera_set_histeq_agc_roi_enable( 1301 | camera.pointer, ctypes.c_bool(enable) 1302 | ) 1303 | 1304 | 1305 | def cseekcamera_get_histeq_agc_roi_enable(camera): 1306 | enable = ctypes.c_bool() 1307 | status = _cdll.seekcamera_get_histeq_agc_roi_enable( 1308 | camera.pointer, ctypes.byref(enable) 1309 | ) 1310 | 1311 | return enable, status 1312 | 1313 | 1314 | def cseekcamera_get_linear_agc_lock_mode(camera): 1315 | mode = ctypes.c_int32() 1316 | status = _cdll.seekcamera_get_linear_agc_lock_mode( 1317 | camera.pointer, ctypes.byref(mode) 1318 | ) 1319 | 1320 | return mode, status 1321 | 1322 | 1323 | def cseekcamera_set_linear_agc_lock_mode(camera, mode): 1324 | return _cdll.seekcamera_set_linear_agc_lock_mode( 1325 | camera.pointer, ctypes.c_int32(mode) 1326 | ) 1327 | 1328 | 1329 | def cseekcamera_get_linear_agc_lock_min(camera): 1330 | lock_min = ctypes.c_float() 1331 | status = _cdll.seekcamera_get_linear_agc_lock_min( 1332 | camera.pointer, ctypes.byref(lock_min) 1333 | ) 1334 | 1335 | return lock_min, status 1336 | 1337 | 1338 | def cseekcamera_set_linear_agc_lock_min(camera, lock_min): 1339 | return _cdll.seekcamera_set_linear_agc_lock_min( 1340 | camera.pointer, ctypes.c_float(lock_min) 1341 | ) 1342 | 1343 | 1344 | def cseekcamera_get_linear_agc_lock_max(camera): 1345 | lock_max = ctypes.c_float() 1346 | status = _cdll.seekcamera_get_linear_agc_lock_max( 1347 | camera.pointer, ctypes.byref(lock_max) 1348 | ) 1349 | 1350 | return lock_max, status 1351 | 1352 | 1353 | def cseekcamera_set_linear_agc_lock_max(camera, lock_max): 1354 | return _cdll.seekcamera_set_linear_agc_lock_max( 1355 | camera.pointer, ctypes.c_float(lock_max) 1356 | ) 1357 | 1358 | 1359 | def cseekcamera_get_shutter_mode(camera): 1360 | mode = ctypes.c_int32() 1361 | status = _cdll.seekcamera_get_shutter_mode(camera.pointer, ctypes.byref(mode)) 1362 | return mode, status 1363 | 1364 | 1365 | def cseekcamera_set_shutter_mode(camera, mode): 1366 | return _cdll.seekcamera_set_shutter_mode(camera.pointer, ctypes.c_int32(mode)) 1367 | 1368 | 1369 | def cseekcamera_shutter_trigger(camera): 1370 | return _cdll.seekcamera_shutter_trigger(camera.pointer) 1371 | 1372 | 1373 | def cseekcamera_get_temperature_unit(camera): 1374 | unit = ctypes.c_int32() 1375 | status = _cdll.seekcamera_get_temperature_unit(camera.pointer, ctypes.byref(unit)) 1376 | return unit, status 1377 | 1378 | 1379 | def cseekcamera_set_temperature_unit(camera, unit): 1380 | return _cdll.seekcamera_set_temperature_unit(camera.pointer, ctypes.c_int32(unit)) 1381 | 1382 | 1383 | def cseekcamera_get_scene_emissivity(camera): 1384 | emissivity = ctypes.c_float() 1385 | status = _cdll.seekcamera_get_scene_emissivity( 1386 | camera.pointer, ctypes.byref(emissivity) 1387 | ) 1388 | 1389 | return emissivity, status 1390 | 1391 | 1392 | def cseekcamera_set_scene_emissivity(camera, emissivity): 1393 | return _cdll.seekcamera_set_scene_emissivity( 1394 | camera.pointer, ctypes.c_float(emissivity) 1395 | ) 1396 | 1397 | 1398 | def cseekcamera_get_thermography_offset(camera): 1399 | offset = ctypes.c_float() 1400 | status = _cdll.seekcamera_get_thermography_offset( 1401 | camera.pointer, ctypes.byref(offset) 1402 | ) 1403 | 1404 | return offset, status 1405 | 1406 | 1407 | def cseekcamera_set_thermography_offset(camera, offset): 1408 | return _cdll.seekcamera_set_thermography_offset( 1409 | camera.pointer, ctypes.c_float(offset) 1410 | ) 1411 | 1412 | 1413 | def cseekcamera_get_gradient_correction_filter_enable(camera): 1414 | enable = ctypes.c_bool() 1415 | status = _cdll.seekcamera_get_gradient_correction_filter_enable( 1416 | camera.pointer, ctypes.byref(enable) 1417 | ) 1418 | 1419 | return enable, status 1420 | 1421 | 1422 | def cseekcamera_set_gradient_correction_filter_enable(camera, enable): 1423 | return _cdll.seekcamera_set_gradient_correction_filter_enable( 1424 | camera.pointer, ctypes.c_bool(enable) 1425 | ) 1426 | 1427 | 1428 | def cseekcamera_get_flat_scene_correction_filter_enable(camera): 1429 | enable = ctypes.c_bool() 1430 | status = _cdll.seekcamera_get_flat_scene_correction_filter_enable( 1431 | camera.pointer, ctypes.byref(enable) 1432 | ) 1433 | 1434 | return enable, status 1435 | 1436 | 1437 | def cseekcamera_set_flat_scene_correction_filter_enable(camera, enable): 1438 | return _cdll.seekcamera_set_flat_scene_correction_filter_enable( 1439 | camera.pointer, ctypes.c_bool(enable) 1440 | ) 1441 | 1442 | 1443 | def cseekcamera_get_sharpen_correction_filter_enable(camera): 1444 | enable = ctypes.c_bool() 1445 | status = _cdll.seekcamera_get_sharpen_correction_filter_enable( 1446 | camera.pointer, ctypes.byref(enable) 1447 | ) 1448 | 1449 | return enable, status 1450 | 1451 | 1452 | def cseekcamera_set_sharpen_correction_filter_enable(camera, enable): 1453 | return _cdll.seekcamera_set_sharpen_correction_filter_enable( 1454 | camera.pointer, ctypes.c_bool(enable) 1455 | ) 1456 | 1457 | 1458 | def cseekcamera_set_filter_state(camera, filter_type, filter_state): 1459 | return _cdll.seekcamera_set_filter_state( 1460 | camera.pointer, ctypes.c_int32(filter_type), ctypes.c_int32(filter_state) 1461 | ) 1462 | 1463 | 1464 | def cseekcamera_get_filter_state(camera, filter_type): 1465 | filter_state = ctypes.c_int32() 1466 | status = _cdll.seekcamera_get_filter_state( 1467 | camera.pointer, ctypes.c_int32(filter_type), ctypes.byref(filter_state) 1468 | ) 1469 | 1470 | return filter_state, status 1471 | 1472 | 1473 | def cseekcamera_frame_get_frame_by_format(camera_frame, fmt): 1474 | frame = ctypes.c_void_p() 1475 | status = _cdll.seekcamera_frame_get_frame_by_format( 1476 | camera_frame.pointer, ctypes.c_int32(fmt), ctypes.pointer(frame) 1477 | ) 1478 | 1479 | return CSeekFrame(frame), status 1480 | 1481 | 1482 | def cseekcamera_frame_lock(camera_frame): 1483 | return _cdll.seekcamera_frame_lock(camera_frame.pointer) 1484 | 1485 | 1486 | def cseekcamera_frame_unlock(camera_frame): 1487 | return _cdll.seekcamera_frame_unlock(camera_frame.pointer) 1488 | 1489 | 1490 | def cseekcamera_version_get_major(): 1491 | return _cdll.seekcamera_version_get_major() 1492 | 1493 | 1494 | def cseekcamera_version_get_minor(): 1495 | return _cdll.seekcamera_version_get_minor() 1496 | 1497 | 1498 | def cseekcamera_version_get_patch(): 1499 | return _cdll.seekcamera_version_get_patch() 1500 | 1501 | 1502 | def cseekcamera_version_get_internal(): 1503 | return _cdll.seekcamera_version_get_internal() 1504 | 1505 | 1506 | def cseekcamera_version_get_qualifier(): 1507 | return _cdll.seekcamera_version_get_qualifier() 1508 | 1509 | 1510 | def cseekframe_get_width(frame): 1511 | return _cdll.seekframe_get_width(frame.pointer) 1512 | 1513 | 1514 | def cseekframe_get_height(frame): 1515 | return _cdll.seekframe_get_height(frame.pointer) 1516 | 1517 | 1518 | def cseekframe_get_channels(frame): 1519 | return _cdll.seekframe_get_channels(frame.pointer) 1520 | 1521 | 1522 | def cseekframe_get_pixel_depth(frame): 1523 | return _cdll.seekframe_get_pixel_depth(frame.pointer) 1524 | 1525 | 1526 | def cseekframe_get_pixel_padding(frame): 1527 | return _cdll.seekframe_get_pixel_padding(frame.pointer) 1528 | 1529 | 1530 | def cseekframe_get_line_stride(frame): 1531 | return _cdll.seekframe_get_line_stride(frame.pointer) 1532 | 1533 | 1534 | def cseekframe_get_line_padding(frame): 1535 | return _cdll.seekframe_get_line_padding(frame.pointer) 1536 | 1537 | 1538 | def cseekframe_get_data_size(frame): 1539 | return _cdll.seekframe_get_data_size(frame.pointer) 1540 | 1541 | 1542 | def cseekframe_get_data(frame): 1543 | return _cdll.seekframe_get_data(frame.pointer) 1544 | 1545 | 1546 | def cseekframe_get_row(frame, y): 1547 | return _cdll.seekframe_get_row(frame.pointer, ctypes.c_size_t(y)) 1548 | 1549 | 1550 | def cseekframe_get_pixel(frame, x, y): 1551 | return _cdll.seekframe_get_pixel( 1552 | frame.pointer, ctypes.c_size_t(x), ctypes.c_size_t(y) 1553 | ) 1554 | 1555 | 1556 | def cseekframe_is_empty(frame): 1557 | return _cdll.seekframe_is_empty(frame.pointer) 1558 | 1559 | 1560 | def cseekframe_get_header_size(frame): 1561 | return _cdll.seekframe_get_header_size(frame.pointer) 1562 | 1563 | 1564 | def cseekframe_get_header(frame): 1565 | return _cdll.seekframe_get_header(frame.pointer) 1566 | -------------------------------------------------------------------------------- /seekcamera/error.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Seek Thermal Inc. 2 | # 3 | # Original author: Michael S. Mead 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | 18 | class SeekCameraError(Exception): 19 | """Base class for SeekCamera errors.""" 20 | 21 | @classmethod 22 | def _exception_for(cls, status): 23 | pass 24 | 25 | 26 | class SeekCameraDeviceCommunicationError(SeekCameraError): 27 | """Raised when device communication fails.""" 28 | 29 | @classmethod 30 | def _exception_for(cls, status): 31 | return status == -1 32 | 33 | 34 | class SeekCameraInvalidParameterError(SeekCameraError): 35 | """Raised when an invalid parameter is passed.""" 36 | 37 | @classmethod 38 | def _exception_for(cls, status): 39 | return status == -2 40 | 41 | 42 | class SeekCameraPermissionsError(SeekCameraError): 43 | """Raised when a permissions error occurs.""" 44 | 45 | @classmethod 46 | def _exception_for(cls, status): 47 | return status == -3 48 | 49 | 50 | class SeekCameraNoDeviceError(SeekCameraError): 51 | """Raised when a command is issued and there is not device.""" 52 | 53 | @classmethod 54 | def _exception_for(cls, status): 55 | return status == -4 56 | 57 | 58 | class SeekCameraDeviceNotFoundError(SeekCameraError): 59 | """Raised when a device is expected to be found but is not.""" 60 | 61 | @classmethod 62 | def _exception_for(cls, status): 63 | return status == -5 64 | 65 | 66 | class SeekCameraDeviceBusyError(SeekCameraError): 67 | """Raised when a request is made but the device is busy.""" 68 | 69 | @classmethod 70 | def _exception_for(cls, status): 71 | return status == -6 72 | 73 | 74 | class SeekCameraTimeoutError(SeekCameraError): 75 | """Raised when an operation times out.""" 76 | 77 | @classmethod 78 | def _exception_for(cls, status): 79 | return status == -7 80 | 81 | 82 | class SeekCameraOverflowError(SeekCameraError): 83 | """Raised when overflow is detected.""" 84 | 85 | @classmethod 86 | def _exception_for(cls, status): 87 | return status == -8 88 | 89 | 90 | class SeekCameraUnknownRequestError(SeekCameraError): 91 | """Raised when an unknown request is made.""" 92 | 93 | @classmethod 94 | def _exception_for(cls, status): 95 | return status == -9 96 | 97 | 98 | class SeekCameraInterruptedError(SeekCameraError): 99 | """Raised when an operation is interrupted.""" 100 | 101 | @classmethod 102 | def _exception_for(cls, status): 103 | return status == -10 104 | 105 | 106 | class SeekCameraOutOfMemoryError(SeekCameraError): 107 | """Raised when the host runs out of memory.""" 108 | 109 | @classmethod 110 | def _exception_for(cls, status): 111 | return status == -11 112 | 113 | 114 | class SeekCameraNotSupportedError(SeekCameraError): 115 | """Raised when a request is made but it is not supported.""" 116 | 117 | @classmethod 118 | def _exception_for(cls, status): 119 | return status == -12 120 | 121 | 122 | class SeekCameraOtherError(SeekCameraError): 123 | """Raised when an unknown error occurs.""" 124 | 125 | @classmethod 126 | def _exception_for(cls, status): 127 | return status == -99 128 | 129 | 130 | class SeekCameraCannotPerformRequestError(SeekCameraError): 131 | """Raised when a request cannot be performed.""" 132 | 133 | @classmethod 134 | def _exception_for(cls, status): 135 | return status == -103 136 | 137 | 138 | class SeekCameraFlashAccessFailure(SeekCameraError): 139 | """Raised when flash access fails.""" 140 | 141 | @classmethod 142 | def _exception_for(cls, status): 143 | return status == -104 144 | 145 | 146 | class SeekCameraImplementationError(SeekCameraError): 147 | """Raised when there is an implementation error.""" 148 | 149 | @classmethod 150 | def _exception_for(cls, status): 151 | return status == -105 152 | 153 | 154 | class SeekCameraRequestPendingError(SeekCameraError): 155 | """Raised when a request is already pending.""" 156 | 157 | @classmethod 158 | def _exception_for(cls, status): 159 | return status == -106 160 | 161 | 162 | class SeekCameraInvalidFirmwareImageError(SeekCameraError): 163 | """Raised when an invalid firmware image is encountered.""" 164 | 165 | @classmethod 166 | def _exception_for(cls, status): 167 | return status == -107 168 | 169 | 170 | class SeekCameraInvalidKeyError(SeekCameraError): 171 | """Raised when an invalid key is encountered.""" 172 | 173 | @classmethod 174 | def _exception_for(cls, status): 175 | return status == -108 176 | 177 | 178 | class SeekCameraSensorCommunicationError(SeekCameraError): 179 | """Raised when sensor communication fails.""" 180 | 181 | @classmethod 182 | def _exception_for(cls, status): 183 | return status == -109 184 | 185 | 186 | class SeekCameraOutOfRangeError(SeekCameraError): 187 | """Raised when a value is out of range.""" 188 | 189 | @classmethod 190 | def _exception_for(cls, status): 191 | return status == -301 192 | 193 | 194 | class SeekCameraVerifyFailedError(SeekCameraError): 195 | """Raised when a verification function fails.""" 196 | 197 | @classmethod 198 | def _exception_for(cls, status): 199 | return status == -302 200 | 201 | 202 | class SeekCameraSystemCallFailedError(SeekCameraError): 203 | """Raised when a generic system call fails.""" 204 | 205 | @classmethod 206 | def _exception_for(cls, status): 207 | return status == -303 208 | 209 | 210 | class SeekCameraFileDoesNotExistError(SeekCameraError): 211 | """Raised when file does not exist but should.""" 212 | 213 | @classmethod 214 | def _exception_for(cls, status): 215 | return status == -400 216 | 217 | 218 | class SeekCameraDirectoryDoesNotExistError(SeekCameraError): 219 | """Raised when a directory does not exist but should.""" 220 | 221 | @classmethod 222 | def _exception_for(cls, status): 223 | return status == -401 224 | 225 | 226 | class SeekCameraFileReadFailedError(SeekCameraError): 227 | """Raised when a file read fails.""" 228 | 229 | @classmethod 230 | def _exception_for(cls, status): 231 | return status == -402 232 | 233 | 234 | class SeekCameraFileWriteFailedError(SeekCameraError): 235 | """Raised when a file write fails.""" 236 | 237 | @classmethod 238 | def _exception_for(cls, status): 239 | return status == -403 240 | 241 | 242 | class SeekCameraNotImplementedError(SeekCameraError): 243 | """Raised when a function is not implemented.""" 244 | 245 | @classmethod 246 | def _exception_for(cls, status): 247 | return status == -1000 248 | 249 | 250 | class SeekCameraNotPairedError(SeekCameraError): 251 | """Raised when a function is called on a non-paired device.""" 252 | 253 | @classmethod 254 | def _exception_for(cls, status): 255 | return status == -1001 256 | 257 | 258 | def is_error(status): 259 | """Checks if the input status code is an error or not. 260 | 261 | Parameters 262 | ---------- 263 | status: int 264 | Integer status code returned by the C API. 265 | 266 | Returns 267 | ------- 268 | bool 269 | True if the status code corresponds to an error; false otherwise. 270 | """ 271 | return status != 0 272 | 273 | 274 | def error_from_status(status): 275 | """Makes a SeekCamera base class or derived class from a status code. 276 | 277 | Parameters 278 | ---------- 279 | status: int 280 | Integer status code returned by the C API. 281 | 282 | Returns 283 | ------- 284 | SeekCameraError 285 | Base class or derived class. 286 | 287 | Raises 288 | ------ 289 | SeekCameraInvalidParameterError 290 | If the input status code does not correspond to an error. 291 | """ 292 | if not is_error(status): 293 | raise SeekCameraInvalidParameterError 294 | 295 | for cls in SeekCameraError.__subclasses__(): 296 | if cls._exception_for(status): 297 | return cls 298 | 299 | return SeekCameraError 300 | -------------------------------------------------------------------------------- /seekcamera/version.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Seek Thermal Inc. 2 | # 3 | # Original author: Michael S. Mead 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | 18 | class SeekCameraVersion: 19 | """Version of the seekcamera-python library. 20 | 21 | The version number scheme is [MAJOR].[MINOR].[PATCH]. 22 | 23 | Attributes 24 | ---------- 25 | MAJOR: int 26 | Major version number of the library. 27 | MINOR: int 28 | Minor version number of the library. 29 | PATCH: int 30 | Patch version number of the library. 31 | """ 32 | 33 | MAJOR = 1 34 | MINOR = 3 35 | PATCH = 0 36 | 37 | def __str__(self): 38 | return "{}.{}.{}".format(self.MAJOR, self.MINOR, self.PATCH) 39 | 40 | def __repr__(self): 41 | return "SeekCameraVersion({}, {}, {})".format( 42 | self.MAJOR, self.MINOR, self.PATCH 43 | ) 44 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Copyright 2021 Seek Thermal Inc. 3 | # 4 | # Original author: Michael S. Mead 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | import setuptools 19 | 20 | long_description = "" 21 | with open("README.md", "r") as f: 22 | long_description = f.read() 23 | 24 | setuptools.setup( 25 | name="seekcamera-python", 26 | version="1.3.0", 27 | author="Seek Thermal Incorporated", 28 | author_email="open-source@thermal.com", 29 | description="Seek Thermal SDK Python Language Bindings", 30 | long_description=long_description, 31 | long_description_content_type="text/markdown", 32 | url="https://github.com/seekthermal/seekcamera-python", 33 | license="Apache License 2.0", 34 | license_files=["LICENSE"], 35 | packages=setuptools.find_packages(), 36 | classifiers=[ 37 | "Programming Language :: Python :: 3", 38 | "Operating System :: OS Independent", 39 | "Intended Audience :: Developers", 40 | ], 41 | python_requires=">=3.0", 42 | install_requires=[ 43 | "numpy>=1", 44 | ], 45 | data_files=[ 46 | ("examples", ["examples/seekcamera-opencv.py", "examples/seekcamera-simple.py"]) 47 | ], 48 | ) 49 | --------------------------------------------------------------------------------