Skip to content

Commit 28d52a0

Browse files
committed
update python API src for ZED SDK 3.8 release
1 parent 025d0ce commit 28d52a0

File tree

3 files changed

+113
-24
lines changed

3 files changed

+113
-24
lines changed

src/pyzed/Utils.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ namespace sl {
196196

197197
sl::ObjectDetectionRuntimeParameters* create_object_detection_runtime_parameters(float confidence_threshold,
198198
std::vector<int> object_vector,
199-
std::map<int,float> object_class_confidence_map) {
199+
std::map<int,float> object_class_confidence_map,
200+
int minimum_keypoints_threshold) {
200201

201202
std::vector<sl::OBJECT_CLASS> object_vector_cpy;
202203
for (unsigned int i = 0; i < object_vector.size(); i++)
@@ -208,6 +209,6 @@ namespace sl {
208209
object_class_confidence_map_cpy[static_cast<sl::OBJECT_CLASS>(map_elem.first)] = map_elem.second;
209210
}
210211
}
211-
return new ObjectDetectionRuntimeParameters(confidence_threshold, object_vector_cpy, object_class_confidence_map_cpy);
212+
return new ObjectDetectionRuntimeParameters(confidence_threshold, object_vector_cpy, object_class_confidence_map_cpy, minimum_keypoints_threshold);
212213
}
213214
}

src/pyzed/sl.pyx

Lines changed: 91 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1212
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1313
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
14-
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
14+
# DATA, OR PROFITS;POSITIONAL_TRACKING_STATE OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1515
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1616
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1717
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -286,6 +286,7 @@ class INPUT_TYPE(enum.Enum):
286286
# | MULTI_CLASS_BOX_MEDIUM | Any object, bounding box based, compromise between accuracy and speed |
287287
# | HUMAN_BODY_MEDIUM | Keypoints based, specific to human skeleton, compromise between accuracy and speed |
288288
# | PERSON_HEAD_BOX | Bounding Box detector specialized in person heads, particulary well suited for crowded environments, the person localization is also improved |
289+
# | PERSON_HEAD_BOX_ACCURATE | Bounding Box detector specialized in person heads, particulary well suited for crowded environments, the person localization is also improved, state of the art accuracy |
289290
# | CUSTOM_BOX_OBJECTS | For external inference, using your own custom model and/or frameworks. This mode disables the internal inference engine, the 2D bounding box detection must be provided |
290291
class DETECTION_MODEL(enum.Enum):
291292
MULTI_CLASS_BOX = <int>c_DETECTION_MODEL.MULTI_CLASS_BOX
@@ -295,6 +296,7 @@ class DETECTION_MODEL(enum.Enum):
295296
MULTI_CLASS_BOX_MEDIUM = <int>c_DETECTION_MODEL.MULTI_CLASS_BOX_MEDIUM
296297
HUMAN_BODY_MEDIUM = <int>c_DETECTION_MODEL.HUMAN_BODY_MEDIUM
297298
PERSON_HEAD_BOX = <int>c_DETECTION_MODEL.PERSON_HEAD_BOX
299+
PERSON_HEAD_BOX_ACCURATE = <int>c_DETECTION_MODEL.PERSON_HEAD_BOX_ACCURATE
298300
CUSTOM_BOX_OBJECTS = <int>c_DETECTION_MODEL.CUSTOM_BOX_OBJECTS
299301
LAST = <int>c_DETECTION_MODEL.LAST
300302

@@ -1057,11 +1059,13 @@ class VIEW(enum.Enum):
10571059
# | OK | Positional tracking is working normally. |
10581060
# | OFF | Positional tracking is not enabled. |
10591061
# | FPS_TOO_LOW | Effective FPS is too low to give proper results for motion tracking. Consider using PERFORMANCE parameters ([DEPTH_MODE.PERFORMANCE](\ref DEPTH_MODE), low camera resolution (VGA,HD720)) |
1062+
# | SEARCHING_FLOOR_PLANE | The camera is searching for the floor plane to locate itself related to it, the REFERENCE_FRAME::WORLD will be set afterward.|
10601063
class POSITIONAL_TRACKING_STATE(enum.Enum):
10611064
SEARCHING = <int>c_POSITIONAL_TRACKING_STATE.SEARCHING
10621065
OK = <int>c_POSITIONAL_TRACKING_STATE.OK
10631066
OFF = <int>c_POSITIONAL_TRACKING_STATE.OFF
10641067
FPS_TOO_LOW = <int>c_POSITIONAL_TRACKING_STATE.FPS_TOO_LOW
1068+
SEARCHING_FLOOR_PLANE = <int>c_POSITIONAL_TRACKING_STATE.SEARCHING_FLOOR_PLANE
10651069
LAST = <int>c_POSITIONAL_TRACKING_STATE.POSITIONAL_TRACKING_STATE_LAST
10661070

10671071
def __str__(self):
@@ -1214,6 +1218,7 @@ class COPY_TYPE(enum.Enum):
12141218
# | U8_C3 | unsigned char 3 channels. |
12151219
# | U8_C4 | unsigned char 4 channels. |
12161220
# | U16_C1 | unsigned short 1 channel. |
1221+
# | S8_C4 | signed char 4 channels. |
12171222
class MAT_TYPE(enum.Enum):
12181223
F32_C1 = <int>c_MAT_TYPE.F32_C1
12191224
F32_C2 = <int>c_MAT_TYPE.F32_C2
@@ -1224,6 +1229,7 @@ class MAT_TYPE(enum.Enum):
12241229
U8_C3 = <int>c_MAT_TYPE.U8_C3
12251230
U8_C4 = <int>c_MAT_TYPE.U8_C4
12261231
U16_C1 = <int>c_MAT_TYPE.U16_C1
1232+
S8_C4 = <int>c_MAT_TYPE.S8_C4
12271233

12281234
##
12291235
# Lists available sensor types
@@ -2405,13 +2411,17 @@ cdef class ObjectDetectionParameters:
24052411
, enable_body_fitting=False, max_range=-1.0
24062412
, batch_trajectories_parameters=BatchParameters()
24072413
, body_format=BODY_FORMAT.POSE_18
2408-
, filtering_mode = OBJECT_FILTERING_MODE.NMS3D):
2414+
, filtering_mode = OBJECT_FILTERING_MODE.NMS3D
2415+
, prediction_timeout_s = 0.2
2416+
, allow_reduced_precision_inference = False):
24092417
self.object_detection = new c_ObjectDetectionParameters(image_sync, enable_tracking
24102418
, enable_mask_output, <c_DETECTION_MODEL>(<unsigned int>detection_model.value)
24112419
, enable_body_fitting, max_range
24122420
, (<BatchParameters>batch_trajectories_parameters).batch_params[0]
24132421
, <c_BODY_FORMAT>(<unsigned int>body_format.value)
2414-
, <c_OBJECT_FILTERING_MODE>(<unsigned int>filtering_mode.value))
2422+
, <c_OBJECT_FILTERING_MODE>(<unsigned int>filtering_mode.value)
2423+
, prediction_timeout_s
2424+
, allow_reduced_precision_inference)
24152425

24162426
def __dealloc__(self):
24172427
del self.object_detection
@@ -2522,6 +2532,26 @@ cdef class ObjectDetectionParameters:
25222532
else :
25232533
raise TypeError()
25242534

2535+
##
2536+
# When an object is not detected anymore, the SDK will predict its positions during a short period of time before its state switched to SEARCHING.
2537+
@property
2538+
def prediction_timeout_s(self):
2539+
return self.object_detection.prediction_timeout_s
2540+
2541+
@prediction_timeout_s.setter
2542+
def prediction_timeout_s(self, float prediction_timeout_s):
2543+
self.object_detection.prediction_timeout_s = prediction_timeout_s
2544+
2545+
##
2546+
# Allow inference to run at a lower precision to improve runtime and memory usage,
2547+
# it might increase the initial optimization time and could include downloading calibration data or calibration cache and slightly reduce the accuracy
2548+
@property
2549+
def allow_reduced_precision_inference(self):
2550+
return self.object_detection.allow_reduced_precision_inference
2551+
2552+
@allow_reduced_precision_inference.setter
2553+
def allow_reduced_precision_inference(self, bool allow_reduced_precision_inference):
2554+
self.object_detection.allow_reduced_precision_inference = allow_reduced_precision_inference
25252555

25262556
##
25272557
# Sets the object detection runtime parameters.
@@ -2534,14 +2564,15 @@ cdef class ObjectDetectionRuntimeParameters:
25342564
# \param detection_confidence_threshold : sets \ref detection_confidence_threshold. Default: 50
25352565
# \param object_class_filter : sets \ref object_class_filter. Default: empty list (all classes are tracked)
25362566
# \param object_class_detection_confidence_threshold : sets \ref object_class_detection_confidence_threshold. Default: empty dict (detection_confidence_threshold value will be taken for each class)
2537-
def __cinit__(self, detection_confidence_threshold=50, object_class_filter=[], object_class_detection_confidence_threshold={}):
2567+
# \param minimum_keypoints_threshold: sets \ref minimum_keypoints_threshold. Default: 0 (all skeletons are retrieved)
2568+
def __cinit__(self, detection_confidence_threshold=50, object_class_filter=[], object_class_detection_confidence_threshold={}, minimum_keypoints_threshold=0):
25382569
cdef vector[int] vec_cpy
25392570
cdef map[int,float] map_cpy
25402571
for object_class in object_class_filter:
25412572
vec_cpy.push_back(<int>object_class.value)
25422573
for k,v in object_class_detection_confidence_threshold.items():
25432574
map_cpy[<int>k.value] = v
2544-
self.object_detection_rt = create_object_detection_runtime_parameters(detection_confidence_threshold, vec_cpy, map_cpy)
2575+
self.object_detection_rt = create_object_detection_runtime_parameters(detection_confidence_threshold, vec_cpy, map_cpy, minimum_keypoints_threshold)
25452576

25462577
def __dealloc__(self):
25472578
del self.object_detection_rt
@@ -2607,6 +2638,18 @@ cdef class ObjectDetectionRuntimeParameters:
26072638
for k,v in object_class_detection_confidence_threshold_dict.items():
26082639
self.object_detection_rt.object_class_detection_confidence_threshold[<c_OBJECT_CLASS>(<unsigned int>k.value)] = v
26092640

2641+
##
2642+
# Defines minimal number of keypoints per skeleton to be retrieved:
2643+
# the SDK will outputs skeleton with more keypoints than this threshold.
2644+
# it is useful for example to remove unstable fitting results when a skeleton is partially occluded.
2645+
@property
2646+
def minimum_keypoints_threshold(self):
2647+
return self.object_detection_rt.minimum_keypoints_threshold
2648+
2649+
@minimum_keypoints_threshold.setter
2650+
def minimum_keypoints_threshold(self, int minimum_keypoints_threshold_):
2651+
self.object_detection_rt.minimum_keypoints_threshold = minimum_keypoints_threshold_
2652+
26102653
# Returns the current timestamp at the time the function is called.
26112654
# \ingroup Core_group
26122655
def get_current_timestamp():
@@ -5380,18 +5423,15 @@ cdef class InitParameters:
53805423
self.init.sdk_verbose_log_file.set(<char*>value_filename)
53815424

53825425
##
5383-
# Regions of the generated depth map can oscillate from one frame to another. These oscillations result from a lack of texture (too homogeneous) on an object and by image noise.
5384-
# This parameter enables a stabilization filter that reduces these oscillations.
5385-
# default : true
5386-
# \note The stabilization uses the positional tracking to increase its accuracy, so the Tracking module will be enabled automatically when set to true.
5387-
#
5388-
# Notice that calling \ref Camera.enable_tracking() with your own parameters afterwards is still possible.
5426+
# Regions of the generated depth map can oscillate from one frame to another. These oscillations result from a lack of texture (too homogeneous) on an object and by image noise.
5427+
# This parameter control a stabilization filter that reduces these oscillations. In the range [0-100], 0 is disable (raw depth), smoothness is linear from 1 to 100.
5428+
# \note The stabilization uses the positional tracking to increase its accuracy, so the Positional Tracking module will be enabled automatically when set to a value different from 0
53895429
@property
53905430
def depth_stabilization(self):
53915431
return self.init.depth_stabilization
53925432

53935433
@depth_stabilization.setter
5394-
def depth_stabilization(self, value: bool):
5434+
def depth_stabilization(self, value: int):
53955435
self.init.depth_stabilization = value
53965436

53975437
##
@@ -5699,17 +5739,18 @@ cdef class PositionalTrackingParameters:
56995739
# \param _set_floor_as_origin : activates \ref set_floor_as_origin
57005740
# \param _enable_imu_fusion : activates \ref enable_imu_fusion
57015741
# \param _set_as_static : activates \ref set_as_static
5702-
#
5742+
# \param _depth_min_range : activates \ref depth_min_range
5743+
# \param _set_gravity_as_origin : This setting allows you to set the odometry world using sensors data.
57035744
# \code
57045745
# params = sl.PositionalTrackingParameters(init_pos=Transform(), _enable_pose_smoothing=True)
57055746
# \endcode
57065747
def __cinit__(self, _init_pos=Transform(), _enable_memory=True, _enable_pose_smoothing=False, _area_path=None,
5707-
_set_floor_as_origin=False, _enable_imu_fusion=True, _set_as_static=False):
5748+
_set_floor_as_origin=False, _enable_imu_fusion=True, _set_as_static=False, _depth_min_range=-1, _set_gravity_as_origin=True):
57085749
if _area_path is None:
5709-
self.tracking = new c_PositionalTrackingParameters((<Transform>_init_pos).transform[0], _enable_memory, _enable_pose_smoothing, String(), _set_floor_as_origin, _enable_imu_fusion, _set_as_static)
5750+
self.tracking = new c_PositionalTrackingParameters((<Transform>_init_pos).transform[0], _enable_memory, _enable_pose_smoothing, String(), _set_floor_as_origin, _enable_imu_fusion, _set_as_static, _depth_min_range, _set_gravity_as_origin)
57105751
else :
57115752
area_path = _area_path.encode()
5712-
self.tracking = new c_PositionalTrackingParameters((<Transform>_init_pos).transform[0], _enable_memory, _enable_pose_smoothing, String(<char*> area_path), _set_floor_as_origin, _enable_imu_fusion, _set_as_static)
5753+
self.tracking = new c_PositionalTrackingParameters((<Transform>_init_pos).transform[0], _enable_memory, _enable_pose_smoothing, String(<char*> area_path), _set_floor_as_origin, _enable_imu_fusion, _set_as_static, _depth_min_range, _set_gravity_as_origin)
57135754

57145755
def __dealloc__(self):
57155756
del self.tracking
@@ -5824,6 +5865,28 @@ cdef class PositionalTrackingParameters:
58245865
@set_as_static.setter
58255866
def set_as_static(self, value: bool):
58265867
self.tracking.set_as_static = value
5868+
5869+
##
5870+
# This setting allows you to change the minimum depth used by the SDK for Positional Tracking.
5871+
# It may be useful for example if any steady objects are in front of the camera and may perturbate the positional tracking algorithm.
5872+
# default : -1, no minimum depth
5873+
@property
5874+
def depth_min_range(self):
5875+
return self.tracking.depth_min_range
5876+
5877+
@depth_min_range.setter
5878+
def depth_min_range(self, value):
5879+
self.tracking.depth_min_range = value
5880+
5881+
##
5882+
# This setting allows you to override 2 of the 3 rotations from initial_world_transform using the IMU gravity
5883+
@property
5884+
def set_gravity_as_origin(self):
5885+
return self.tracking.set_gravity_as_origin
5886+
5887+
@set_gravity_as_origin.setter
5888+
def set_gravity_as_origin(self, value: bool):
5889+
self.tracking.set_gravity_as_origin = value
58275890

58285891
##
58295892
# List of possible camera states.
@@ -7214,6 +7277,14 @@ cdef class Camera:
72147277
else:
72157278
raise TypeError("Arguments must be of MEASURE, MEM and integer types.")
72167279

7280+
##
7281+
# Defines a region of interest to focus on for all the SDK, discarding other parts.
7282+
# \param roi_mask: the \ref Mat defining the requested region of interest, all pixel set to 0 will be discard. If empty, set all pixels as valid,
7283+
# otherwise should fit the resolution of the current instance and its type should be U8_C1.
7284+
# \return An ERROR_CODE if something went wrong.
7285+
def set_region_of_interest(self, py_mat: Mat):
7286+
return ERROR_CODE(<int>self.camera.setRegionOfInterest(py_mat.mat))
7287+
72177288
##
72187289
# Sets the playback cursor to the desired frame number in the SVO file.
72197290
#
@@ -7499,6 +7570,8 @@ cdef class Camera:
74997570
tracking.tracking.area_file_path = self.camera.getPositionalTrackingParameters().area_file_path
75007571
tracking.tracking.enable_imu_fusion = self.camera.getPositionalTrackingParameters().enable_imu_fusion
75017572
tracking.tracking.set_as_static = self.camera.getPositionalTrackingParameters().set_as_static
7573+
tracking.tracking.depth_min_range = self.camera.getPositionalTrackingParameters().depth_min_range
7574+
tracking.tracking.set_gravity_as_origin = self.camera.getPositionalTrackingParameters().set_gravity_as_origin
75027575
return tracking
75037576

75047577
##
@@ -7524,6 +7597,8 @@ cdef class Camera:
75247597
object_detection = ObjectDetectionParameters()
75257598
object_detection.object_detection.image_sync = self.camera.getObjectDetectionParameters().image_sync
75267599
object_detection.object_detection.enable_tracking = self.camera.getObjectDetectionParameters().enable_tracking
7600+
object_detection.object_detection.max_range = self.camera.getObjectDetectionParameters().max_range
7601+
object_detection.object_detection.prediction_timeout_s = self.camera.getObjectDetectionParameters().prediction_timeout_s
75277602
return object_detection
75287603

75297604
##

0 commit comments

Comments
 (0)