asmagic 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
asmagic-0.1.2/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Shenzhen AncoraSpring Robotics Technology Co., Ltd.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,35 @@
1
+ # Include only necessary documentation
2
+ include README.md
3
+ include LICENSE
4
+
5
+ # Include type hints
6
+ include asmagic/py.typed
7
+
8
+ # Include proto files
9
+ recursive-include asmagic/proto *.py
10
+
11
+ # Exclude unnecessary files
12
+ global-exclude __pycache__
13
+ global-exclude *.py[co]
14
+ global-exclude .DS_Store
15
+ exclude *.egg-info
16
+
17
+ # Exclude tutorial and guide files (not needed in package)
18
+ exclude 新手上传PyPI教程.md
19
+ exclude 超简单上传命令.md
20
+ exclude 依赖说明.md
21
+ exclude PUBLISH_TO_PYPI.md
22
+ exclude QUICK_PUBLISH.md
23
+ exclude README_PUBLISH.md
24
+ exclude HIGH_FPS_GUIDE.md
25
+ exclude IDE_SETUP.md
26
+ exclude IMAGE_DISPLAY_GUIDE.md
27
+ exclude SIMPLE_API_GUIDE.md
28
+ exclude TYPE_HINTS_DEMO.md
29
+ exclude USAGE_SIMPLE.md
30
+ exclude publish.sh
31
+ exclude test_type_hints.py
32
+
33
+ # Exclude examples directory (users can see them on GitHub)
34
+ recursive-exclude examples *
35
+
asmagic-0.1.2/PKG-INFO ADDED
@@ -0,0 +1,459 @@
1
+ Metadata-Version: 2.1
2
+ Name: asmagic
3
+ Version: 0.1.2
4
+ Summary: AR Sensor Data Magic Library - Subscribe to AR sensor data streams
5
+ Author: ASMagic Team
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/asmagic/asmagic
8
+ Project-URL: Documentation, https://github.com/asmagic/asmagic#readme
9
+ Project-URL: Repository, https://github.com/asmagic/asmagic
10
+ Project-URL: Issues, https://github.com/asmagic/asmagic/issues
11
+ Keywords: ar,sensor,zmq,protobuf,streaming
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.8
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Topic :: Scientific/Engineering
23
+ Requires-Python: >=3.8
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: numpy>=1.20.0
27
+ Requires-Dist: pyzmq>=22.0.0
28
+ Requires-Dist: protobuf>=4.0.0
29
+ Requires-Dist: opencv-python>=4.5.0
30
+ Requires-Dist: Pillow>=8.0.0
31
+ Provides-Extra: dev
32
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
33
+ Requires-Dist: black>=22.0.0; extra == "dev"
34
+ Requires-Dist: mypy>=0.990; extra == "dev"
35
+
36
+ # asmagic
37
+
38
+ > A Python library for receiving AR sensor data streams from asMagic iOS App via ZeroMQ.
39
+
40
+ Working with asMagic App:
41
+
42
+ <a href="https://apps.apple.com/cn/app/asmagic/id6661033548">
43
+ <img src="https://tools.applemediaservices.com/api/badges/download-on-the-app-store/black/en-us?size=250x83" alt="Download on the App Store" height="40">
44
+ </a>
45
+
46
+ Supports real-time streaming of:
47
+
48
+ - 6DOF camera pose (position + orientation)
49
+ - RGB camera images
50
+ - Depth maps
51
+ - Camera intrinsics
52
+ - Device velocity
53
+
54
+ ## Install
55
+
56
+ ```bash
57
+ pip install asmagic
58
+ ```
59
+
60
+ ## Quick Start
61
+
62
+ ```python
63
+ from asmagic import ARDataSubscriber
64
+
65
+ # Create subscriber with your iPhone's IP address
66
+ sub = ARDataSubscriber("192.168.1.100")
67
+
68
+ try:
69
+ # Continuous data streaming
70
+ for data in sub:
71
+ # All sensor data in one frame
72
+ print(f"Timestamp: {data.timestamp}")
73
+ print(f"Velocity: {data.velocity}")
74
+ print(f"Local Pose: {data.local_pose}")
75
+ print(f"Global Pose: {data.global_pose}")
76
+ print(f"Camera Intrinsics: {data.camera_intrinsics}")
77
+
78
+ # Access image data
79
+ if data.has_color_image:
80
+ # Color: bytes(jpeg format) or array
81
+ color_bytes = data.color_bytes
82
+ color_array = data.color_array # or shortcut: data.color
83
+ print(f"Color: {len(color_bytes)} bytes, array shape: {color_array.shape}")
84
+
85
+ if data.has_depth_image:
86
+ # Depth: Numpy array
87
+ depth = data.depth_array # or shortcut: data.depth
88
+ print(f"Depth: {depth.shape}")
89
+
90
+ except KeyboardInterrupt:
91
+ print("\nStopped by user")
92
+ finally:
93
+ sub.close()
94
+ ```
95
+
96
+ ## Usage Examples
97
+
98
+ ### Example 1: Continuous Data Reading
99
+
100
+ ```python
101
+ from asmagic import ARDataSubscriber
102
+
103
+ # Connect to iPhone
104
+ sub = ARDataSubscriber("192.168.1.100")
105
+
106
+ try:
107
+ for data in sub:
108
+ # Print all available data
109
+ print(f"\n--- Frame at {data.timestamp} ---")
110
+ print(f"Velocity: {data.velocity}")
111
+ print(f"Local Pose: {data.local_pose}")
112
+ print(f"Global Pose: {data.global_pose}")
113
+ print(f"Camera Intrinsics: {data.camera_intrinsics}")
114
+
115
+ if data.has_depth_image:
116
+ depth = data.depth # or data.depth_array
117
+ print(f"Depth shape: {depth.shape}, min: {depth.min()}, max: {depth.max()}")
118
+
119
+ except KeyboardInterrupt:
120
+ print("\nStopped")
121
+ finally:
122
+ sub.close()
123
+ ```
124
+
125
+ ### Example 2: Display Color and Depth Images
126
+
127
+ ```python
128
+ from asmagic import ARDataSubscriber
129
+ import cv2
130
+
131
+ # Connect to iPhone
132
+ sub = ARDataSubscriber("192.168.1.100")
133
+
134
+ try:
135
+ for data in sub:
136
+ # Display both images side by side
137
+ data.show_images()
138
+
139
+ # Or display individually:
140
+ # data.show_color() # RGB image
141
+ # data.show_depth() # Depth map with colormap
142
+
143
+ # Press ESC to exit
144
+ if cv2.waitKey(1) == 27:
145
+ break
146
+
147
+ except KeyboardInterrupt:
148
+ print("\nStopped")
149
+ finally:
150
+ sub.close()
151
+ cv2.destroyAllWindows()
152
+ ```
153
+
154
+ ### Example 3: Process Image Data
155
+
156
+ ```python
157
+ from asmagic import ARDataSubscriber
158
+ import numpy as np
159
+
160
+ sub = ARDataSubscriber("192.168.1.100")
161
+
162
+ try:
163
+ for data in sub:
164
+
165
+ # Color image: process as numpy array
166
+ if data.has_color_image:
167
+ color = data.color_array # RGB numpy array
168
+ print(f"Color shape: {color.shape}")
169
+
170
+ # Depth image: always as numpy array
171
+ if data.has_depth_image:
172
+ depth = data.depth_array # uint16 numpy array
173
+ depth_meters = depth.astype(np.float32) / 10000.0
174
+ print(f"Depth range: {depth_meters.min():.2f}m - {depth_meters.max():.2f}m")
175
+
176
+ except KeyboardInterrupt:
177
+ pass
178
+ finally:
179
+ sub.close()
180
+ ```
181
+
182
+ ### Example 4: Using Pose Data
183
+
184
+ ```python
185
+ from asmagic import ARDataSubscriber
186
+ import numpy as np
187
+
188
+ sub = ARDataSubscriber("192.168.1.100")
189
+
190
+ try:
191
+ for data in sub:
192
+ # Extract position from pose (first 3 elements)
193
+ position = data.local_pose[:3] # [tx, ty, tz]
194
+
195
+ # Extract quaternion from pose (last 4 elements)
196
+ quaternion = data.local_pose[3:] # [qx, qy, qz, qw]
197
+
198
+ print(f"Position (m): x={position[0]:.3f}, y={position[1]:.3f}, z={position[2]:.3f}")
199
+ print(f"Quaternion: {quaternion}")
200
+ print(f"Velocity (m/s): {data.velocity}") # [vx, vy, vz]
201
+
202
+ except KeyboardInterrupt:
203
+ pass
204
+ finally:
205
+ sub.close()
206
+ ```
207
+
208
+ ### Example 5: Continuous Reading with `get()`
209
+
210
+ ```python
211
+ from asmagic import ARDataSubscriber
212
+
213
+ sub = ARDataSubscriber("192.168.1.100")
214
+
215
+ try:
216
+ while True:
217
+ data = sub.get()
218
+ if data:
219
+ print(f"Timestamp: {data.timestamp}")
220
+ print(f"Velocity: {data.velocity}")
221
+ print(f"Local Pose: {data.local_pose}")
222
+ print(f"Global Pose: {data.global_pose}")
223
+ print(f"Camera Intrinsics: {data.camera_intrinsics}")
224
+
225
+ # Access images
226
+ if data.has_color_image:
227
+ print(f"Color bytes: {len(data.color_bytes)} bytes")
228
+ print(f"Color array: {data.color_array.shape}")
229
+
230
+ if data.has_depth_image:
231
+ print(f"Depth array: {data.depth_array.shape}")
232
+
233
+ except KeyboardInterrupt:
234
+ print("\nStopped")
235
+ finally:
236
+ sub.close()
237
+ ```
238
+
239
+ > **Note**: Example 5 (`while True` with `get()`) and Example 1 (`for data in sub:`) achieve the same goal of continuous data reading.
240
+
241
+ ### Example 6: Get Individual Data Fields
242
+
243
+ ```python
244
+ from asmagic import ARDataSubscriber
245
+ import numpy as np
246
+
247
+ sub = ARDataSubscriber("192.168.1.100")
248
+
249
+ try:
250
+ while True:
251
+ # Get only specific data fields
252
+ timestamp = sub.get_timestamp()
253
+ print(f"Timestamp: {timestamp}")
254
+
255
+ except KeyboardInterrupt:
256
+ print("\nStopped")
257
+ finally:
258
+ sub.close()
259
+ ```
260
+
261
+ > **Note**: Use `get_*()` methods when you only need specific data fields. This is more efficient than receiving the full frame.
262
+
263
+ ## Data Format Reference
264
+
265
+ ### Frame Data Fields
266
+
267
+ Each `data` object contains the following fields:
268
+
269
+ | Field | Type | Shape | Unit | Description |
270
+ | ------------------- | ------------ | ------- | ------- | ----------------------------------------------------------------------- |
271
+ | `timestamp` | `float` | scalar | seconds | Unix timestamp (seconds since 1970-01-01) |
272
+ | `local_pose` | `np.ndarray` | (7,) | m, quat | Camera pose in device coordinate: $[t_x, t_y, t_z, q_x, q_y, q_z, q_w]$ |
273
+ | `global_pose` | `np.ndarray` | (7,) | m, quat | Camera pose in world coordinate: $[t_x, t_y, t_z, q_x, q_y, q_z, q_w]$ |
274
+ | `velocity` | `np.ndarray` | (3,) | m/s | Linear velocity: $[v_x, v_y, v_z]$ |
275
+ | `camera_intrinsics` | `np.ndarray` | (9,) | pixels | 3×3 matrix (flattened): $[f_x, 0, 0, 0, f_y, 0, c_x, c_y, 1]$ |
276
+ | `color_bytes` | `bytes` | - | - | JPEG image bytes (640×480, quality=0.8) |
277
+ | `color_array` | `np.ndarray` | (H,W,3) | - | Decoded RGB image as numpy array |
278
+ | `depth_array` | `np.ndarray` | (H,W) | 10e-4 m | Depth image as numpy array (uint16) |
279
+ | `depth_width` | `int` | scalar | pixels | Depth image width (256 width) |
280
+ | `depth_height` | `int` | scalar | pixels | Depth image height (192 height) |
281
+
282
+ ### Coordinate System
283
+
284
+ **Pose Format**: $[t_x, t_y, t_z, q_x, q_y, q_z, q_w]$
285
+
286
+ - **Translation** (first 3 values): Position in meters
287
+ - $t_x, t_y, t_z$: X, Y, Z coordinates
288
+ - **Rotation** (last 4 values): Orientation as quaternion
289
+ - $q_x, q_y, q_z$: Imaginary part
290
+ - $q_w$: Real part
291
+ - Normalized: $q_x^2 + q_y^2 + q_z^2 + q_w^2 = 1$
292
+
293
+ **Coordinate Frame**:
294
+
295
+ - **X-axis**: Right
296
+ - **Y-axis**: Up
297
+ - **Z-axis**: Forward
298
+
299
+ **Difference between local_pose and global_pose**:
300
+
301
+ - `local_pose`: Position relative to device starting point
302
+ - `global_pose`: Position in shared world coordinate (when multiple devices collaborate)
303
+
304
+ > **Note**: When using a single device, `local_pose` and `global_pose` are identical
305
+
306
+ ### Velocity
307
+
308
+ **Format**: $[v_x, v_y, v_z]$
309
+
310
+ - Calculated as: $\vec{v} = \frac{\Delta \vec{p}}{\Delta t}$
311
+ - Unit: meters per second (m/s)
312
+ - In the same coordinate frame as pose
313
+
314
+ ### Camera Intrinsics
315
+
316
+ **Format**: $[f_x, 0, 0, 0, f_y, 0, c_x, c_y, 1]$
317
+
318
+ Represents 3×3 matrix:
319
+
320
+ $$
321
+ K = \begin{bmatrix}
322
+ f_x & 0 & c_x \\
323
+ 0 & f_y & c_y \\
324
+ 0 & 0 & 1
325
+ \end{bmatrix}
326
+ $$
327
+
328
+ Where:
329
+
330
+ - $f_x, f_y$: Focal length in pixels
331
+ - $c_x, c_y$: Principal point (optical center) in pixels
332
+
333
+ ### Depth Image
334
+
335
+ - **Format**: 16-bit unsigned integer (uint16)
336
+ - **Unit**: $10^{-4}$ m (0.1 mm, scaled by 10000 from meters)
337
+ - **Conversion to meters**: $d_{meters} = \frac{d_{raw}}{10000}$
338
+ - **Range**: $0 \leq d_{raw} \leq 65535$ → $0$ to $6.5535$ m
339
+ - **Access**: Use `data.depth` or `data.depth_array` to get numpy array
340
+
341
+ ### Image Data Access
342
+
343
+ **Color Image**: Two formats available
344
+
345
+ - `color_bytes`: JPEG compressed bytes - use for saving, forwarding, or storage
346
+ - `color_array`: RGB numpy array (H×W×3) - use for processing with OpenCV, deep learning, etc.
347
+ - `color`: Shortcut for `color_array`
348
+
349
+ **Depth Image**: Numpy array only
350
+
351
+ - `depth_array`: uint16 numpy array (H×W) - ready for depth calculations
352
+ - `depth`: Shortcut for `depth_array`
353
+
354
+ | Use Case | Use This | Why |
355
+ | ------------------------- | ------------- | -------------------------------------- |
356
+ | Save color to file | `color_bytes` | No decoding needed, fastest |
357
+ | Forward to network/API | `color_bytes` | Keep compressed format, save bandwidth |
358
+ | Image processing (OpenCV) | `color_array` | Need numpy array for algorithms |
359
+ | Deep learning | `color_array` | Convert to tensors from numpy |
360
+ | Depth calculation | `depth_array` | Ready-to-use (H, W) array |
361
+
362
+ ## API Reference
363
+
364
+ ### ARDataSubscriber
365
+
366
+ **Constructor:**
367
+
368
+ ```python
369
+ ARDataSubscriber(ip, port=8000, hwm=1, conflate=True, verbose=False)
370
+ ```
371
+
372
+ **Parameters:**
373
+
374
+ - `ip` (str): iPhone's IP address
375
+ - `port` (int): Port number (default: 8000)
376
+ - `hwm` (int): High water mark (default: 1, keeps only latest message)
377
+ - `conflate` (bool): Message conflation (default: True)
378
+ - `verbose` (bool): Print connection info (default: False)
379
+
380
+ **Usage:**
381
+
382
+ ```python
383
+ # Create subscriber
384
+ sub = ARDataSubscriber("192.168.1.100")
385
+
386
+ # Continuously receive data
387
+ for data in sub:
388
+ print(data.timestamp)
389
+ print(data.velocity)
390
+
391
+ # Close when done
392
+ sub.close()
393
+ ```
394
+
395
+ **Main Methods:**
396
+
397
+ | Method | Returns | Description |
398
+ | ------------------------- | ---------------------- | -------------------------- |
399
+ | `get()` | `ARFrame` or `None` | Get latest data frame |
400
+ | `get_timestamp()` | `float` or `None` | Get timestamp only |
401
+ | `get_velocity()` | `np.ndarray` or `None` | Get velocity only |
402
+ | `get_local_pose()` | `np.ndarray` or `None` | Get local pose only |
403
+ | `get_global_pose()` | `np.ndarray` or `None` | Get global pose only |
404
+ | `get_camera_intrinsics()` | `np.ndarray` or `None` | Get camera intrinsics only |
405
+ | `get_color_image()` | `bytes` or `None` | Get color image bytes only |
406
+ | `get_depth_image()` | `np.ndarray` or `None` | Get depth array only |
407
+ | `close()` | `None` | Close connection |
408
+
409
+ **Note**:
410
+
411
+ - The subscriber is iterable, so you can use `for data in sub:` to receive frames continuously.
412
+ - All `get_*()` methods accept an optional `timeout` parameter (default: 1000ms).
413
+
414
+ ### ARFrame
415
+
416
+ Data object returned by `get()` or when iterating.
417
+
418
+ **Properties** (see Data Format Reference above for details):
419
+
420
+ | Property | Type | Description |
421
+ | ------------------- | ------------ | ------------------------------------------------- |
422
+ | `timestamp` | `float` | Unix timestamp in seconds |
423
+ | `velocity` | `np.ndarray` | Velocity $[v_x, v_y, v_z]$ in m/s |
424
+ | `local_pose` | `np.ndarray` | Local pose $[t_x, t_y, t_z, q_x, q_y, q_z, q_w]$ |
425
+ | `global_pose` | `np.ndarray` | Global pose $[t_x, t_y, t_z, q_x, q_y, q_z, q_w]$ |
426
+ | `camera_intrinsics` | `np.ndarray` | Camera intrinsics (3×3 flattened) |
427
+ | **Color Image** | | |
428
+ | `color_bytes` | `bytes` | JPEG image bytes (for saving/forwarding) |
429
+ | `color_array` | `np.ndarray` | Decoded RGB image array (H×W×3) |
430
+ | `color` | `np.ndarray` | Shortcut for `color_array` |
431
+ | **Depth Image** | | |
432
+ | `depth_array` | `np.ndarray` | Depth image array (uint16, H×W) |
433
+ | `depth` | `np.ndarray` | Shortcut for `depth_array` |
434
+ | `depth_width` | `int` | Depth image width |
435
+ | `depth_height` | `int` | Depth image height |
436
+ | **Helpers** | | |
437
+ | `has_color_image` | `bool` | Check if color image exists |
438
+ | `has_depth_image` | `bool` | Check if depth image exists |
439
+
440
+ **Methods:**
441
+
442
+ | Method | Returns | Description |
443
+ | ------------------------------------- | ------- | --------------------------------- |
444
+ | `show_color(window_name)` | `bool` | Display color image with OpenCV |
445
+ | `show_depth(window_name, colormap)` | `bool` | Display depth image with colormap |
446
+ | `show_images(show_color, show_depth)` | `tuple` | Display both images side by side |
447
+
448
+ ## Requirements
449
+
450
+ - Python >= 3.8
451
+ - numpy >= 1.20.0
452
+ - pyzmq >= 22.0.0
453
+ - protobuf >= 4.0.0
454
+ - opencv-python >= 4.5.0
455
+ - Pillow >= 8.0.0
456
+
457
+ ## License
458
+
459
+ MIT License