pyhikrobot 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyhikrobot-0.1.0/.gitignore +20 -0
- pyhikrobot-0.1.0/CHANGELOG.md +68 -0
- pyhikrobot-0.1.0/LICENSE +201 -0
- pyhikrobot-0.1.0/NOTICE +11 -0
- pyhikrobot-0.1.0/PKG-INFO +234 -0
- pyhikrobot-0.1.0/README.md +197 -0
- pyhikrobot-0.1.0/pyproject.toml +112 -0
- pyhikrobot-0.1.0/src/hikrobot/__init__.py +97 -0
- pyhikrobot-0.1.0/src/hikrobot/_ctypes_defs.py +568 -0
- pyhikrobot-0.1.0/src/hikrobot/_errors.py +490 -0
- pyhikrobot-0.1.0/src/hikrobot/_loader.py +295 -0
- pyhikrobot-0.1.0/src/hikrobot/camera.py +680 -0
- pyhikrobot-0.1.0/src/hikrobot/device.py +212 -0
- pyhikrobot-0.1.0/src/hikrobot/frame.py +308 -0
- pyhikrobot-0.1.0/src/hikrobot/nodes.py +275 -0
- pyhikrobot-0.1.0/src/hikrobot/py.typed +0 -0
- pyhikrobot-0.1.0/tests/conftest.py +568 -0
- pyhikrobot-0.1.0/tests/hardware/test_smoke.py +491 -0
- pyhikrobot-0.1.0/tests/unit/test_camera.py +213 -0
- pyhikrobot-0.1.0/tests/unit/test_ctypes_defs.py +219 -0
- pyhikrobot-0.1.0/tests/unit/test_device.py +171 -0
- pyhikrobot-0.1.0/tests/unit/test_errors.py +236 -0
- pyhikrobot-0.1.0/tests/unit/test_frame.py +419 -0
- pyhikrobot-0.1.0/tests/unit/test_import.py +38 -0
- pyhikrobot-0.1.0/tests/unit/test_loader.py +191 -0
- pyhikrobot-0.1.0/tests/unit/test_nodes.py +214 -0
- pyhikrobot-0.1.0/tests/unit/test_transport.py +143 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here.
|
|
4
|
+
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## [0.1.0] - 2026-07-27
|
|
10
|
+
|
|
11
|
+
First release. Enumeration, open/close, the GenICam node map, streaming with enforced buffer
|
|
12
|
+
lifetime, and GigE transport tuning — all exercised against an MV-CS023-10GM. Action commands
|
|
13
|
+
and the CUDA layer are not implemented yet, and the public API may still change.
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- README with the public API, the buffer-lifetime rules and the GigE transport notes. Every
|
|
18
|
+
example is verified against a real camera; `ruff format` also parses the Python blocks, so a
|
|
19
|
+
broken snippet fails lint.
|
|
20
|
+
- CI: a `package` job that builds the wheel, installs it into a clean environment and imports it
|
|
21
|
+
from `site-packages` — the check the `src/` layout exists to make possible.
|
|
22
|
+
|
|
23
|
+
- Repository skeleton: `src/` layout, hatchling build, ruff/mypy/pytest configuration, CI matrix
|
|
24
|
+
(ubuntu-latest + windows-latest, unit tests only).
|
|
25
|
+
- `_loader`: lazy MVS library discovery and loading across Linux and Windows, with the
|
|
26
|
+
`MVCAM_SDK_PATH` / `MVCAM_COMMON_RUNENV` / installer-default search order, the
|
|
27
|
+
architecture-directory map, `WinDLL` on Windows and `RTLD_GLOBAL` on Linux.
|
|
28
|
+
- `_errors`: `HikrobotError` base with `SDKNotFoundError`, `SDKLoadError` and
|
|
29
|
+
`UnsupportedPlatformError`.
|
|
30
|
+
- `_errors`: all 55 `MV_E_*` status codes of `MvErrorDefine.h` transcribed by hand, mapped onto a
|
|
31
|
+
`StatusError` hierarchy — one class per vendor range (`GeneralError`, `GenICamError`, `GigEError`,
|
|
32
|
+
`USBError`, `UpgradeError`) plus named classes for the codes callers act on. Codes are normalised
|
|
33
|
+
from the signed `int` the SDK returns, so `restype` may be `c_int` or `c_uint`.
|
|
34
|
+
- `_errors`: the `check` / `call` helpers, the only sanctioned way to invoke an SDK entry point.
|
|
35
|
+
`call(..., allow=...)` covers statuses that are expected at a given call site, which keeps bare
|
|
36
|
+
`if ret != 0` out of the package.
|
|
37
|
+
- `_ctypes_defs`: the structures the enumerate/open/grab path needs — `MV_CC_DEVICE_INFO` with its
|
|
38
|
+
six-member transport union, `MV_CC_DEVICE_INFO_LIST`, `MV_FRAME_OUT_INFO_EX`, `MV_FRAME_OUT` —
|
|
39
|
+
transcribed by hand from `CameraParams.h`, with the transport-layer and access-mode constants.
|
|
40
|
+
- `_ctypes_defs`: `argtypes`/`restype` for the twelve entry points used so far, applied through
|
|
41
|
+
`sdk()`, which loads the library once and declares every prototype before first use.
|
|
42
|
+
- `device`: `enumerate_devices()` and the `DeviceInfo` record. Each record holds its own copy of
|
|
43
|
+
the vendor structure, so it stays valid after a later enumeration has reused the SDK's own.
|
|
44
|
+
- `camera`: `Camera` with `open()` / `close()`, context-manager support, `is_open`,
|
|
45
|
+
`is_connected` and the access-mode table. A failed open destroys the handle it had already
|
|
46
|
+
created; a failed close still destroys it and still forgets it.
|
|
47
|
+
- `CameraStateError` for state mismatches the wrapper catches before the SDK does.
|
|
48
|
+
- Tests: a fake MVS library at the CDLL boundary, so struct packing, `argtypes` and the
|
|
49
|
+
status-to-exception mapping stay under test without hardware.
|
|
50
|
+
- `nodes`: `NodeMap` with typed access to integer, float, boolean, enumeration, string and
|
|
51
|
+
command nodes, plus the `IntRange` / `FloatRange` records. Enumerations go through the `Ex`
|
|
52
|
+
entry point, whose 256-entry list is not capped at 64 like the older one.
|
|
53
|
+
- `frame`: `Frame` — a zero-copy, read-only NumPy view onto a driver node, with metadata
|
|
54
|
+
snapshotted so it outlives the buffer. `data` and `copy()` raise `BufferReleasedError` once the
|
|
55
|
+
node is gone; bit-packed formats raise `UnsupportedPixelFormatError` from `data` and stay
|
|
56
|
+
reachable through `raw_bytes`.
|
|
57
|
+
- `camera`: `start_grabbing()` / `stop_grabbing()` / `is_grabbing`, and the `frames()` and
|
|
58
|
+
`frames_raw()` iterators. `frames()` releases each node in a `finally`; `frames_raw()` hands the
|
|
59
|
+
release to the caller. Stopping acquisition reclaims any frame still outstanding, because the
|
|
60
|
+
pool is torn down with it.
|
|
61
|
+
- `BufferReleasedError` and `UnsupportedPixelFormatError`.
|
|
62
|
+
- `camera`: GigE transport tuning — `packet_size`, `packet_delay`, `optimal_packet_size`,
|
|
63
|
+
`tune_packet_size()`, `enable_resend()` and the `statistics` counters (`TransportStats`).
|
|
64
|
+
`MV_CC_GetOptimalPacketSize` returns the size rather than a status and reports failure by
|
|
65
|
+
returning an `MV_E_*` code, which the wrapper unpicks.
|
|
66
|
+
- `camera`: `Camera.nodes` and `Camera.handle`, plus named properties over the SFNC features -
|
|
67
|
+
`width`, `height`, `offset_x`, `offset_y`, `payload_size`, `exposure_us`, `gain_db`,
|
|
68
|
+
`frame_rate`, `pixel_format`, `pixel_formats`, and the matching range accessors.
|
pyhikrobot-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
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.
|
pyhikrobot-0.1.0/NOTICE
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
pyhikrobot
|
|
2
|
+
Copyright 2026 Stanislav Shalimov
|
|
3
|
+
|
|
4
|
+
This product includes software developed by contributors to the
|
|
5
|
+
pyhikrobot project.
|
|
6
|
+
|
|
7
|
+
Hikrobot and MVS are trademarks of Hangzhou Hikrobot Co., Ltd.
|
|
8
|
+
Use of these names is nominative and does not imply affiliation
|
|
9
|
+
or endorsement. This software does not include or distribute any
|
|
10
|
+
Hikrobot software; the MVS SDK must be obtained from the vendor
|
|
11
|
+
under its own terms.
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pyhikrobot
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Thin, zero-copy Python bindings for Hikrobot machine-vision cameras (MVS SDK).
|
|
5
|
+
Project-URL: Homepage, https://github.com/Shalimov04/pyhikrobot
|
|
6
|
+
Project-URL: Source, https://github.com/Shalimov04/pyhikrobot
|
|
7
|
+
Project-URL: Changelog, https://github.com/Shalimov04/pyhikrobot/blob/main/CHANGELOG.md
|
|
8
|
+
Author: Stanislav Shalimov
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
License-File: NOTICE
|
|
12
|
+
Keywords: camera,genicam,gige,hikrobot,machine-vision,mvs,numpy
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Science/Research
|
|
16
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
17
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Topic :: Multimedia :: Graphics :: Capture
|
|
25
|
+
Classifier: Topic :: Scientific/Engineering :: Image Processing
|
|
26
|
+
Classifier: Typing :: Typed
|
|
27
|
+
Requires-Python: >=3.9
|
|
28
|
+
Requires-Dist: numpy>=1.20
|
|
29
|
+
Provides-Extra: cuda
|
|
30
|
+
Requires-Dist: cupy-cuda12x>=13; extra == 'cuda'
|
|
31
|
+
Provides-Extra: dev
|
|
32
|
+
Requires-Dist: mypy; extra == 'dev'
|
|
33
|
+
Requires-Dist: pytest-cov; extra == 'dev'
|
|
34
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
35
|
+
Requires-Dist: ruff; extra == 'dev'
|
|
36
|
+
Description-Content-Type: text/markdown
|
|
37
|
+
|
|
38
|
+
# pyhikrobot
|
|
39
|
+
|
|
40
|
+
Thin, zero-copy Python bindings for Hikrobot machine-vision cameras over the MVS SDK.
|
|
41
|
+
NumPy views without the copy, a cross-platform loader, and errors you can catch.
|
|
42
|
+
|
|
43
|
+
> **Status: alpha.** Enumeration, open/close, the GenICam node map, streaming and GigE
|
|
44
|
+
> transport tuning are implemented and tested against real hardware. Action commands and
|
|
45
|
+
> the CUDA layer are not written yet. The public API may still change.
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## Requirements
|
|
50
|
+
|
|
51
|
+
| | |
|
|
52
|
+
|---|---|
|
|
53
|
+
| Python | 3.9+ |
|
|
54
|
+
| Runtime dependency | `numpy` — nothing else, ever, in the core package |
|
|
55
|
+
| SDK | Hikrobot MVS 4.x, installed separately by you |
|
|
56
|
+
| Platforms | Linux `x86_64` / `aarch64` / `armv7l`, Windows x64 |
|
|
57
|
+
|
|
58
|
+
This package **does not ship any Hikrobot code**. It opens an SDK you installed yourself;
|
|
59
|
+
get it from the vendor under their terms.
|
|
60
|
+
|
|
61
|
+
## Install
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pip install pyhikrobot
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The `cuda` extra (`pip install "pyhikrobot[cuda]"`) pulls in CuPy for the device-side
|
|
68
|
+
layer, which is not written yet.
|
|
69
|
+
|
|
70
|
+
The SDK is found through `MVCAM_SDK_PATH`, falling back to `/opt/MVS` on Linux and the
|
|
71
|
+
installer's `Common Files\MVS\Runtime` on Windows. Nothing is loaded at import time, so
|
|
72
|
+
`import hikrobot` works on a machine with no SDK and no camera — a missing SDK raises
|
|
73
|
+
`SDKNotFoundError` on first real use.
|
|
74
|
+
|
|
75
|
+
## Quick start
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
import hikrobot
|
|
79
|
+
|
|
80
|
+
devices = hikrobot.enumerate_devices()
|
|
81
|
+
for device in devices:
|
|
82
|
+
print(device.transport, device.model_name, device.serial_number, device.ip_address)
|
|
83
|
+
|
|
84
|
+
with hikrobot.Camera(devices[0]) as camera:
|
|
85
|
+
camera.exposure_us = 2500.0
|
|
86
|
+
camera.gain_db = 0.0
|
|
87
|
+
|
|
88
|
+
for frame in camera.frames(timeout_ms=1000):
|
|
89
|
+
print(frame.frame_number, frame.data.shape, frame.data.mean())
|
|
90
|
+
break
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
`Camera()` touches no SDK state; the context manager opens and closes the device.
|
|
94
|
+
|
|
95
|
+
## Buffer lifetime
|
|
96
|
+
|
|
97
|
+
**This is the one rule that matters.** `frame.data` is a read-only NumPy view onto a node
|
|
98
|
+
of the driver's buffer pool — not memory you own. The pool is fixed and recycled, so once
|
|
99
|
+
the node goes back the driver writes the *next* frame into the same address.
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
for frame in camera.frames(timeout_ms=1000):
|
|
103
|
+
total = frame.data.sum() # fine — inside the body
|
|
104
|
+
keep = frame.copy() # fine — owns its memory, writable
|
|
105
|
+
leaked = frame.data # a view; its node goes back at the end of the body
|
|
106
|
+
break
|
|
107
|
+
|
|
108
|
+
frame.data # BufferReleasedError — the usual mistake, caught
|
|
109
|
+
leaked.mean() # no error, and no longer this frame's pixels
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Note the asymmetry. Reaching for `frame.data` after the release raises, which catches the
|
|
113
|
+
common mistake in development instead of in the field. An array you already took out
|
|
114
|
+
cannot be caught — NumPy has no idea the memory changed hands, so it keeps working and
|
|
115
|
+
quietly returns whatever the driver wrote there next. That is the failure this API is
|
|
116
|
+
shaped to avoid, and `.copy()` is the only thing that avoids it.
|
|
117
|
+
|
|
118
|
+
`frames()` releases the node in a `finally`, on every route out including `break`,
|
|
119
|
+
`return` and exceptions. There is deliberately no "hold this one for me" shortcut: a
|
|
120
|
+
`.copy()` of a 2 MB frame is visible in a profile, an accidentally retained view is not.
|
|
121
|
+
|
|
122
|
+
For consumers that outlive the loop body, `frames_raw()` hands the release over:
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
camera.start_grabbing(node_count=8) # own acquisition, or leaving the loop stops it
|
|
126
|
+
try:
|
|
127
|
+
for frame in camera.frames_raw(timeout_ms=1000):
|
|
128
|
+
queue.put(frame) # released later, by whoever drains the queue
|
|
129
|
+
finally:
|
|
130
|
+
camera.stop_grabbing() # reclaims anything still outstanding
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
The pool holds exactly `node_count` nodes and **the SDK's default is one**, so holding a
|
|
134
|
+
second frame without raising it fails with `InsufficientBufferError`.
|
|
135
|
+
|
|
136
|
+
## Camera settings
|
|
137
|
+
|
|
138
|
+
Named properties cover the common SFNC features:
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
camera.width, camera.height, camera.offset_x, camera.offset_y
|
|
142
|
+
camera.exposure_us, camera.gain_db, camera.frame_rate
|
|
143
|
+
camera.pixel_format, camera.pixel_formats
|
|
144
|
+
camera.payload_size # read-only
|
|
145
|
+
camera.exposure_range_us.min # FloatRange(value, min, max)
|
|
146
|
+
camera.nodes.int_range("Width").inc # IntRange(value, min, max, inc)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Anything else goes through the node map directly:
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
camera.nodes.set_enum("TriggerMode", "On")
|
|
153
|
+
camera.nodes.set_enum("TriggerSource", "Software")
|
|
154
|
+
camera.nodes.execute("TriggerSoftware")
|
|
155
|
+
camera.nodes.get_int("GevTimestampTickFrequency")
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Two behaviours worth knowing, both measured rather than assumed:
|
|
159
|
+
|
|
160
|
+
- A missing node and a wrong-typed access return the **same** status, so both raise
|
|
161
|
+
`GenICamError`. When one appears, check the spelling *and* the type.
|
|
162
|
+
- Float features are quantised to a hardware step the node map does not expose. Writing
|
|
163
|
+
`gain_db = 1.0` reads back as `1.0052`. Write, then read, and trust the second value.
|
|
164
|
+
|
|
165
|
+
## GigE transport
|
|
166
|
+
|
|
167
|
+
The knobs that decide whether streaming works at all:
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
camera.tune_packet_size() # probe the path, apply what it carries
|
|
171
|
+
camera.enable_resend(True) # retransmit packets the host missed
|
|
172
|
+
|
|
173
|
+
camera.start_grabbing(node_count=4)
|
|
174
|
+
for frame in camera.frames(timeout_ms=5000):
|
|
175
|
+
...
|
|
176
|
+
stats = camera.statistics # only valid while acquisition runs
|
|
177
|
+
camera.stop_grabbing()
|
|
178
|
+
|
|
179
|
+
stats.lost_packets, stats.lost_frames, stats.resent_packets
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Incomplete frames almost always mean a packet size the network path cannot carry — start
|
|
183
|
+
with `tune_packet_size()`. Counters live only between `start_grabbing()` and
|
|
184
|
+
`stop_grabbing()` and reset on every start.
|
|
185
|
+
|
|
186
|
+
## Errors
|
|
187
|
+
|
|
188
|
+
Everything derives from `HikrobotError`, so you can catch one thing. Below it, one class
|
|
189
|
+
per vendor error range, plus named classes for the codes callers actually branch on:
|
|
190
|
+
|
|
191
|
+
```text
|
|
192
|
+
HikrobotError
|
|
193
|
+
├── SDKNotFoundError, SDKLoadError, UnsupportedPlatformError
|
|
194
|
+
├── CameraStateError, BufferReleasedError, UnsupportedPixelFormatError
|
|
195
|
+
└── StatusError .status .name .operation
|
|
196
|
+
├── GeneralError InvalidHandleError, CallOrderError, NoDataError,
|
|
197
|
+
│ IncompleteImageError, InsufficientBufferError, …
|
|
198
|
+
├── GenICamError CameraTimeoutError, ValueOutOfRangeError, …
|
|
199
|
+
├── GigEError AccessDeniedError, DeviceBusyError, NetworkError, …
|
|
200
|
+
├── USBError
|
|
201
|
+
└── UpgradeError
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
An untranslated code still arrives as its range's class carrying `.status` and `.name`, so
|
|
205
|
+
nothing is lost:
|
|
206
|
+
|
|
207
|
+
```python
|
|
208
|
+
try:
|
|
209
|
+
camera.open()
|
|
210
|
+
except hikrobot.AccessDeniedError:
|
|
211
|
+
... # held by another process
|
|
212
|
+
except hikrobot.HikrobotError as exc:
|
|
213
|
+
print(exc) # MV_CC_OpenDevice failed: MV_E_NETER (0x80000206) - network error
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## Development
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
pip install -e ".[dev]"
|
|
220
|
+
|
|
221
|
+
pytest tests/unit # no SDK, no camera, no CUDA — runs anywhere
|
|
222
|
+
pytest tests --hardware # opt-in; needs one reachable camera
|
|
223
|
+
ruff check . && ruff format --check . && mypy
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Unit tests run against a fake that sits at the `CDLL` boundary, so struct packing,
|
|
227
|
+
`argtypes` and the status-to-exception mapping stay under test without hardware.
|
|
228
|
+
|
|
229
|
+
## License
|
|
230
|
+
|
|
231
|
+
Apache-2.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
|
|
232
|
+
|
|
233
|
+
Hikrobot and MVS are trademarks of Hangzhou Hikrobot Co., Ltd. This project is not
|
|
234
|
+
affiliated with or endorsed by them, and distributes none of their software.
|