rocket-welder-sdk 1.1.47__py3-none-any.whl → 1.2.0__py3-none-any.whl
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.
- rocket_welder_sdk/high_level/data_context.py +4 -1
- rocket_welder_sdk/rocket_welder_client.py +84 -1
- rocket_welder_sdk/segmentation_result.py +42 -8
- {rocket_welder_sdk-1.1.47.dist-info → rocket_welder_sdk-1.2.0.dist-info}/METADATA +1 -1
- {rocket_welder_sdk-1.1.47.dist-info → rocket_welder_sdk-1.2.0.dist-info}/RECORD +7 -7
- {rocket_welder_sdk-1.1.47.dist-info → rocket_welder_sdk-1.2.0.dist-info}/WHEEL +1 -1
- {rocket_welder_sdk-1.1.47.dist-info → rocket_welder_sdk-1.2.0.dist-info}/top_level.txt +0 -0
|
@@ -85,6 +85,7 @@ class ISegmentationDataContext(ABC):
|
|
|
85
85
|
self,
|
|
86
86
|
segment_class: SegmentClass,
|
|
87
87
|
instance_id: int,
|
|
88
|
+
confidence: float,
|
|
88
89
|
points: Union[Sequence[Point], npt.NDArray[np.int32]],
|
|
89
90
|
) -> None:
|
|
90
91
|
"""
|
|
@@ -93,6 +94,7 @@ class ISegmentationDataContext(ABC):
|
|
|
93
94
|
Args:
|
|
94
95
|
segment_class: SegmentClass from schema definition
|
|
95
96
|
instance_id: Instance ID (for multiple instances of same class, 0-255)
|
|
97
|
+
confidence: Detection confidence score (0.0-1.0)
|
|
96
98
|
points: Contour points defining the instance boundary
|
|
97
99
|
"""
|
|
98
100
|
pass
|
|
@@ -150,6 +152,7 @@ class SegmentationDataContext(ISegmentationDataContext):
|
|
|
150
152
|
self,
|
|
151
153
|
segment_class: SegmentClass,
|
|
152
154
|
instance_id: int,
|
|
155
|
+
confidence: float,
|
|
153
156
|
points: Union[Sequence[Point], npt.NDArray[np.int32]],
|
|
154
157
|
) -> None:
|
|
155
158
|
"""Add a segmentation instance for this frame."""
|
|
@@ -162,7 +165,7 @@ class SegmentationDataContext(ISegmentationDataContext):
|
|
|
162
165
|
else:
|
|
163
166
|
points_array = np.array(points, dtype=np.int32)
|
|
164
167
|
|
|
165
|
-
self._writer.append(segment_class.class_id, instance_id, points_array)
|
|
168
|
+
self._writer.append(segment_class.class_id, instance_id, confidence, points_array)
|
|
166
169
|
|
|
167
170
|
def commit(self) -> None:
|
|
168
171
|
"""Commit the context (called automatically when delegate returns)."""
|
|
@@ -85,6 +85,42 @@ class RocketWelderClient:
|
|
|
85
85
|
with self._lock:
|
|
86
86
|
return self._controller is not None and self._controller.is_running
|
|
87
87
|
|
|
88
|
+
@property
|
|
89
|
+
def ml_model_path(self) -> Optional[str]:
|
|
90
|
+
"""
|
|
91
|
+
Path to the ML model file mounted in the container.
|
|
92
|
+
|
|
93
|
+
Reads from ML_MODEL_PATH environment variable set by RocketWelder
|
|
94
|
+
when a model is mapped to this container's pipeline element.
|
|
95
|
+
|
|
96
|
+
Returns:
|
|
97
|
+
The path to the model file (e.g., /var/models/model.hef),
|
|
98
|
+
or None if no model is configured.
|
|
99
|
+
"""
|
|
100
|
+
import os
|
|
101
|
+
|
|
102
|
+
return os.environ.get("ML_MODEL_PATH")
|
|
103
|
+
|
|
104
|
+
@property
|
|
105
|
+
def ml_model_version(self) -> Optional[int]:
|
|
106
|
+
"""
|
|
107
|
+
Version of the ML model.
|
|
108
|
+
|
|
109
|
+
Reads from ML_MODEL_VERSION environment variable set by RocketWelder.
|
|
110
|
+
|
|
111
|
+
Returns:
|
|
112
|
+
The model version as integer, or None if not set or not a valid number.
|
|
113
|
+
"""
|
|
114
|
+
import os
|
|
115
|
+
|
|
116
|
+
value = os.environ.get("ML_MODEL_VERSION")
|
|
117
|
+
if value is None:
|
|
118
|
+
return None
|
|
119
|
+
try:
|
|
120
|
+
return int(value)
|
|
121
|
+
except ValueError:
|
|
122
|
+
return None
|
|
123
|
+
|
|
88
124
|
def get_metadata(self) -> Optional[GstMetadata]:
|
|
89
125
|
"""
|
|
90
126
|
Get the current GStreamer metadata.
|
|
@@ -577,6 +613,47 @@ class RocketWelderClient:
|
|
|
577
613
|
"""Context manager exit."""
|
|
578
614
|
self.stop()
|
|
579
615
|
|
|
616
|
+
@staticmethod
|
|
617
|
+
def get_ml_model_path() -> Optional[str]:
|
|
618
|
+
"""
|
|
619
|
+
Get the ML model path from environment (static method).
|
|
620
|
+
|
|
621
|
+
Convenience method to get the model path without creating a client instance.
|
|
622
|
+
Useful during initialization before the client is created.
|
|
623
|
+
|
|
624
|
+
Returns:
|
|
625
|
+
The path to the model file (e.g., /var/models/model.hef),
|
|
626
|
+
or None if no model is configured.
|
|
627
|
+
|
|
628
|
+
Example:
|
|
629
|
+
model_path = RocketWelderClient.get_ml_model_path()
|
|
630
|
+
if model_path:
|
|
631
|
+
model = load_model(model_path)
|
|
632
|
+
else:
|
|
633
|
+
raise RuntimeError("No ML model configured")
|
|
634
|
+
"""
|
|
635
|
+
import os
|
|
636
|
+
|
|
637
|
+
return os.environ.get("ML_MODEL_PATH")
|
|
638
|
+
|
|
639
|
+
@staticmethod
|
|
640
|
+
def get_ml_model_version() -> Optional[int]:
|
|
641
|
+
"""
|
|
642
|
+
Get the ML model version from environment (static method).
|
|
643
|
+
|
|
644
|
+
Returns:
|
|
645
|
+
The model version as integer, or None if not set or not a valid number.
|
|
646
|
+
"""
|
|
647
|
+
import os
|
|
648
|
+
|
|
649
|
+
value = os.environ.get("ML_MODEL_VERSION")
|
|
650
|
+
if value is None:
|
|
651
|
+
return None
|
|
652
|
+
try:
|
|
653
|
+
return int(value)
|
|
654
|
+
except ValueError:
|
|
655
|
+
return None
|
|
656
|
+
|
|
580
657
|
@classmethod
|
|
581
658
|
def from_connection_string(cls, connection_string: str) -> RocketWelderClient:
|
|
582
659
|
"""
|
|
@@ -750,7 +827,13 @@ class _NoOpKeyPointsWriter(IKeyPointsWriter):
|
|
|
750
827
|
class _NoOpSegmentationWriter(ISegmentationResultWriter):
|
|
751
828
|
"""No-op segmentation writer that discards all data."""
|
|
752
829
|
|
|
753
|
-
def append(
|
|
830
|
+
def append(
|
|
831
|
+
self,
|
|
832
|
+
class_id: int,
|
|
833
|
+
instance_id: int,
|
|
834
|
+
confidence: float,
|
|
835
|
+
points: Any,
|
|
836
|
+
) -> None:
|
|
754
837
|
"""Discard segmentation data."""
|
|
755
838
|
pass
|
|
756
839
|
|
|
@@ -6,8 +6,8 @@ Compatible with C# implementation for cross-platform interoperability.
|
|
|
6
6
|
|
|
7
7
|
Protocol (per frame):
|
|
8
8
|
[FrameId: 8B little-endian][Width: varint][Height: varint]
|
|
9
|
-
[classId: 1B][instanceId: 1B][pointCount: varint][points: delta+varint...]
|
|
10
|
-
[classId: 1B][instanceId: 1B][pointCount: varint][points: delta+varint...]
|
|
9
|
+
[classId: 1B][instanceId: 1B][confidence: 2B LE][pointCount: varint][points: delta+varint...]
|
|
10
|
+
[classId: 1B][instanceId: 1B][confidence: 2B LE][pointCount: varint][points: delta+varint...]
|
|
11
11
|
...
|
|
12
12
|
|
|
13
13
|
Features:
|
|
@@ -104,6 +104,7 @@ class SegmentationInstance:
|
|
|
104
104
|
|
|
105
105
|
class_id: int
|
|
106
106
|
instance_id: int
|
|
107
|
+
confidence: float # Detection confidence score (0.0-1.0)
|
|
107
108
|
points: PointArray # NumPy array of shape (N, 2) with dtype int32
|
|
108
109
|
|
|
109
110
|
def to_normalized(self, width: int, height: int) -> npt.NDArray[np.float32]:
|
|
@@ -237,6 +238,7 @@ class SegmentationResultWriter:
|
|
|
237
238
|
self,
|
|
238
239
|
class_id: int,
|
|
239
240
|
instance_id: int,
|
|
241
|
+
confidence: float,
|
|
240
242
|
points: Union[List[Point], PointArray],
|
|
241
243
|
) -> None:
|
|
242
244
|
"""
|
|
@@ -245,6 +247,7 @@ class SegmentationResultWriter:
|
|
|
245
247
|
Args:
|
|
246
248
|
class_id: Object class ID (0-255)
|
|
247
249
|
instance_id: Instance ID within class (0-255)
|
|
250
|
+
confidence: Detection confidence score (0.0-1.0)
|
|
248
251
|
points: List of (x, y) tuples or NumPy array of shape (N, 2)
|
|
249
252
|
"""
|
|
250
253
|
if class_id < 0 or class_id > 255:
|
|
@@ -266,6 +269,11 @@ class SegmentationResultWriter:
|
|
|
266
269
|
# Write class_id and instance_id
|
|
267
270
|
self._buffer.write(bytes([class_id, instance_id]))
|
|
268
271
|
|
|
272
|
+
# Write confidence as 2 bytes little-endian (ushort 0-65535)
|
|
273
|
+
confidence_clamped = max(0.0, min(1.0, confidence))
|
|
274
|
+
confidence_raw = int(confidence_clamped * 65535)
|
|
275
|
+
self._buffer.write(struct.pack("<H", confidence_raw))
|
|
276
|
+
|
|
269
277
|
# Write point count
|
|
270
278
|
point_count = len(points_array)
|
|
271
279
|
_write_varint(self._buffer, point_count)
|
|
@@ -402,6 +410,13 @@ class SegmentationResultReader:
|
|
|
402
410
|
class_id = header[0]
|
|
403
411
|
instance_id = header[1]
|
|
404
412
|
|
|
413
|
+
# Read confidence (2 bytes little-endian)
|
|
414
|
+
confidence_bytes = self._stream.read(2)
|
|
415
|
+
if len(confidence_bytes) != 2:
|
|
416
|
+
raise EOFError("Unexpected end of stream reading confidence")
|
|
417
|
+
confidence_raw = struct.unpack("<H", confidence_bytes)[0]
|
|
418
|
+
confidence = confidence_raw / 65535.0
|
|
419
|
+
|
|
405
420
|
# Read point count with validation
|
|
406
421
|
point_count = _read_varint(self._stream)
|
|
407
422
|
if point_count > self._max_points_per_instance:
|
|
@@ -412,7 +427,7 @@ class SegmentationResultReader:
|
|
|
412
427
|
if point_count == 0:
|
|
413
428
|
# Empty points array
|
|
414
429
|
points = np.empty((0, 2), dtype=np.int32)
|
|
415
|
-
return SegmentationInstance(class_id, instance_id, points)
|
|
430
|
+
return SegmentationInstance(class_id, instance_id, confidence, points)
|
|
416
431
|
|
|
417
432
|
# Allocate NumPy array for points
|
|
418
433
|
points = np.empty((point_count, 2), dtype=np.int32)
|
|
@@ -430,7 +445,7 @@ class SegmentationResultReader:
|
|
|
430
445
|
y += delta_y
|
|
431
446
|
points[i] = [x, y]
|
|
432
447
|
|
|
433
|
-
return SegmentationInstance(class_id, instance_id, points)
|
|
448
|
+
return SegmentationInstance(class_id, instance_id, confidence, points)
|
|
434
449
|
|
|
435
450
|
def read_all(self) -> List[SegmentationInstance]:
|
|
436
451
|
"""
|
|
@@ -472,6 +487,7 @@ class ISegmentationResultWriter(ABC):
|
|
|
472
487
|
self,
|
|
473
488
|
class_id: int,
|
|
474
489
|
instance_id: int,
|
|
490
|
+
confidence: float,
|
|
475
491
|
points: Union[List[Point], PointArray],
|
|
476
492
|
) -> None:
|
|
477
493
|
"""
|
|
@@ -480,6 +496,7 @@ class ISegmentationResultWriter(ABC):
|
|
|
480
496
|
Args:
|
|
481
497
|
class_id: Object class ID (0-255)
|
|
482
498
|
instance_id: Instance ID within class (0-255)
|
|
499
|
+
confidence: Detection confidence score (0.0-1.0)
|
|
483
500
|
points: List of (x, y) tuples or NumPy array of shape (N, 2)
|
|
484
501
|
"""
|
|
485
502
|
pass
|
|
@@ -741,6 +758,7 @@ class SegmentationProtocol:
|
|
|
741
758
|
Instance Format:
|
|
742
759
|
[ClassId: 1 byte]
|
|
743
760
|
[InstanceId: 1 byte]
|
|
761
|
+
[Confidence: 2 bytes, little-endian uint16]
|
|
744
762
|
[PointCount: varint]
|
|
745
763
|
[Point0: X zigzag-varint, Y zigzag-varint] (absolute)
|
|
746
764
|
[Point1+: deltaX zigzag-varint, deltaY zigzag-varint]
|
|
@@ -777,6 +795,12 @@ class SegmentationProtocol:
|
|
|
777
795
|
def _write_instance_core(stream: BinaryIO, instance: SegmentationInstance) -> None:
|
|
778
796
|
"""Write a single instance to the stream."""
|
|
779
797
|
stream.write(bytes([instance.class_id, instance.instance_id]))
|
|
798
|
+
|
|
799
|
+
# Write confidence as 2 bytes little-endian (ushort 0-65535)
|
|
800
|
+
confidence_clamped = max(0.0, min(1.0, instance.confidence))
|
|
801
|
+
confidence_raw = int(confidence_clamped * 65535)
|
|
802
|
+
stream.write(struct.pack("<H", confidence_raw))
|
|
803
|
+
|
|
780
804
|
point_count = len(instance.points)
|
|
781
805
|
_write_varint(stream, point_count)
|
|
782
806
|
|
|
@@ -823,6 +847,7 @@ class SegmentationProtocol:
|
|
|
823
847
|
buffer: bytearray,
|
|
824
848
|
class_id: int,
|
|
825
849
|
instance_id: int,
|
|
850
|
+
confidence: float,
|
|
826
851
|
points: Union[List[Point], PointArray],
|
|
827
852
|
) -> int:
|
|
828
853
|
"""
|
|
@@ -834,6 +859,7 @@ class SegmentationProtocol:
|
|
|
834
859
|
buffer: Pre-allocated buffer to write to.
|
|
835
860
|
class_id: Class identifier (0-255).
|
|
836
861
|
instance_id: Instance identifier (0-255).
|
|
862
|
+
confidence: Detection confidence score (0.0-1.0).
|
|
837
863
|
points: Polygon points.
|
|
838
864
|
|
|
839
865
|
Returns:
|
|
@@ -845,7 +871,7 @@ class SegmentationProtocol:
|
|
|
845
871
|
else:
|
|
846
872
|
points_array = points.astype(np.int32)
|
|
847
873
|
|
|
848
|
-
instance = SegmentationInstance(class_id, instance_id, points_array)
|
|
874
|
+
instance = SegmentationInstance(class_id, instance_id, confidence, points_array)
|
|
849
875
|
|
|
850
876
|
stream = io.BytesIO()
|
|
851
877
|
SegmentationProtocol._write_instance_core(stream, instance)
|
|
@@ -864,8 +890,8 @@ class SegmentationProtocol:
|
|
|
864
890
|
Returns:
|
|
865
891
|
Maximum bytes needed.
|
|
866
892
|
"""
|
|
867
|
-
# classId(1) + instanceId(1) + pointCount(varint, max 5) + points(max 10 bytes each)
|
|
868
|
-
return 1 + 1 + 5 + (point_count * 10)
|
|
893
|
+
# classId(1) + instanceId(1) + confidence(2) + pointCount(varint, max 5) + points(max 10 bytes each)
|
|
894
|
+
return 1 + 1 + 2 + 5 + (point_count * 10)
|
|
869
895
|
|
|
870
896
|
@staticmethod
|
|
871
897
|
def read(data: bytes) -> SegmentationFrame:
|
|
@@ -899,6 +925,14 @@ class SegmentationProtocol:
|
|
|
899
925
|
|
|
900
926
|
class_id = header[0]
|
|
901
927
|
instance_id = header[1]
|
|
928
|
+
|
|
929
|
+
# Read confidence (2 bytes little-endian)
|
|
930
|
+
confidence_bytes = stream.read(2)
|
|
931
|
+
if len(confidence_bytes) != 2:
|
|
932
|
+
raise EOFError("Unexpected end of stream reading confidence")
|
|
933
|
+
confidence_raw = struct.unpack("<H", confidence_bytes)[0]
|
|
934
|
+
confidence = confidence_raw / 65535.0
|
|
935
|
+
|
|
902
936
|
point_count = _read_varint(stream)
|
|
903
937
|
|
|
904
938
|
if point_count == 0:
|
|
@@ -916,7 +950,7 @@ class SegmentationProtocol:
|
|
|
916
950
|
points[i] = [x, y]
|
|
917
951
|
prev_x, prev_y = x, y
|
|
918
952
|
|
|
919
|
-
instances.append(SegmentationInstance(class_id, instance_id, points))
|
|
953
|
+
instances.append(SegmentationInstance(class_id, instance_id, confidence, points))
|
|
920
954
|
|
|
921
955
|
return SegmentationFrame(frame_id, width, height, instances)
|
|
922
956
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: rocket-welder-sdk
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.2.0
|
|
4
4
|
Summary: High-performance video streaming SDK for RocketWelder services using ZeroBuffer IPC
|
|
5
5
|
Home-page: https://github.com/modelingevolution/rocket-welder-sdk
|
|
6
6
|
Author: ModelingEvolution
|
|
@@ -12,8 +12,8 @@ rocket_welder_sdk/keypoints_protocol.py,sha256=kN8ok6Ptpgl4txoQE9DpKhMoI7zr73vTw
|
|
|
12
12
|
rocket_welder_sdk/opencv_controller.py,sha256=MDM6_yFBB9BaMa5jnZRqw7xZZB-WuLr7EPrrfHQ2DK4,9905
|
|
13
13
|
rocket_welder_sdk/periodic_timer.py,sha256=hnObybmrnf3J47QrNKJhYAytLKwria016123NvPRfQ0,9369
|
|
14
14
|
rocket_welder_sdk/py.typed,sha256=0cXFZXmes4Y-vnl4lO3HtyyyWaFNw85B7tJdFeCtHDc,67
|
|
15
|
-
rocket_welder_sdk/rocket_welder_client.py,sha256=
|
|
16
|
-
rocket_welder_sdk/segmentation_result.py,sha256=
|
|
15
|
+
rocket_welder_sdk/rocket_welder_client.py,sha256=YJ6WwGuJ_R3HdVKmUcNuv8Fg4F54zNidBEgbihWTHaw,36770
|
|
16
|
+
rocket_welder_sdk/segmentation_result.py,sha256=f1rJQFO7lJP5nqzdmFClvty0Z9m5-kvivJu-uK2wmXo,30807
|
|
17
17
|
rocket_welder_sdk/session_id.py,sha256=YgnDwmdOcdJTXIObjkrzIkxU2gbMzNko1h1ms4lNIfU,1928
|
|
18
18
|
rocket_welder_sdk/varint.py,sha256=SmffemQCXToRzs3lb7hWQWDY7NmKv4XG_Wb0oeMrb_I,5058
|
|
19
19
|
rocket_welder_sdk/external_controls/__init__.py,sha256=ldOLGhLLS5BQL8m4VKFYV0SvsNNlV2tghlc7rkqadU8,699
|
|
@@ -28,7 +28,7 @@ rocket_welder_sdk/graphics/vector_graphics_encoder.py,sha256=lD3cIOAVL_JvKZayIQ_
|
|
|
28
28
|
rocket_welder_sdk/high_level/__init__.py,sha256=OKbI3l0PFo1Cb_v0kbv16Wr05urz8heVGps0dJcTcG4,1507
|
|
29
29
|
rocket_welder_sdk/high_level/client.py,sha256=rVnnrn68PEvc68p5acuOBZfEjobWWed8XcssTRzxNr8,11502
|
|
30
30
|
rocket_welder_sdk/high_level/connection_strings.py,sha256=1Hp72V5qDngHGXyjBRFMckz365BMpGVjb3PMSGvCtow,12531
|
|
31
|
-
rocket_welder_sdk/high_level/data_context.py,sha256=
|
|
31
|
+
rocket_welder_sdk/high_level/data_context.py,sha256=DuLwIjCBopr2Lyo_fLhRPCC8m7mPwyL8MHYSjrJVUT4,4960
|
|
32
32
|
rocket_welder_sdk/high_level/frame_sink_factory.py,sha256=tLhMV_qnY-ZUtffIzhycM9znNjYguRumba4vphpNx7E,3493
|
|
33
33
|
rocket_welder_sdk/high_level/schema.py,sha256=2Vv0rDwahtGswWB_ceaCdc7JDtmbkx4wE2jQePzeTpU,5367
|
|
34
34
|
rocket_welder_sdk/high_level/transport_protocol.py,sha256=pdl7l1Tu9b7IYb95q6kzDY7-g1fbhSnhdV_gGhLeYzk,2943
|
|
@@ -45,7 +45,7 @@ rocket_welder_sdk/ui/icons.py,sha256=DcDklZkPmiEzlOD4IR7VTJOtGPCuuh_OM_WN7ScghWE
|
|
|
45
45
|
rocket_welder_sdk/ui/ui_events_projection.py,sha256=siiNhjLEBOPfTKw1ZhOPGkwIN5rLDH7V9VCZTNrhEtQ,7836
|
|
46
46
|
rocket_welder_sdk/ui/ui_service.py,sha256=uRdpyJGoCQmtOli_HKSrxLwhZYG-XRuHIYdkmFz1zNk,12026
|
|
47
47
|
rocket_welder_sdk/ui/value_types.py,sha256=f7OA_9zgXEDPoITc8v8SfAR23I4XeFhE3E2_GcAbR6k,1616
|
|
48
|
-
rocket_welder_sdk-1.
|
|
49
|
-
rocket_welder_sdk-1.
|
|
50
|
-
rocket_welder_sdk-1.
|
|
51
|
-
rocket_welder_sdk-1.
|
|
48
|
+
rocket_welder_sdk-1.2.0.dist-info/METADATA,sha256=GLfE2qHXoj5Yg42mKefTI59GBAmPSXjo3bUAo5zX2lY,24738
|
|
49
|
+
rocket_welder_sdk-1.2.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
50
|
+
rocket_welder_sdk-1.2.0.dist-info/top_level.txt,sha256=2iZvBjnwVCUW-uDE23-eJld5PZ9-mlPI69QiXM5IrTA,18
|
|
51
|
+
rocket_welder_sdk-1.2.0.dist-info/RECORD,,
|
|
File without changes
|