diff --git a/continuous-integration/deployment/expected-version.txt b/continuous-integration/deployment/expected-version.txt index cf869073..76e20a2e 100644 --- a/continuous-integration/deployment/expected-version.txt +++ b/continuous-integration/deployment/expected-version.txt @@ -1 +1 @@ -2.18.0 +2.18.0.1 diff --git a/modules/zivid/_calibration/detector.py b/modules/zivid/_calibration/detector.py index ebe3108d..0066b01a 100644 --- a/modules/zivid/_calibration/detector.py +++ b/modules/zivid/_calibration/detector.py @@ -4,11 +4,14 @@ the zivid.calibration module. """ +from __future__ import annotations + import _zivid import numpy from zivid._calibration.pose import Pose from zivid.camera import Camera from zivid.frame import Frame +from zivid.point_cloud import PointCloud class CalibrationBoardDetectionStatus: # pylint: disable=too-few-public-methods @@ -47,7 +50,7 @@ def __init__(self, impl): self.__impl = impl - def valid(self): + def valid(self) -> bool: """Check validity of DetectionResult. Returns: @@ -55,7 +58,7 @@ def valid(self): """ return self.__impl.valid() - def centroid(self): + def centroid(self) -> numpy.ndarray: """Get the centroid of the detected feature points. Will throw an exception if the DetectionResult is not valid. @@ -65,7 +68,7 @@ def centroid(self): """ return self.__impl.centroid() - def pose(self): + def pose(self) -> Pose: """Get position and orientation of the top left detected corner in camera-space. This is the top left inner corner as viewed from the board's coordinate system. @@ -81,7 +84,7 @@ def pose(self): """ return Pose(self.__impl.pose().to_matrix()) - def status(self): + def status(self) -> str: """Get the status of the detection. Returns: @@ -89,7 +92,7 @@ def status(self): """ return self.__impl.status().name - def status_description(self): + def status_description(self) -> str: """Get a human-readable description of the status. Useful for feedback if valid() returns False. @@ -102,7 +105,7 @@ def status_description(self): """ return self.__impl.status_description() - def feature_points(self): + def feature_points(self) -> list[numpy.ndarray]: """Get the detected feature points in camera-space. Returns a 2D array of 3D coordinates representing the centers of the calibration @@ -116,7 +119,7 @@ def feature_points(self): """ return self.__impl.feature_points() - def feature_points_2d(self): + def feature_points_2d(self) -> list[numpy.ndarray]: """Get the detected feature points in pixel-space. Same as feature_points(), but with 2D coordinates instead of 3D coordinates. The points @@ -159,7 +162,7 @@ def __init__(self, impl): self.__impl = impl @property - def corners_in_pixel_coordinates(self): + def corners_in_pixel_coordinates(self) -> numpy.ndarray: """Get 2D image coordinates of the corners of the detected marker. Returns: @@ -168,7 +171,7 @@ def corners_in_pixel_coordinates(self): return numpy.array(self.__impl.corners_in_pixel_coordinates()) @property - def corners_in_camera_coordinates(self): + def corners_in_camera_coordinates(self) -> numpy.ndarray: """Get 3D spatial coordinates of the corners of the detected marker. Returns: @@ -177,7 +180,7 @@ def corners_in_camera_coordinates(self): return numpy.array(self.__impl.corners_in_camera_coordinates()) @property - def identifier(self): + def identifier(self) -> int: """Get the id of the detected marker. Returns: @@ -186,7 +189,7 @@ def identifier(self): return self.__impl.id_() @property - def pose(self): + def pose(self) -> Pose: """Get 3D pose of the marker. The returned pose will be positioned at the center of the marker, and have an orientation such that its z-axis @@ -251,7 +254,7 @@ class MarkerDictionary: } @classmethod - def valid_values(cls): + def valid_values(cls) -> list[str]: """Get valid values for MarkerDictionary. Returns: @@ -260,7 +263,7 @@ def valid_values(cls): return list(cls._valid_values.keys()) @classmethod - def marker_count(cls, dictionary_name): + def marker_count(cls, dictionary_name: str) -> int: """Get the number of markers in a dictionary. Args: @@ -305,7 +308,7 @@ def __init__(self, impl): self.__impl = impl - def valid(self): + def valid(self) -> bool: """Check validity of DetectionResult. Returns: @@ -313,7 +316,7 @@ def valid(self): """ return self.__impl.valid() - def allowed_marker_ids(self): + def allowed_marker_ids(self) -> list[int]: """Get the allowed marker ids this detection result was made with. Returns: @@ -321,7 +324,7 @@ def allowed_marker_ids(self): """ return self.__impl.allowed_marker_ids() - def detected_markers(self): + def detected_markers(self) -> list[MarkerShape]: """Get all detected markers. Returns: @@ -336,7 +339,7 @@ def __str__(self): return str(self.__impl) -def detect_feature_points(point_cloud): +def detect_feature_points(point_cloud: PointCloud) -> DetectionResult: """Detect feature points from a calibration object in a point cloud. Args: @@ -350,7 +353,7 @@ def detect_feature_points(point_cloud): ) -def detect_calibration_board(source): +def detect_calibration_board(source: Camera | Frame) -> DetectionResult: """Detect feature points from a calibration board in a frame or using a given camera. If a camera is used, this function will perform a relatively slow but high-quality point cloud @@ -386,7 +389,7 @@ def detect_calibration_board(source): ) -def capture_calibration_board(camera): +def capture_calibration_board(camera: Camera) -> Frame: """Capture a calibration board with the given camera. The functionality is to be exclusively used in combination with Zivid verified calibration boards. @@ -409,7 +412,9 @@ def capture_calibration_board(camera): return Frame(_zivid.calibration.capture_calibration_board(camera._Camera__impl)) # pylint: disable=protected-access -def detect_markers(frame, allowed_marker_ids, marker_dictionary): +def detect_markers( + frame: Frame, allowed_marker_ids: list[int], marker_dictionary: str +) -> DetectionResultFiducialMarkers: """Detect fiducial markers such as ArUco markers in a frame. Only markers with integer IDs are supported. To get more information about fiducial markers, refer to the diff --git a/modules/zivid/_calibration/hand_eye.py b/modules/zivid/_calibration/hand_eye.py index 97cb8656..f699717b 100644 --- a/modules/zivid/_calibration/hand_eye.py +++ b/modules/zivid/_calibration/hand_eye.py @@ -4,7 +4,10 @@ the zivid.calibration module. """ +from __future__ import annotations + import _zivid +import numpy from zivid._calibration.detector import DetectionResult, DetectionResultFiducialMarkers from zivid._calibration.pose import Pose @@ -12,7 +15,7 @@ class HandEyeInput: """Class binding together a robot pose and the corresponding detection result.""" - def __init__(self, robot_pose, detection_result): + def __init__(self, robot_pose: Pose, detection_result: DetectionResult | DetectionResultFiducialMarkers) -> None: """Construct a HandEyeInput. Args: @@ -47,7 +50,7 @@ def __init__(self, robot_pose, detection_result): ).format(type(detection_result)) ) - def robot_pose(self): + def robot_pose(self) -> Pose: """Get the contained robot pose. Returns: @@ -55,7 +58,7 @@ def robot_pose(self): """ return Pose(self.__impl.robot_pose()) - def detection_result(self): + def detection_result(self) -> DetectionResult: """Get the contained detection result. Returns: @@ -89,7 +92,7 @@ def __init__(self, impl): ) self.__impl = impl - def rotation(self): + def rotation(self) -> float: """Get the rotation residual. Returns: @@ -97,7 +100,7 @@ def rotation(self): """ return self.__impl.rotation() - def translation(self): + def translation(self) -> float: """Get the translation residual. Returns: @@ -147,7 +150,7 @@ def __init__(self, impl): ) self.__impl = impl - def valid(self): + def valid(self) -> bool: """Check validity of HandEyeOutput. Returns: @@ -158,7 +161,7 @@ def valid(self): def __bool__(self): return bool(self.__impl) - def transform(self): + def transform(self) -> numpy.ndarray: """Get hand-eye transform. Returns: @@ -168,7 +171,7 @@ def transform(self): """ return self.__impl.transform() - def residuals(self): + def residuals(self) -> list[HandEyeResidual]: """Get hand-eye calibration residuals. Returns: @@ -176,7 +179,7 @@ def residuals(self): """ return [HandEyeResidual(internal_residual) for internal_residual in self.__impl.residuals()] - def status(self): + def status(self) -> str: """Get the status of the calibration. Returns: @@ -188,7 +191,7 @@ def __str__(self): return str(self.__impl) -def calibrate_eye_in_hand(calibration_inputs): +def calibrate_eye_in_hand(calibration_inputs: list[HandEyeInput]) -> HandEyeOutput: """Perform eye-in-hand calibration. Args: @@ -207,7 +210,7 @@ def calibrate_eye_in_hand(calibration_inputs): ) -def calibrate_eye_to_hand(calibration_inputs): +def calibrate_eye_to_hand(calibration_inputs: list[HandEyeInput]) -> HandEyeOutput: """Perform eye-to-hand calibration. Args: diff --git a/modules/zivid/_calibration/infield_correction.py b/modules/zivid/_calibration/infield_correction.py index baf9f4ba..2ce3ebb0 100644 --- a/modules/zivid/_calibration/infield_correction.py +++ b/modules/zivid/_calibration/infield_correction.py @@ -4,11 +4,15 @@ the zivid.calibration module. """ +from __future__ import annotations + import _zivid +import numpy from zivid.calibration import DetectionResult +from zivid.camera import Camera -def verify_camera(infield_correction_input): +def verify_camera(infield_correction_input: InfieldCorrectionInput) -> CameraVerification: """Verify the current camera trueness based on a single measurement. The purpose of this function is to allow quick assessment of the quality of @@ -35,7 +39,7 @@ def verify_camera(infield_correction_input): ) -def compute_camera_correction(dataset): +def compute_camera_correction(dataset: list[InfieldCorrectionInput]) -> CameraCorrection: """Calculate new in-field camera correction. The purpose of this function is to calculate a new in-field correction for a @@ -76,7 +80,7 @@ def compute_camera_correction(dataset): ) -def write_camera_correction(camera, camera_correction): +def write_camera_correction(camera: Camera, camera_correction: CameraCorrection) -> None: """Write the in-field correction on a camera. After calling this function, the given correction will automatically be used @@ -97,7 +101,7 @@ def write_camera_correction(camera, camera_correction): ) -def reset_camera_correction(camera): +def reset_camera_correction(camera: Camera) -> None: """Reset the in-field correction on a camera to factory settings. Args: @@ -106,7 +110,7 @@ def reset_camera_correction(camera): _zivid.infield_correction.reset_camera_correction(camera._Camera__impl) # pylint: disable=protected-access -def has_camera_correction(camera): +def has_camera_correction(camera: Camera) -> bool: """Check if the camera has an in-field correction written to it. This is false if write_camera_correction has never been called using this @@ -121,7 +125,7 @@ def has_camera_correction(camera): return _zivid.infield_correction.has_camera_correction(camera._Camera__impl) # pylint: disable=protected-access -def camera_correction_timestamp(camera): +def camera_correction_timestamp(camera: Camera): """Get the UTC time at which the camera's in-field correction was created. Args: @@ -149,14 +153,14 @@ class InfieldCorrectionDetectionStatus: } @classmethod - def valid_values(cls): + def valid_values(cls) -> dict: return cls._valid_values class InfieldCorrectionInput: """Container for input-data needed by in-field verification and correction functions.""" - def __init__(self, detection_result): + def __init__(self, detection_result: DetectionResult) -> None: """Construct an InfieldCorrectionInput instance. Input data should be captured by calling the version of detect_feature_points that @@ -177,7 +181,7 @@ def __init__(self, detection_result): detection_result._DetectionResult__impl, # pylint: disable=protected-access ) - def detection_result(self): + def detection_result(self) -> DetectionResult: """Get the contained DetectionResult. Returns: @@ -185,7 +189,7 @@ def detection_result(self): """ return DetectionResult(self.__impl.detection_result()) - def valid(self): + def valid(self) -> bool: """Check if this object is valid for use with in-field correction. Returns: @@ -193,7 +197,7 @@ def valid(self): """ return self.__impl.valid() - def status_description(self): + def status_description(self) -> str: """Get a string describing the status of this input object. Mostly used to figure out why valid() is False. @@ -203,7 +207,7 @@ def status_description(self): """ return self.__impl.status_description() - def status(self): + def status(self) -> str: """Get a the status of this input object. Mostly used to figure out why valid() is False. @@ -245,7 +249,7 @@ def __init__(self, impl): ) self.__impl = impl - def local_dimension_trueness(self): + def local_dimension_trueness(self) -> float: """Get the estimated local dimension trueness. The dimension trueness represents the relative deviation between the @@ -263,7 +267,7 @@ def local_dimension_trueness(self): """ return self.__impl.local_dimension_trueness() - def position(self): + def position(self) -> numpy.ndarray: """Get the location at which the measurement was made. Returns: @@ -297,7 +301,7 @@ def __init__(self, impl): ) self.__impl = impl - def dimension_accuracy(self): + def dimension_accuracy(self) -> float: """Get the estimated dimension accuracy obtained if the correction is applied. This number represents a 1-sigma (68% confidence) upper bound for @@ -319,7 +323,7 @@ def dimension_accuracy(self): """ return self.__impl.dimension_accuracy() - def z_min(self): + def z_min(self) -> float: """Get the range of validity of the accuracy estimate (lower end). Returns: @@ -327,7 +331,7 @@ def z_min(self): """ return self.__impl.z_min() - def z_max(self): + def z_max(self) -> float: """Get the range of validity of the accuracy estimate (upper end). Returns: @@ -361,7 +365,7 @@ def __init__(self, impl): ) self.__impl = impl - def accuracy_estimate(self): + def accuracy_estimate(self) -> AccuracyEstimate: """Get an estimate for expected dimension accuracy if the correction is applied to the camera. Returns: diff --git a/modules/zivid/_calibration/multi_camera.py b/modules/zivid/_calibration/multi_camera.py index 8bdfb2fc..93909237 100644 --- a/modules/zivid/_calibration/multi_camera.py +++ b/modules/zivid/_calibration/multi_camera.py @@ -4,7 +4,11 @@ the zivid.calibration module. """ +from __future__ import annotations + import _zivid +import numpy +from zivid._calibration.detector import DetectionResult class MultiCameraResidual: @@ -29,7 +33,7 @@ def __init__(self, impl): ) self.__impl = impl - def translation(self): + def translation(self) -> float: """Get the average overlap error. Returns: @@ -63,7 +67,7 @@ def __init__(self, impl): ) self.__impl = impl - def valid(self): + def valid(self) -> bool: """Check validity of MultiCameraOutput. Returns: @@ -74,7 +78,7 @@ def valid(self): def __bool__(self): return bool(self.__impl) - def transforms(self): + def transforms(self) -> list[numpy.ndarray]: """Get multi-camera calibration transforms. Returns: @@ -82,7 +86,7 @@ def transforms(self): """ return self.__impl.transforms() - def residuals(self): + def residuals(self) -> list[MultiCameraResidual]: """Get multi-camera calibration residuals. Returns: @@ -94,7 +98,7 @@ def __str__(self): return str(self.__impl) -def calibrate_multi_camera(detection_results): +def calibrate_multi_camera(detection_results: list[DetectionResult]) -> MultiCameraOutput: """Perform multi-camera calibration. Args: diff --git a/modules/zivid/_calibration/pose.py b/modules/zivid/_calibration/pose.py index 85893067..3b96927f 100644 --- a/modules/zivid/_calibration/pose.py +++ b/modules/zivid/_calibration/pose.py @@ -4,13 +4,16 @@ the zivid.calibration module. """ +from __future__ import annotations + import _zivid +import numpy class Pose: """Class representing a robot pose.""" - def __init__(self, transformation_matrix): + def __init__(self, transformation_matrix: numpy.ndarray) -> None: """Construct a Pose object. Args: @@ -18,7 +21,7 @@ def __init__(self, transformation_matrix): """ self.__impl = _zivid.calibration.Pose(transformation_matrix) - def to_matrix(self): + def to_matrix(self) -> numpy.ndarray: """Get the matrix representation of the pose. Returns: diff --git a/modules/zivid/_local_point_cloud_registration_parameters.py b/modules/zivid/_local_point_cloud_registration_parameters.py index 422ddfae..97b6b9c5 100644 --- a/modules/zivid/_local_point_cloud_registration_parameters.py +++ b/modules/zivid/_local_point_cloud_registration_parameters.py @@ -1,5 +1,7 @@ """Auto generated, do not edit.""" +from __future__ import annotations + # pylint: disable=too-many-lines,protected-access,too-few-public-methods,too-many-arguments,too-many-positional-arguments,line-too-long,missing-function-docstring,missing-class-docstring,redefined-builtin,too-many-branches,too-many-boolean-expressions import _zivid @@ -10,8 +12,12 @@ class ConvergenceCriteria: def __init__( self, - rmse_diff_threshold=_zivid.toolbox.LocalPointCloudRegistrationParameters.ConvergenceCriteria.RMSEDiffThreshold().value, - source_coverage_diff_threshold=_zivid.toolbox.LocalPointCloudRegistrationParameters.ConvergenceCriteria.SourceCoverageDiffThreshold().value, + rmse_diff_threshold: ( + float | int + ) = _zivid.toolbox.LocalPointCloudRegistrationParameters.ConvergenceCriteria.RMSEDiffThreshold().value, + source_coverage_diff_threshold: ( + float | int + ) = _zivid.toolbox.LocalPointCloudRegistrationParameters.ConvergenceCriteria.SourceCoverageDiffThreshold().value, ): if isinstance( @@ -105,9 +111,11 @@ def __str__(self): def __init__( self, - max_correspondence_distance=_zivid.toolbox.LocalPointCloudRegistrationParameters.MaxCorrespondenceDistance().value, - max_iteration_count=_zivid.toolbox.LocalPointCloudRegistrationParameters.MaxIterationCount().value, - convergence_criteria=None, + max_correspondence_distance: ( + float | int + ) = _zivid.toolbox.LocalPointCloudRegistrationParameters.MaxCorrespondenceDistance().value, + max_iteration_count: int = _zivid.toolbox.LocalPointCloudRegistrationParameters.MaxIterationCount().value, + convergence_criteria: LocalPointCloudRegistrationParameters.ConvergenceCriteria | None = None, ): if isinstance( diff --git a/modules/zivid/_suggest_settings_parameters.py b/modules/zivid/_suggest_settings_parameters.py index 1bcf3797..5b7da230 100644 --- a/modules/zivid/_suggest_settings_parameters.py +++ b/modules/zivid/_suggest_settings_parameters.py @@ -1,5 +1,7 @@ """Auto generated, do not edit.""" +from __future__ import annotations + # pylint: disable=too-many-lines,protected-access,too-few-public-methods,too-many-arguments,too-many-positional-arguments,line-too-long,missing-function-docstring,missing-class-docstring,redefined-builtin,too-many-branches,too-many-boolean-expressions import datetime @@ -26,8 +28,8 @@ def valid_values(cls): def __init__( self, - ambient_light_frequency=_zivid.capture_assistant.SuggestSettingsParameters.AmbientLightFrequency().value, - max_capture_time=_zivid.capture_assistant.SuggestSettingsParameters.MaxCaptureTime().value, + ambient_light_frequency: str = _zivid.capture_assistant.SuggestSettingsParameters.AmbientLightFrequency().value, + max_capture_time: datetime.timedelta = _zivid.capture_assistant.SuggestSettingsParameters.MaxCaptureTime().value, ): if isinstance( diff --git a/modules/zivid/application.py b/modules/zivid/application.py index 2c2a467e..4d09be89 100644 --- a/modules/zivid/application.py +++ b/modules/zivid/application.py @@ -1,8 +1,10 @@ """Contains Application class.""" +from __future__ import annotations + import _zivid from zivid.camera import Camera -from zivid.camera_address import _to_internal_camera_address +from zivid.camera_address import CameraAddress, _to_internal_camera_address class Application: @@ -47,7 +49,7 @@ def __init__(self, cuda_context=None): def __str__(self): return str(self.__impl) - def create_file_camera(self, frame): + def create_file_camera(self, frame) -> Camera: """Create a virtual camera from a captured frame or a .zfc file. A file camera is a virtual camera that replays a previously captured frame. It holds the raw sensor @@ -96,7 +98,7 @@ def create_file_camera(self, frame): return Camera(self.__impl.create_file_camera(frame._Frame__impl)) return Camera(self.__impl.create_file_camera(str(frame))) - def connect_camera(self, serial_number=None, address=None): + def connect_camera(self, serial_number: str | None = None, address: CameraAddress | None = None) -> Camera: """Connect to the next available Zivid camera. Args: @@ -118,7 +120,7 @@ def connect_camera(self, serial_number=None, address=None): return Camera(self.__impl.connect_camera(serial_number)) return Camera(self.__impl.connect_camera()) - def cameras(self): + def cameras(self) -> list[Camera]: """Get a list of all cameras. Returns: diff --git a/modules/zivid/bounding_box.py b/modules/zivid/bounding_box.py index d41791d1..bdcfd543 100644 --- a/modules/zivid/bounding_box.py +++ b/modules/zivid/bounding_box.py @@ -1,12 +1,14 @@ """Contains BoundingBox class.""" +from __future__ import annotations + import _zivid class BoundingBox: """Defines a 2D rectangular bounding box in image coordinates.""" - def __init__(self, x, y, width, height): + def __init__(self, x: int, y: int, width: int, height: int): """Construct a BoundingBox object. Args: @@ -18,7 +20,7 @@ def __init__(self, x, y, width, height): self.__impl = _zivid.BoundingBox(x, y, width, height) @property - def x(self): + def x(self) -> int: """Get the top-left corner x coordinate. Returns: @@ -27,7 +29,7 @@ def x(self): return self.__impl.x @x.setter - def x(self, value): + def x(self, value: int) -> None: """Set the top-left corner x coordinate. Args: @@ -36,7 +38,7 @@ def x(self, value): self.__impl.x = value @property - def y(self): + def y(self) -> int: """Get the top-left corner y coordinate. Returns: @@ -45,7 +47,7 @@ def y(self): return self.__impl.y @y.setter - def y(self, value): + def y(self, value: int) -> None: """Set the top-left corner y coordinate. Args: @@ -54,7 +56,7 @@ def y(self, value): self.__impl.y = value @property - def width(self): + def width(self) -> int: """Get the width of the bounding box. Returns: @@ -63,7 +65,7 @@ def width(self): return self.__impl.width @width.setter - def width(self, value): + def width(self, value: int) -> None: """Set the width of the bounding box. Args: @@ -72,7 +74,7 @@ def width(self, value): self.__impl.width = value @property - def height(self): + def height(self) -> int: """Get the height of the bounding box. Returns: @@ -81,7 +83,7 @@ def height(self): return self.__impl.height @height.setter - def height(self, value): + def height(self, value: int) -> None: """Set the height of the bounding box. Args: diff --git a/modules/zivid/camera.py b/modules/zivid/camera.py index a6ef5ebb..d6dfe49a 100644 --- a/modules/zivid/camera.py +++ b/modules/zivid/camera.py @@ -1,9 +1,11 @@ """Contains Camera class.""" +from __future__ import annotations + import _zivid -from zivid.camera_health import _to_camera_health -from zivid.camera_info import _to_camera_info -from zivid.camera_state import _to_camera_state +from zivid.camera_health import CameraHealth, _to_camera_health +from zivid.camera_info import CameraInfo, _to_camera_info +from zivid.camera_state import CameraState, _to_camera_state from zivid.frame import Frame from zivid.frame_2d import Frame2D from zivid.network_configuration import ( @@ -11,7 +13,7 @@ _to_internal_network_configuration, _to_network_configuration, ) -from zivid.scene_conditions import _to_scene_conditions +from zivid.scene_conditions import SceneConditions, _to_scene_conditions from zivid.settings import Settings, _to_internal_settings from zivid.settings2d import Settings2D, _to_internal_settings2d @@ -45,7 +47,7 @@ def __str__(self): def __eq__(self, other): return self.__impl == other._Camera__impl - def capture_2d_3d(self, settings): + def capture_2d_3d(self, settings: Settings) -> Frame: """Capture a 2D+3D frame. This method captures both a 3D point cloud and a 2D color image. Use this method when you want to capture @@ -97,7 +99,7 @@ def capture_2d_3d(self, settings): ) return Frame(self.__impl.capture_2d_3d(_to_internal_settings(settings))) - def capture_3d(self, settings): + def capture_3d(self, settings: Settings) -> Frame: """Capture a single 3D frame. This method is used to capture a 3D frame without a 2D color image. It ignores all color settings in the input @@ -122,7 +124,7 @@ def capture_3d(self, settings): ) return Frame(self.__impl.capture_3d(_to_internal_settings(settings))) - def capture_2d(self, settings): + def capture_2d(self, settings: Settings | Settings2D) -> Frame2D: """Capture a single 2D frame. This method returns right after the acquisition of the images is complete, and the camera has stopped projecting @@ -151,7 +153,7 @@ def capture_2d(self, settings): ) ) - def capture(self, settings): + def capture(self, settings: Settings | Settings2D) -> Frame | Frame2D: """Capture a single frame or a single 2D frame. This method is deprecated as of SDK 2.14, and will be removed in the next SDK major version (3.0). Use @@ -181,7 +183,7 @@ def capture(self, settings): ) @property - def info(self): + def info(self) -> CameraInfo: """Get information about camera model, serial number etc. Returns: @@ -189,7 +191,7 @@ def info(self): """ return _to_camera_info(self.__impl.info) - def check_health(self): + def check_health(self) -> CameraHealth: """Run health checks on the camera and return a severity report. The returned CameraHealth contains an aggregated overall severity, along with the severity of each @@ -206,7 +208,7 @@ def check_health(self): return _to_camera_health(self.__impl.check_health()) @property - def state(self): + def state(self) -> CameraState: """Get the current camera state. Returns: @@ -214,7 +216,7 @@ def state(self): """ return _to_camera_state(self.__impl.state) - def connect(self): + def connect(self) -> Camera: """Connect to the camera. Returns: @@ -223,12 +225,12 @@ def connect(self): self.__impl.connect() return self - def disconnect(self): + def disconnect(self) -> None: """Disconnect from the camera and free all resources associated with it.""" self.__impl.disconnect() @property - def network_configuration(self): + def network_configuration(self) -> NetworkConfiguration: """Get the network configuration of the camera. Returns: @@ -236,7 +238,7 @@ def network_configuration(self): """ return _to_network_configuration(self.__impl.network_configuration) - def apply_network_configuration(self, network_configuration): + def apply_network_configuration(self, network_configuration: NetworkConfiguration) -> None: """Apply the network configuration to the camera. Args: @@ -270,7 +272,7 @@ def apply_network_configuration(self, network_configuration): ) self.__impl.apply_network_configuration(_to_internal_network_configuration(network_configuration)) - def write_user_data(self, user_data): + def write_user_data(self, user_data: bytes) -> None: """Write user data to camera. The total number of writes supported depends on camera model and size of data. Args: @@ -286,7 +288,7 @@ def write_user_data(self, user_data): self.__impl.write_user_data(list(user_data)) @property - def user_data(self): + def user_data(self) -> bytes: """Read user data from camera. Returns: @@ -294,7 +296,7 @@ def user_data(self): """ return bytes(self.__impl.user_data) - def release(self): + def release(self) -> None: """Release the underlying resources.""" try: impl = self.__impl @@ -303,7 +305,7 @@ def release(self): else: impl.release() - def measure_scene_conditions(self): + def measure_scene_conditions(self) -> SceneConditions: """Measure and analyze the conditions of the scene. The returned value will report if noticeable ambient light flicker indicative of a 50 Hz or 60 Hz power grid diff --git a/modules/zivid/camera_address.py b/modules/zivid/camera_address.py index ee12770c..940a15da 100644 --- a/modules/zivid/camera_address.py +++ b/modules/zivid/camera_address.py @@ -1,5 +1,7 @@ """Contains the CameraAddress class.""" +from __future__ import annotations + import _zivid @@ -10,7 +12,7 @@ class CameraAddress: Accepts either an IPv4 address string (e.g. "172.28.60.5") or a resolvable hostname. """ - def __init__(self, value): + def __init__(self, value: str): """Construct a CameraAddress from a hostname or IPv4 address string. Args: @@ -25,7 +27,7 @@ def __init__(self, value): self.__impl = _zivid.CameraAddress(value) @property - def value(self): + def value(self) -> str: """Get the address value. Returns: diff --git a/modules/zivid/camera_health.py b/modules/zivid/camera_health.py index 9720eb68..492b28f9 100644 --- a/modules/zivid/camera_health.py +++ b/modules/zivid/camera_health.py @@ -1,5 +1,7 @@ """Auto generated, do not edit.""" +from __future__ import annotations + # pylint: disable=too-many-lines,protected-access,too-few-public-methods,too-many-arguments,too-many-positional-arguments,line-too-long,missing-function-docstring,missing-class-docstring,redefined-builtin,too-many-branches,too-many-boolean-expressions import datetime @@ -44,8 +46,8 @@ def valid_values(cls): def __init__( self, - status=_zivid.CameraHealth.Fan.Status().value, - value=_zivid.CameraHealth.Fan.Value().value, + status: str = _zivid.CameraHealth.Fan.Status().value, + value: str | None = _zivid.CameraHealth.Fan.Value().value, ): if isinstance(status, _zivid.CameraHealth.Fan.Status.enum): @@ -132,8 +134,8 @@ def valid_values(cls): def __init__( self, - status=_zivid.CameraHealth.InfieldVerification.Status().value, - value=_zivid.CameraHealth.InfieldVerification.Value().value, + status: str = _zivid.CameraHealth.InfieldVerification.Status().value, + value: datetime.datetime | None = _zivid.CameraHealth.InfieldVerification.Value().value, ): if isinstance(status, _zivid.CameraHealth.InfieldVerification.Status.enum): @@ -215,8 +217,8 @@ def valid_values(cls): def __init__( self, - status=_zivid.CameraHealth.MaxTransferSpeed.Status().value, - value=_zivid.CameraHealth.MaxTransferSpeed.Value().value, + status: str = _zivid.CameraHealth.MaxTransferSpeed.Status().value, + value: int | None = _zivid.CameraHealth.MaxTransferSpeed.Value().value, ): if isinstance(status, _zivid.CameraHealth.MaxTransferSpeed.Status.enum): @@ -294,8 +296,8 @@ def valid_values(cls): def __init__( self, - status=_zivid.CameraHealth.Memory.Status().value, - value=_zivid.CameraHealth.Memory.Value().value, + status: str = _zivid.CameraHealth.Memory.Status().value, + value: int | None = _zivid.CameraHealth.Memory.Value().value, ): if isinstance(status, _zivid.CameraHealth.Memory.Status.enum): @@ -375,8 +377,8 @@ def valid_values(cls): def __init__( self, - status=_zivid.CameraHealth.Temperature.DMD.Status().value, - value=_zivid.CameraHealth.Temperature.DMD.Value().value, + status: str = _zivid.CameraHealth.Temperature.DMD.Status().value, + value: float | int | None = _zivid.CameraHealth.Temperature.DMD.Value().value, ): if isinstance(status, _zivid.CameraHealth.Temperature.DMD.Status.enum): @@ -476,8 +478,8 @@ def valid_values(cls): def __init__( self, - status=_zivid.CameraHealth.Temperature.LED.Status().value, - value=_zivid.CameraHealth.Temperature.LED.Value().value, + status: str = _zivid.CameraHealth.Temperature.LED.Status().value, + value: float | int | None = _zivid.CameraHealth.Temperature.LED.Value().value, ): if isinstance(status, _zivid.CameraHealth.Temperature.LED.Status.enum): @@ -577,8 +579,8 @@ def valid_values(cls): def __init__( self, - status=_zivid.CameraHealth.Temperature.Lens.Status().value, - value=_zivid.CameraHealth.Temperature.Lens.Value().value, + status: str = _zivid.CameraHealth.Temperature.Lens.Status().value, + value: float | int | None = _zivid.CameraHealth.Temperature.Lens.Value().value, ): if isinstance(status, _zivid.CameraHealth.Temperature.Lens.Status.enum): @@ -658,9 +660,9 @@ def __str__(self): def __init__( self, - dmd=None, - led=None, - lens=None, + dmd: CameraHealth.Temperature.DMD | None = None, + led: CameraHealth.Temperature.LED | None = None, + lens: CameraHealth.Temperature.Lens | None = None, ): if dmd is None: @@ -739,12 +741,12 @@ def valid_values(cls): def __init__( self, - overall=_zivid.CameraHealth.Overall().value, - fan=None, - infield_verification=None, - max_transfer_speed=None, - memory=None, - temperature=None, + overall: str = _zivid.CameraHealth.Overall().value, + fan: CameraHealth.Fan | None = None, + infield_verification: CameraHealth.InfieldVerification | None = None, + max_transfer_speed: CameraHealth.MaxTransferSpeed | None = None, + memory: CameraHealth.Memory | None = None, + temperature: CameraHealth.Temperature | None = None, ): if isinstance(overall, _zivid.CameraHealth.Overall.enum): diff --git a/modules/zivid/camera_info.py b/modules/zivid/camera_info.py index f5e62625..737de89b 100644 --- a/modules/zivid/camera_info.py +++ b/modules/zivid/camera_info.py @@ -1,5 +1,7 @@ """Auto generated, do not edit.""" +from __future__ import annotations + # pylint: disable=too-many-lines,protected-access,too-few-public-methods,too-many-arguments,too-many-positional-arguments,line-too-long,missing-function-docstring,missing-class-docstring,redefined-builtin,too-many-branches,too-many-boolean-expressions import _zivid @@ -10,8 +12,8 @@ class Revision: def __init__( self, - major=_zivid.CameraInfo.Revision.Major().value, - minor=_zivid.CameraInfo.Revision.Minor().value, + major: int = _zivid.CameraInfo.Revision.Major().value, + minor: int = _zivid.CameraInfo.Revision.Minor().value, ): if isinstance(major, (int,)): @@ -58,7 +60,7 @@ class UserData: def __init__( self, - max_size_bytes=_zivid.CameraInfo.UserData.MaxSizeBytes().value, + max_size_bytes: int = _zivid.CameraInfo.UserData.MaxSizeBytes().value, ): if isinstance(max_size_bytes, (int,)): @@ -123,13 +125,13 @@ def valid_values(cls): def __init__( self, - firmware_version=_zivid.CameraInfo.FirmwareVersion().value, - hardware_revision=_zivid.CameraInfo.HardwareRevision().value, - model=_zivid.CameraInfo.Model().value, - model_name=_zivid.CameraInfo.ModelName().value, - serial_number=_zivid.CameraInfo.SerialNumber().value, - revision=None, - user_data=None, + firmware_version: str = _zivid.CameraInfo.FirmwareVersion().value, + hardware_revision: str = _zivid.CameraInfo.HardwareRevision().value, + model: str = _zivid.CameraInfo.Model().value, + model_name: str = _zivid.CameraInfo.ModelName().value, + serial_number: str = _zivid.CameraInfo.SerialNumber().value, + revision: CameraInfo.Revision | None = None, + user_data: CameraInfo.UserData | None = None, ): if isinstance(firmware_version, (str,)): diff --git a/modules/zivid/camera_intrinsics.py b/modules/zivid/camera_intrinsics.py index 84600f80..0561eda6 100644 --- a/modules/zivid/camera_intrinsics.py +++ b/modules/zivid/camera_intrinsics.py @@ -1,5 +1,7 @@ """Auto generated, do not edit.""" +from __future__ import annotations + # pylint: disable=too-many-lines,protected-access,too-few-public-methods,too-many-arguments,too-many-positional-arguments,line-too-long,missing-function-docstring,missing-class-docstring,redefined-builtin,too-many-branches,too-many-boolean-expressions import _zivid @@ -10,10 +12,10 @@ class CameraMatrix: def __init__( self, - cx=_zivid.CameraIntrinsics.CameraMatrix.CX().value, - cy=_zivid.CameraIntrinsics.CameraMatrix.CY().value, - fx=_zivid.CameraIntrinsics.CameraMatrix.FX().value, - fy=_zivid.CameraIntrinsics.CameraMatrix.FY().value, + cx: float | int = _zivid.CameraIntrinsics.CameraMatrix.CX().value, + cy: float | int = _zivid.CameraIntrinsics.CameraMatrix.CY().value, + fx: float | int = _zivid.CameraIntrinsics.CameraMatrix.FX().value, + fy: float | int = _zivid.CameraIntrinsics.CameraMatrix.FY().value, ): if isinstance( @@ -156,11 +158,11 @@ class Distortion: def __init__( self, - k1=_zivid.CameraIntrinsics.Distortion.K1().value, - k2=_zivid.CameraIntrinsics.Distortion.K2().value, - k3=_zivid.CameraIntrinsics.Distortion.K3().value, - p1=_zivid.CameraIntrinsics.Distortion.P1().value, - p2=_zivid.CameraIntrinsics.Distortion.P2().value, + k1: float | int = _zivid.CameraIntrinsics.Distortion.K1().value, + k2: float | int = _zivid.CameraIntrinsics.Distortion.K2().value, + k3: float | int = _zivid.CameraIntrinsics.Distortion.K3().value, + p1: float | int = _zivid.CameraIntrinsics.Distortion.P1().value, + p2: float | int = _zivid.CameraIntrinsics.Distortion.P2().value, ): if isinstance( @@ -339,8 +341,8 @@ def __str__(self): def __init__( self, - camera_matrix=None, - distortion=None, + camera_matrix: CameraIntrinsics.CameraMatrix | None = None, + distortion: CameraIntrinsics.Distortion | None = None, ): if camera_matrix is None: diff --git a/modules/zivid/camera_state.py b/modules/zivid/camera_state.py index 84972548..50d6cd6a 100644 --- a/modules/zivid/camera_state.py +++ b/modules/zivid/camera_state.py @@ -1,5 +1,7 @@ """Auto generated, do not edit.""" +from __future__ import annotations + # pylint: disable=too-many-lines,protected-access,too-few-public-methods,too-many-arguments,too-many-positional-arguments,line-too-long,missing-function-docstring,missing-class-docstring,redefined-builtin,too-many-branches,too-many-boolean-expressions import collections.abc @@ -40,7 +42,7 @@ def valid_values(cls): def __init__( self, - link_speed=_zivid.CameraState.Network.LocalInterface.Ethernet.LinkSpeed().value, + link_speed: str = _zivid.CameraState.Network.LocalInterface.Ethernet.LinkSpeed().value, ): if isinstance(link_speed, _zivid.CameraState.Network.LocalInterface.Ethernet.LinkSpeed.enum): @@ -90,8 +92,8 @@ class Subnet: def __init__( self, - address=_zivid.CameraState.Network.LocalInterface.IPV4.Subnet.Address().value, - mask=_zivid.CameraState.Network.LocalInterface.IPV4.Subnet.Mask().value, + address: str = _zivid.CameraState.Network.LocalInterface.IPV4.Subnet.Address().value, + mask: str = _zivid.CameraState.Network.LocalInterface.IPV4.Subnet.Mask().value, ): if isinstance(address, (str,)): @@ -188,9 +190,9 @@ def __str__(self): def __init__( self, - interface_name=_zivid.CameraState.Network.LocalInterface.InterfaceName().value, - ethernet=None, - ipv4=None, + interface_name: str = _zivid.CameraState.Network.LocalInterface.InterfaceName().value, + ethernet: CameraState.Network.LocalInterface.Ethernet | None = None, + ipv4: CameraState.Network.LocalInterface.IPV4 | None = None, ): if isinstance(interface_name, (str,)): @@ -283,7 +285,7 @@ def valid_values(cls): def __init__( self, - link_speed=_zivid.CameraState.Network.Ethernet.LinkSpeed().value, + link_speed: str = _zivid.CameraState.Network.Ethernet.LinkSpeed().value, ): if isinstance(link_speed, _zivid.CameraState.Network.Ethernet.LinkSpeed.enum): @@ -329,7 +331,7 @@ class IPV4: def __init__( self, - address=_zivid.CameraState.Network.IPV4.Address().value, + address: str = _zivid.CameraState.Network.IPV4.Address().value, ): if isinstance(address, (str,)): @@ -361,8 +363,8 @@ def __str__(self): def __init__( self, local_interfaces=None, - ethernet=None, - ipv4=None, + ethernet: CameraState.Network.Ethernet | None = None, + ipv4: CameraState.Network.IPV4 | None = None, ): if local_interfaces is None: @@ -444,11 +446,11 @@ class Temperature: def __init__( self, - dmd=_zivid.CameraState.Temperature.DMD().value, - general=_zivid.CameraState.Temperature.General().value, - led=_zivid.CameraState.Temperature.LED().value, - lens=_zivid.CameraState.Temperature.Lens().value, - pcb=_zivid.CameraState.Temperature.PCB().value, + dmd: float | int = _zivid.CameraState.Temperature.DMD().value, + general: float | int = _zivid.CameraState.Temperature.General().value, + led: float | int = _zivid.CameraState.Temperature.LED().value, + lens: float | int = _zivid.CameraState.Temperature.Lens().value, + pcb: float | int = _zivid.CameraState.Temperature.PCB().value, ): if isinstance( @@ -675,12 +677,12 @@ def valid_values(cls): def __init__( self, - available=_zivid.CameraState.Available().value, - connected=_zivid.CameraState.Connected().value, - inaccessible_reason=_zivid.CameraState.InaccessibleReason().value, - status=_zivid.CameraState.Status().value, - network=None, - temperature=None, + available: bool = _zivid.CameraState.Available().value, + connected: bool = _zivid.CameraState.Connected().value, + inaccessible_reason: str | None = _zivid.CameraState.InaccessibleReason().value, + status: str = _zivid.CameraState.Status().value, + network: CameraState.Network | None = None, + temperature: CameraState.Temperature | None = None, ): if isinstance(available, (bool,)): diff --git a/modules/zivid/capture_assistant.py b/modules/zivid/capture_assistant.py index 77f4048a..00c830f6 100644 --- a/modules/zivid/capture_assistant.py +++ b/modules/zivid/capture_assistant.py @@ -1,12 +1,17 @@ """Contains the Capture Assistant functionality.""" +from __future__ import annotations + import _zivid -from zivid._suggest_settings_parameters import SuggestSettingsParameters # pylint: disable=unused-import # noqa: F401 -from zivid._suggest_settings_parameters import _to_internal_capture_assistant_suggest_settings_parameters -from zivid.settings import _to_settings +from zivid._suggest_settings_parameters import ( + SuggestSettingsParameters, + _to_internal_capture_assistant_suggest_settings_parameters, +) +from zivid.camera import Camera +from zivid.settings import Settings, _to_settings -def suggest_settings(camera, suggest_settings_parameters): +def suggest_settings(camera: Camera, suggest_settings_parameters: SuggestSettingsParameters) -> Settings: """Find settings for the current scene based on given parameters. The suggested settings returned from this function should be passed into diff --git a/modules/zivid/device_array.py b/modules/zivid/device_array.py index 355fe9ff..968356bf 100644 --- a/modules/zivid/device_array.py +++ b/modules/zivid/device_array.py @@ -1,5 +1,7 @@ """Contains the DeviceArray class.""" +from __future__ import annotations + import _zivid import numpy @@ -87,7 +89,7 @@ def _impl(self): return self.__impl @property - def shape(self): + def shape(self) -> tuple: """Get the shape of the device array. Returns: @@ -96,7 +98,7 @@ def shape(self): return self.__impl.shape @property - def strides(self): + def strides(self) -> tuple: """Get the strides of the device array in element count. Returns: @@ -105,7 +107,7 @@ def strides(self): return self.__impl.strides @property - def strides_in_bytes(self): + def strides_in_bytes(self) -> tuple: """Get the strides of the device array in bytes. Returns: @@ -114,7 +116,7 @@ def strides_in_bytes(self): return self.__impl.strides_in_bytes @property - def size_bytes(self): + def size_bytes(self) -> int: """Get the size of the device array in bytes. Returns: @@ -132,7 +134,7 @@ def backend(self): return self.__impl.backend @property - def is_valid(self): + def is_valid(self) -> bool: """Check if the device array is valid. Returns: @@ -141,7 +143,7 @@ def is_valid(self): return self.__impl.is_valid @property - def is_empty(self): + def is_empty(self) -> bool: """Check if the device array is empty. Returns: @@ -149,7 +151,7 @@ def is_empty(self): """ return self.__impl.is_empty - def device_pointer(self): + def device_pointer(self) -> int: """Get the raw device pointer for the array data. No synchronization is performed. The DeviceArray was already synchronized against the @@ -198,7 +200,7 @@ def __cuda_array_interface__(self): "version": 3, } - def copy_to_host_organized_array(self, stream_or_queue): + def copy_to_host_organized_array(self, stream_or_queue) -> numpy.ndarray: """Enqueue a device-to-host copy and return a numpy array WITHOUT synchronizing. Use this for device arrays obtained from organized point clouds, or from 2D frames. @@ -240,7 +242,7 @@ def copy_to_host_organized_array(self, stream_or_queue): " or 2D frames." ) from e - def copy_to_host_unorganized_array(self, stream_or_queue): + def copy_to_host_unorganized_array(self, stream_or_queue) -> numpy.ndarray: """Enqueue a device-to-host copy and return a numpy array WITHOUT synchronizing. Use this for device arrays obtained from unorganized point clouds. diff --git a/modules/zivid/device_array_view.py b/modules/zivid/device_array_view.py index ea954f17..5e8a2d59 100644 --- a/modules/zivid/device_array_view.py +++ b/modules/zivid/device_array_view.py @@ -1,5 +1,7 @@ """Contains the DeviceArrayView class and the create_device_array_view factory.""" +from __future__ import annotations + import _zivid import numpy from zivid.device_array import _require_stream_or_queue @@ -51,22 +53,22 @@ def _impl(self): return self.__impl @property - def shape(self): + def shape(self) -> tuple: """Tuple of view dimensions.""" return self.__impl.shape @property - def strides(self): + def strides(self) -> tuple: """Tuple of view strides in element count.""" return self.__impl.strides @property - def strides_in_bytes(self): + def strides_in_bytes(self) -> tuple: """Tuple of view strides in bytes.""" return self.__impl.strides_in_bytes @property - def size_bytes(self): + def size_bytes(self) -> int: """Size of the view in bytes.""" return self.__impl.size_bytes @@ -76,16 +78,16 @@ def backend(self): return self.__impl.backend @property - def is_valid(self): + def is_valid(self) -> bool: """True if the view is valid (not empty).""" return self.__impl.is_valid @property - def is_empty(self): + def is_empty(self) -> bool: """True if the view is empty.""" return self.__impl.is_empty - def device_pointer(self): + def device_pointer(self) -> int: """Get the raw device pointer to the viewed memory. Returns: @@ -94,7 +96,7 @@ def device_pointer(self): """ return self.__impl.device_pointer() - def copy_to_host_organized_array(self, stream_or_queue): + def copy_to_host_organized_array(self, stream_or_queue) -> numpy.ndarray: """Enqueue a device-to-host copy and return a numpy array WITHOUT synchronizing. Only available for color views. The D2H copy is enqueued on ``stream_or_queue`` and this @@ -144,7 +146,7 @@ def _device_array_view_fill_target(destination_buffer, supported): return suffix, impl -def create_device_array_view(cuda_array, user_stream, color_format): +def create_device_array_view(cuda_array, user_stream, color_format: PixelFormat) -> DeviceArrayView: """Wrap a caller-owned CUDA array as a non-owning Zivid DeviceArrayView. ``cuda_array`` is any object exposing the CUDA Array Interface (``__cuda_array_interface__``) — diff --git a/modules/zivid/experimental/_pixel_mapping.py b/modules/zivid/experimental/_pixel_mapping.py index 50f0e971..826df01b 100644 --- a/modules/zivid/experimental/_pixel_mapping.py +++ b/modules/zivid/experimental/_pixel_mapping.py @@ -1,5 +1,7 @@ """Module for experimental pixel mapping. This API may change in the future.""" +from __future__ import annotations + import _zivid @@ -9,23 +11,23 @@ class PixelMapping: Required when mapping an index in a subsampled point cloud to e.g. a full resolution 2D image. """ - def __init__(self, row_stride=1, col_stride=1, row_offset=0.0, col_offset=0.0): + def __init__(self, row_stride: int = 1, col_stride: int = 1, row_offset: float = 0.0, col_offset: float = 0.0): self.__impl = _zivid.PixelMapping(row_stride, col_stride, row_offset, col_offset) @property - def row_stride(self): + def row_stride(self) -> int: return self.__impl.row_stride() @property - def col_stride(self): + def col_stride(self) -> int: return self.__impl.col_stride() @property - def row_offset(self): + def row_offset(self) -> float: return self.__impl.row_offset() @property - def col_offset(self): + def col_offset(self) -> float: return self.__impl.col_offset() def __str__(self): diff --git a/modules/zivid/experimental/calibration.py b/modules/zivid/experimental/calibration.py index e5ec8710..2d6178a8 100644 --- a/modules/zivid/experimental/calibration.py +++ b/modules/zivid/experimental/calibration.py @@ -1,13 +1,17 @@ """Module for experimental calibration features. This API may change in the future.""" +from __future__ import annotations + import _zivid -from zivid.camera_intrinsics import _to_camera_intrinsics +from zivid.camera import Camera +from zivid.camera_intrinsics import CameraIntrinsics, _to_camera_intrinsics from zivid.experimental import PixelMapping +from zivid.frame import Frame from zivid.settings import Settings, _to_internal_settings from zivid.settings2d import Settings2D, _to_internal_settings2d -def intrinsics(camera, settings=None): +def intrinsics(camera: Camera, settings: Settings | Settings2D | None = None) -> CameraIntrinsics: """Get intrinsic parameters of a given camera and settings (3D or 2D). These intrinsic parameters take into account the expected resolution of the point clouds captured @@ -52,7 +56,7 @@ def intrinsics(camera, settings=None): ) -def estimate_intrinsics(frame): +def estimate_intrinsics(frame: Frame) -> CameraIntrinsics: """Estimate camera intrinsics for a given frame. The estimated parameters may be used to project 3D point cloud onto the corresponding 2D image. @@ -73,7 +77,7 @@ def estimate_intrinsics(frame): ) -def pixel_mapping(camera, settings): +def pixel_mapping(camera: Camera, settings: Settings) -> PixelMapping: """Return pixel mapping information given camera and settings. When mapping from a subsampled point cloud to a full resolution diff --git a/modules/zivid/experimental/hand_eye_low_dof.py b/modules/zivid/experimental/hand_eye_low_dof.py index 4203bdfd..911555f9 100644 --- a/modules/zivid/experimental/hand_eye_low_dof.py +++ b/modules/zivid/experimental/hand_eye_low_dof.py @@ -3,6 +3,8 @@ This API may change in the future. """ +from __future__ import annotations + import collections.abc import _zivid @@ -12,7 +14,7 @@ class FixedPlacementOfFiducialMarker: """Specifies the fixed placement of a fiducial marker for low degrees-of-freedom hand-eye calibration.""" - def __init__(self, marker_id, position): + def __init__(self, marker_id: int, position: list): """Construct a FixedPlacementOfFiducialMarker. For eye-in-hand calibration, positions should be given in the robot's base frame. For eye-to-hand calibration, @@ -46,7 +48,7 @@ def __init__(self, marker_id, position): ) @property - def id(self): + def id(self) -> int: """Get ID of fiducial marker. Returns: @@ -55,7 +57,7 @@ def id(self): return self.__impl.id @property - def position(self): + def position(self) -> list: """Get position of fiducial marker. Returns: @@ -70,7 +72,7 @@ def __str__(self): class FixedPlacementOfFiducialMarkers: # pylint: disable=too-few-public-methods """Specifies the fixed placement of a list of fiducial markers for low degrees-of-freedom hand-eye calibration.""" - def __init__(self, marker_dictionary, markers): + def __init__(self, marker_dictionary: str, markers: list): """Construct a FixedPlacementOfFiducialMarkers instance. Args: @@ -111,7 +113,7 @@ def __str__(self): class FixedPlacementOfCalibrationBoard: # pylint: disable=too-few-public-methods """Specifies the fixed placement of a Zivid calibration board for low degrees-of-freedom hand-eye calibration.""" - def __init__(self, position_or_pose): + def __init__(self, position_or_pose: Pose | list): """Construct a FixedPlacementOfCalibrationBoard instance. For eye-in-hand calibration, the position or pose should be given in the robot's base frame. For eye-to-hand @@ -153,7 +155,7 @@ def __str__(self): class FixedPlacementOfCalibrationObjects: # pylint: disable=too-few-public-methods """Specifies the fixed placement of calibration objects for low degrees-of-freedom hand-eye calibration.""" - def __init__(self, fixed_objects): + def __init__(self, fixed_objects: FixedPlacementOfFiducialMarkers | FixedPlacementOfCalibrationBoard): """Construct a FixedPlacementOfCalibrationObjects instance from fiducial markers or a calibration board. Args: @@ -183,7 +185,9 @@ def __str__(self): return str(self.__impl) -def calibrate_eye_in_hand_low_dof(calibration_inputs, fixed_objects): +def calibrate_eye_in_hand_low_dof( + calibration_inputs: list, fixed_objects: FixedPlacementOfCalibrationObjects +) -> HandEyeOutput: """Perform eye-in-hand calibration for low degrees-of-freedom robots. For robots with low degrees-of-freedom (DOF), that is, less than 6 DOF, the robot pose and capture inputs are not @@ -217,7 +221,9 @@ def calibrate_eye_in_hand_low_dof(calibration_inputs, fixed_objects): ) -def calibrate_eye_to_hand_low_dof(calibration_inputs, fixed_objects): +def calibrate_eye_to_hand_low_dof( + calibration_inputs: list, fixed_objects: FixedPlacementOfCalibrationObjects +) -> HandEyeOutput: """Perform eye-to-hand calibration for low degrees-of-freedom robots. For robots with low degrees-of-freedom (DOF), that is, less than 6 DOF, the robot pose and capture inputs are not diff --git a/modules/zivid/experimental/point_cloud_export/_export_frame.py b/modules/zivid/experimental/point_cloud_export/_export_frame.py index 6561e993..b36af72a 100644 --- a/modules/zivid/experimental/point_cloud_export/_export_frame.py +++ b/modules/zivid/experimental/point_cloud_export/_export_frame.py @@ -1,9 +1,11 @@ +from __future__ import annotations + import _zivid from zivid.experimental.point_cloud_export.file_format import PCD, PLY, XYZ, ZDF from zivid.frame import Frame -def export_frame(frame, file_format): +def export_frame(frame: Frame, file_format: PCD | PLY | XYZ | ZDF) -> None: """Save frame to a file. The file format is specified by the file_format argument. The file format can be ZDF, PLY, XYZ, diff --git a/modules/zivid/experimental/point_cloud_export/_export_unorganized_point_cloud.py b/modules/zivid/experimental/point_cloud_export/_export_unorganized_point_cloud.py index 4f0f835b..b371a9ba 100644 --- a/modules/zivid/experimental/point_cloud_export/_export_unorganized_point_cloud.py +++ b/modules/zivid/experimental/point_cloud_export/_export_unorganized_point_cloud.py @@ -1,9 +1,13 @@ +from __future__ import annotations + import _zivid from zivid.experimental.point_cloud_export.file_format import PCD, PLY, XYZ from zivid.unorganized_point_cloud import UnorganizedPointCloud -def export_unorganized_point_cloud(unorganized_point_cloud, file_format): +def export_unorganized_point_cloud( + unorganized_point_cloud: UnorganizedPointCloud, file_format: PCD | PLY | XYZ +) -> None: """Save UnorganizedPointCloud to a file. The file format is specified by the file_format argument. The file format can be PLY, XYZ, or diff --git a/modules/zivid/experimental/point_cloud_export/file_format.py b/modules/zivid/experimental/point_cloud_export/file_format.py index 337fb70a..3946cb13 100644 --- a/modules/zivid/experimental/point_cloud_export/file_format.py +++ b/modules/zivid/experimental/point_cloud_export/file_format.py @@ -1,5 +1,7 @@ """Module defining file formats that point cloud data can be exported to.""" +from __future__ import annotations + import _zivid @@ -10,7 +12,7 @@ class ColorSpace: # pylint: disable=too-few-public-methods srgb = "srgb" @staticmethod - def valid_values(): + def valid_values() -> list: """Get valid values for color space. Returns: @@ -34,7 +36,7 @@ class IncludeNormals: # pylint: disable=too-few-public-methods yes = "yes" @staticmethod - def valid_values(): + def valid_values() -> list: """Get valid values for including normals. Returns: @@ -54,7 +56,7 @@ def _to_internal(cls, value): class ZDF: # pylint: disable=too-few-public-methods """Specification for saving frame in ZDF (*.zdf) format.""" - def __init__(self, file_name): + def __init__(self, file_name: str): """Create a ZDF file format specification with file name. Args: @@ -85,7 +87,7 @@ class Layout: unordered = "unordered" @staticmethod - def valid_values(): + def valid_values() -> list: """Get valid values for layout. Returns: @@ -103,10 +105,10 @@ def _to_internal(cls, value): def __init__( self, - file_name, - layout=Layout.ordered, - color_space=ColorSpace.srgb, - include_normals=IncludeNormals.no, + file_name: str, + layout: str = Layout.ordered, + color_space: str = ColorSpace.srgb, + include_normals: str = IncludeNormals.no, ): """Create a PLY file format specification with file name. @@ -148,7 +150,7 @@ class XYZ: # pylint: disable=too-few-public-methods ASCII characters are used to store cartesian coordinates of XYZ points and RGB color values. """ - def __init__(self, file_name, color_space=ColorSpace.srgb): + def __init__(self, file_name: str, color_space: str = ColorSpace.srgb): """Create a XYZ file format specification with file name. Sets color space to linear RGB. @@ -187,7 +189,7 @@ class Layout: unorganized = "unorganized" @staticmethod - def valid_values(): + def valid_values() -> list: """Get valid values for layout. Returns: @@ -204,7 +206,11 @@ def _to_internal(cls, value): raise ValueError("Invalid layout '{}'. Valid layouts are: {}".format(value, cls.valid_values())) def __init__( - self, file_name, color_space=ColorSpace.srgb, include_normals=IncludeNormals.no, layout=Layout.organized + self, + file_name: str, + color_space: str = ColorSpace.srgb, + include_normals: str = IncludeNormals.no, + layout: str = Layout.organized, ): """Create a PCD file format specification with file name. diff --git a/modules/zivid/experimental/toolbox/barcode.py b/modules/zivid/experimental/toolbox/barcode.py index cfdffefd..db818f0b 100644 --- a/modules/zivid/experimental/toolbox/barcode.py +++ b/modules/zivid/experimental/toolbox/barcode.py @@ -1,10 +1,12 @@ """Module for experimental barcode reading. This API may change in the future.""" +from __future__ import annotations + import _zivid from zivid.bounding_box import BoundingBox from zivid.camera import Camera from zivid.frame_2d import Frame2D -from zivid.settings2d import _to_settings2d +from zivid.settings2d import Settings2D, _to_settings2d class LinearBarcodeFormat: @@ -31,7 +33,7 @@ class LinearBarcodeFormat: } @classmethod - def valid_values(cls): + def valid_values(cls) -> dict: """List all valid linear barcode format values.""" return cls._valid_values @@ -48,7 +50,7 @@ class MatrixBarcodeFormat: } @classmethod - def valid_values(cls): + def valid_values(cls) -> dict: """List all valid matrix barcode format values.""" return cls._valid_values @@ -75,11 +77,11 @@ def __init__(self, impl): """Initialize.""" self.__impl = impl - def center_position(self): + def center_position(self) -> tuple: """Position of barcode as tuple of pixel coodinates (x,y).""" return tuple(self.__impl.center_position()) - def bounding_box(self): + def bounding_box(self) -> BoundingBox: """Get the bounding box of the region in the 2D image.""" bb_impl = self.__impl.bounding_box() return BoundingBox(x=bb_impl.x, y=bb_impl.y, width=bb_impl.width, height=bb_impl.height) @@ -118,19 +120,19 @@ def __init__(self, impl): """Initialize.""" self.__impl = impl - def code(self): + def code(self) -> str: """Code as string.""" return self.__impl.code() - def code_format(self): + def code_format(self) -> str: """Code format as string.""" return self.__impl.code_format() - def center_position(self): + def center_position(self) -> tuple: """Position of barcode as tuple of pixel coodinates (x,y).""" return tuple(self.__impl.center_position()) - def bounding_box(self): + def bounding_box(self) -> BoundingBox: """Get the bounding box of the barcode in the 2D image.""" bb_impl = self.__impl.bounding_box() return BoundingBox(x=bb_impl.x, y=bb_impl.y, width=bb_impl.width, height=bb_impl.height) @@ -197,7 +199,7 @@ def __init__(self): """Initialize BarcodeDetector.""" self.__impl = _zivid.toolbox.BarcodeDetector() - def suggest_settings(self, camera): + def suggest_settings(self, camera: Camera) -> Settings2D: """Get 2D capture settings that are ideal for barcode reading with the given camera. Args: @@ -211,7 +213,7 @@ def suggest_settings(self, camera): settings2d_impl = self.__impl.suggest_settings(camera._Camera__impl) # pylint: disable=protected-access return _to_settings2d(settings2d_impl) - def detect_linear_codes(self, frame2d): + def detect_linear_codes(self, frame2d: Frame2D) -> list: """Detect linear (1D) barcode candidate regions based on the result of a 2D capture. This method detects potential barcode regions in the image but does not attempt to decode them. @@ -233,7 +235,7 @@ def detect_linear_codes(self, frame2d): ) return [LinearBarcodeDetectionResult(result) for result in results] - def decode_linear_codes(self, detection_results, format_filter=None): + def decode_linear_codes(self, detection_results: list, format_filter=None) -> list: """Decode linear (1D) barcode candidate regions. This method attempts to decode barcode candidates that were previously detected using @@ -266,7 +268,7 @@ def decode_linear_codes(self, detection_results, format_filter=None): ) return [LinearBarcodeDecodingResult(result) if result is not None else None for result in results] - def read_linear_codes(self, frame2d, format_filter=None): + def read_linear_codes(self, frame2d: Frame2D, format_filter=None) -> list: """Detect and decode linear (1D) barcodes based on the result of a 2D capture. Args: @@ -286,7 +288,7 @@ def read_linear_codes(self, frame2d, format_filter=None): ) return [LinearBarcodeDecodingResult(result) for result in results] - def read_matrix_codes(self, frame2d, format_filter=None): + def read_matrix_codes(self, frame2d: Frame2D, format_filter=None) -> list: """Detect and decode matrix (2D) barcodes based on the result of a 2D capture. Args: @@ -305,7 +307,7 @@ def read_matrix_codes(self, frame2d, format_filter=None): ) return [MatrixBarcodeDecodingResult(result) for result in results] - def release(self): + def release(self) -> None: """Release the underlying resources.""" try: impl = self.__impl diff --git a/modules/zivid/experimental/toolbox/point_cloud_registration.py b/modules/zivid/experimental/toolbox/point_cloud_registration.py index 339c14fd..24e12b84 100644 --- a/modules/zivid/experimental/toolbox/point_cloud_registration.py +++ b/modules/zivid/experimental/toolbox/point_cloud_registration.py @@ -1,6 +1,9 @@ """Module for experimental point cloud registration. This API may change in the future.""" +from __future__ import annotations + import _zivid +import numpy from zivid._local_point_cloud_registration_parameters import ( LocalPointCloudRegistrationParameters, _to_internal_toolbox_local_point_cloud_registration_parameters, @@ -32,7 +35,7 @@ def __init__(self, impl): ) self.__impl = impl - def transform(self): + def transform(self) -> Pose: """The transform that must be applied to the source point cloud for it to align with the target point cloud. Returns: @@ -40,7 +43,7 @@ def transform(self): """ return Pose(self.__impl.transform().to_matrix()) - def converged(self): + def converged(self) -> bool: """A boolean indicating whether the convergence criteria were satisfied before reaching the iteration limit. Returns: @@ -48,7 +51,7 @@ def converged(self): """ return self.__impl.converged() - def source_coverage(self): + def source_coverage(self) -> float: """The fraction of points in the source that has a correspondence in the target after transformation. Returns: @@ -56,7 +59,7 @@ def source_coverage(self): """ return self.__impl.source_coverage() - def root_mean_square_error(self): + def root_mean_square_error(self) -> float: """The root mean squared distance between corresponding points in the source and target after transformation. Returns: @@ -68,7 +71,12 @@ def __str__(self): return str(self.__impl) -def local_point_cloud_registration(target, source, parameters=None, initial_transform=None): +def local_point_cloud_registration( + target: UnorganizedPointCloud, + source: UnorganizedPointCloud, + parameters: LocalPointCloudRegistrationParameters | None = None, + initial_transform: Pose | Matrix4x4 | numpy.ndarray | None = None, +) -> LocalPointCloudRegistrationResult: """Compute alignment transform between two point clouds. Given a `source` point cloud and a `target` point cloud, this function attempts to compute the transform diff --git a/modules/zivid/firmware.py b/modules/zivid/firmware.py index ac4e073d..8006251a 100644 --- a/modules/zivid/firmware.py +++ b/modules/zivid/firmware.py @@ -1,9 +1,12 @@ """Contains functions for checking and updating camera firmware.""" +from __future__ import annotations + import _zivid +from zivid.camera import Camera -def update(camera, progress_callback=None): +def update(camera: Camera, progress_callback=None) -> None: """Update camera firmware. If the current API requires a different firmware than what is present on the camera, @@ -25,7 +28,7 @@ def update(camera, progress_callback=None): ) -def is_up_to_date(camera): +def is_up_to_date(camera: Camera) -> bool: """Check if the firmware on the camera is of the version that is required by the API. Args: diff --git a/modules/zivid/frame.py b/modules/zivid/frame.py index 00a4cb4c..a3fbeb9d 100644 --- a/modules/zivid/frame.py +++ b/modules/zivid/frame.py @@ -1,15 +1,18 @@ """Contains the Frame class.""" +from __future__ import annotations + from pathlib import Path import _zivid -from zivid.camera_info import _to_camera_info -from zivid.camera_state import _to_camera_state +import numpy +from zivid.camera_info import CameraInfo, _to_camera_info +from zivid.camera_state import CameraState, _to_camera_state from zivid.frame_2d import Frame2D -from zivid.frame_info import _to_frame_info +from zivid.frame_info import FrameInfo, _to_frame_info from zivid.mask import Mask, _to_internal_mask from zivid.point_cloud import PointCloud -from zivid.settings import _to_settings +from zivid.settings import Settings, _to_settings class Frame: @@ -43,7 +46,7 @@ def __init__(self, file_name): def __str__(self): return str(self.__impl) - def point_cloud(self): + def point_cloud(self) -> PointCloud: """Get the point cloud. See documentation/functions of zivid.PointCloud for instructions on how to @@ -54,7 +57,7 @@ def point_cloud(self): """ return PointCloud(self.__impl.point_cloud()) - def frame_2d(self): + def frame_2d(self) -> Frame2D | None: """Get 2D frame from 2D+3D frame. If the frame is the result of a 2D+3D capture, this method returns the 2D frame contained in the 2D+3D frame. In @@ -80,7 +83,7 @@ def frame_2d(self): """ return Frame2D(self.__impl.frame_2d()) if self.__impl.frame_2d() is not None else None - def save(self, file_path): + def save(self, file_path: str | Path) -> None: """Save the frame to file. The file type is determined from the file extension. Supported extensions are .zdf, .ply @@ -114,7 +117,7 @@ def save(self, file_path): """ self.__impl.save(str(file_path)) - def load(self, file_path): + def load(self, file_path: str | Path) -> None: """Load a frame from a Zivid data file. Args: @@ -123,7 +126,7 @@ def load(self, file_path): self.__impl.load(str(file_path)) @property - def settings(self): + def settings(self) -> Settings: """Get the settings used to capture this frame. Returns: @@ -132,7 +135,7 @@ def settings(self): return _to_settings(self.__impl.settings) @property - def state(self): + def state(self) -> CameraState: """Get the camera state data at the time of the frame capture. Returns: @@ -141,7 +144,7 @@ def state(self): return _to_camera_state(self.__impl.state) @property - def info(self): + def info(self) -> FrameInfo: """Get information collected at the time of the frame capture. Returns: @@ -150,7 +153,7 @@ def info(self): return _to_frame_info(self.__impl.info) @property - def camera_info(self): + def camera_info(self) -> CameraInfo: """Get information about the camera used to capture the frame. Returns: @@ -158,7 +161,7 @@ def camera_info(self): """ return _to_camera_info(self.__impl.camera_info) - def release(self): + def release(self) -> None: """Release the underlying resources.""" try: impl = self.__impl @@ -167,7 +170,7 @@ def release(self): else: impl.release() - def clone(self): + def clone(self) -> Frame: """Get a clone of the frame. The clone will include a copy of all the point cloud data on the compute device memory. This means that the @@ -184,7 +187,7 @@ def clone(self): """ return Frame(self.__impl.clone()) - def mask(self, mask): + def mask(self, mask: numpy.ndarray | Mask) -> Frame: """Apply a binary mask to the frame's point cloud in-place. The mask indicates which points in the point cloud should be considered invalid (NaN). @@ -208,7 +211,7 @@ def mask(self, mask): self.__impl.mask(_to_internal_mask(mask_obj)) return self - def masked(self, mask): + def masked(self, mask: numpy.ndarray | Mask) -> Frame: """Get a copy of the frame with a binary mask applied to its point cloud. This method is identical to "mask", except the masked frame is diff --git a/modules/zivid/frame_2d.py b/modules/zivid/frame_2d.py index 82e2b885..1238f144 100644 --- a/modules/zivid/frame_2d.py +++ b/modules/zivid/frame_2d.py @@ -1,16 +1,18 @@ """Contains the Frame2D class.""" +from __future__ import annotations + from pathlib import Path import _zivid -from zivid.camera_info import _to_camera_info -from zivid.camera_state import _to_camera_state +from zivid.camera_info import CameraInfo, _to_camera_info +from zivid.camera_state import CameraState, _to_camera_state from zivid.device_array import DeviceArray, _require_stream_or_queue -from zivid.device_array_view import _device_array_view_fill_target -from zivid.frame_info import _to_frame_info +from zivid.device_array_view import DeviceArrayView, _device_array_view_fill_target +from zivid.frame_info import FrameInfo, _to_frame_info from zivid.image import Image from zivid.pixel_format import PixelFormat, _resolve_color_format -from zivid.settings2d import _to_settings2d +from zivid.settings2d import Settings2D, _to_settings2d _COLOR_FORMAT_ACCESSOR_SUFFIX = { PixelFormat.RGBA: "rgba", @@ -70,7 +72,7 @@ def __init__(self, impl): def __str__(self): return str(self.__impl) - def image_rgba(self): + def image_rgba(self) -> Image: """Get color (RGBA) image from the frame. Returns: @@ -78,7 +80,7 @@ def image_rgba(self): """ return Image(self.__impl.image_rgba()) - def image_bgra(self): + def image_bgra(self) -> Image: """Get color (BGRA) image from the frame. Returns: @@ -86,7 +88,7 @@ def image_bgra(self): """ return Image(self.__impl.image_bgra()) - def image_rgba_srgb(self): + def image_rgba_srgb(self) -> Image: """Get color (RGBA) image from the frame in the sRGB color space. Returns: @@ -94,7 +96,7 @@ def image_rgba_srgb(self): """ return Image(self.__impl.image_rgba_srgb()) - def image_bgra_srgb(self): + def image_bgra_srgb(self) -> Image: """Get color (BGRA) image from the frame in the sRGB color space. Returns: @@ -102,26 +104,26 @@ def image_bgra_srgb(self): """ return Image(self.__impl.image_bgra_srgb()) - def image_rgb(self): + def image_rgb(self) -> Image: """Get color (RGB, 3-channel, no alpha) image from the frame. Identical to :py:meth:`image_rgba` but skips the alpha channel for ~25% bandwidth savings. """ return Image(self.__impl.image_rgb()) - def image_rgb_srgb(self): + def image_rgb_srgb(self) -> Image: """Get color (RGB, 3-channel, no alpha) image from the frame in the sRGB color space.""" return Image(self.__impl.image_rgb_srgb()) - def image_bgr(self): + def image_bgr(self) -> Image: """Get color (BGR, 3-channel, no alpha) image from the frame.""" return Image(self.__impl.image_bgr()) - def image_bgr_srgb(self): + def image_bgr_srgb(self) -> Image: """Get color (BGR, 3-channel, no alpha) image from the frame in the sRGB color space.""" return Image(self.__impl.image_bgr_srgb()) - def image_device_array(self, stream_or_queue, color_format): + def image_device_array(self, stream_or_queue, color_format: PixelFormat) -> DeviceArray: """Get the 2D image as a newly allocated GPU device buffer. Args: @@ -139,7 +141,7 @@ def image_device_array(self, stream_or_queue, color_format): accessor = getattr(self.__impl, "image_device_array_{}".format(suffix)) return DeviceArray(accessor(stream_or_queue)) - def image_device_array_fill(self, stream_or_queue, destination_buffer): + def image_device_array_fill(self, stream_or_queue, destination_buffer: DeviceArrayView) -> None: """Fill a caller-provided DeviceArrayView with the 2D image. The color format is taken from destination_buffer, which must be a color DeviceArrayView @@ -158,7 +160,7 @@ def image_device_array_fill(self, stream_or_queue, destination_buffer): fill = getattr(self.__impl, "image_device_array_{}_fill".format(suffix)) fill(stream_or_queue, impl) - def image_srgb(self): + def image_srgb(self) -> Image: """Get color (RGBA) image from the frame in the sRGB color space. This method is deprecated. Use image_rgba_srgb() instead. @@ -168,7 +170,7 @@ def image_srgb(self): """ return Image(self.__impl.image_rgba_srgb()) - def save(self, file_path): + def save(self, file_path: str | Path) -> None: """Save the 2D frame to a .zdf file. Args: @@ -176,7 +178,7 @@ def save(self, file_path): """ self.__impl.save(str(file_path)) - def load(self, file_path): + def load(self, file_path: str | Path) -> None: """Load a 2D frame from a .zdf file. Args: @@ -185,7 +187,7 @@ def load(self, file_path): self.__impl.load(str(file_path)) @property - def settings(self): + def settings(self) -> Settings2D: """Get the settings used to capture this frame. Returns: @@ -194,7 +196,7 @@ def settings(self): return _to_settings2d(self.__impl.settings) @property - def state(self): + def state(self) -> CameraState: """Get the camera state data at the time of the frame capture. Returns: @@ -203,7 +205,7 @@ def state(self): return _to_camera_state(self.__impl.state) @property - def info(self): + def info(self) -> FrameInfo: """Get information collected at the time of the capture. Returns: @@ -212,7 +214,7 @@ def info(self): return _to_frame_info(self.__impl.info) @property - def camera_info(self): + def camera_info(self) -> CameraInfo: """Get information about the camera used to capture the frame. Returns: @@ -220,7 +222,7 @@ def camera_info(self): """ return _to_camera_info(self.__impl.camera_info) - def release(self): + def release(self) -> None: """Release the underlying resources.""" try: impl = self.__impl @@ -229,7 +231,7 @@ def release(self): else: impl.release() - def clone(self): + def clone(self) -> Frame2D: """Get a clone of the frame. The clone will include a copy of all the frame data. diff --git a/modules/zivid/frame_info.py b/modules/zivid/frame_info.py index 7dd970ad..f0436a03 100644 --- a/modules/zivid/frame_info.py +++ b/modules/zivid/frame_info.py @@ -1,5 +1,7 @@ """Auto generated, do not edit.""" +from __future__ import annotations + # pylint: disable=too-many-lines,protected-access,too-few-public-methods,too-many-arguments,too-many-positional-arguments,line-too-long,missing-function-docstring,missing-class-docstring,redefined-builtin,too-many-branches,too-many-boolean-expressions import datetime @@ -12,7 +14,7 @@ class Diagnostics: def __init__( self, - packet_loss=_zivid.FrameInfo.Diagnostics.PacketLoss().value, + packet_loss: bool = _zivid.FrameInfo.Diagnostics.PacketLoss().value, ): if isinstance(packet_loss, (bool,)): @@ -45,11 +47,11 @@ class Metrics: def __init__( self, - acquisition_time=_zivid.FrameInfo.Metrics.AcquisitionTime().value, - capture_time=_zivid.FrameInfo.Metrics.CaptureTime().value, - kernel_compute_time=_zivid.FrameInfo.Metrics.KernelComputeTime().value, - reprocessing_time=_zivid.FrameInfo.Metrics.ReprocessingTime().value, - throttling_time=_zivid.FrameInfo.Metrics.ThrottlingTime().value, + acquisition_time: datetime.timedelta = _zivid.FrameInfo.Metrics.AcquisitionTime().value, + capture_time: datetime.timedelta = _zivid.FrameInfo.Metrics.CaptureTime().value, + kernel_compute_time: datetime.timedelta = _zivid.FrameInfo.Metrics.KernelComputeTime().value, + reprocessing_time: datetime.timedelta | None = _zivid.FrameInfo.Metrics.ReprocessingTime().value, + throttling_time: datetime.timedelta = _zivid.FrameInfo.Metrics.ThrottlingTime().value, ): if isinstance(acquisition_time, (datetime.timedelta,)): @@ -182,7 +184,7 @@ class SoftwareVersion: def __init__( self, - core=_zivid.FrameInfo.SoftwareVersion.Core().value, + core: str = _zivid.FrameInfo.SoftwareVersion.Core().value, ): if isinstance(core, (str,)): @@ -215,7 +217,7 @@ class CPU: def __init__( self, - model=_zivid.FrameInfo.SystemInfo.CPU.Model().value, + model: str = _zivid.FrameInfo.SystemInfo.CPU.Model().value, ): if isinstance(model, (str,)): @@ -248,8 +250,8 @@ class ComputeDevice: def __init__( self, - model=_zivid.FrameInfo.SystemInfo.ComputeDevice.Model().value, - vendor=_zivid.FrameInfo.SystemInfo.ComputeDevice.Vendor().value, + model: str = _zivid.FrameInfo.SystemInfo.ComputeDevice.Model().value, + vendor: str = _zivid.FrameInfo.SystemInfo.ComputeDevice.Vendor().value, ): if isinstance(model, (str,)): @@ -298,9 +300,9 @@ def __str__(self): def __init__( self, - operating_system=_zivid.FrameInfo.SystemInfo.OperatingSystem().value, - cpu=None, - compute_device=None, + operating_system: str = _zivid.FrameInfo.SystemInfo.OperatingSystem().value, + cpu: FrameInfo.SystemInfo.CPU | None = None, + compute_device: FrameInfo.SystemInfo.ComputeDevice | None = None, ): if isinstance(operating_system, (str,)): @@ -367,11 +369,11 @@ def __str__(self): def __init__( self, - time_stamp=_zivid.FrameInfo.TimeStamp().value, - diagnostics=None, - metrics=None, - software_version=None, - system_info=None, + time_stamp: datetime.datetime = _zivid.FrameInfo.TimeStamp().value, + diagnostics: FrameInfo.Diagnostics | None = None, + metrics: FrameInfo.Metrics | None = None, + software_version: FrameInfo.SoftwareVersion | None = None, + system_info: FrameInfo.SystemInfo | None = None, ): if isinstance(time_stamp, (datetime.datetime,)): diff --git a/modules/zivid/image.py b/modules/zivid/image.py index d16ee83d..db9f94ea 100644 --- a/modules/zivid/image.py +++ b/modules/zivid/image.py @@ -1,5 +1,7 @@ """Contains a the Image class.""" +from __future__ import annotations + import _zivid import numpy @@ -37,7 +39,7 @@ def __init__(self, impl): self.__impl = impl @property - def height(self): + def height(self) -> int: """Get the height of the image (number of rows). Returns: @@ -46,7 +48,7 @@ def height(self): return self.__impl.height() @property - def width(self): + def width(self) -> int: """Get the width of the image (number of columns). Returns: @@ -54,7 +56,7 @@ def width(self): """ return self.__impl.width() - def save(self, file_path): + def save(self, file_path) -> None: """Save the image to a file. The supported file type is PNG with extension .png. @@ -66,7 +68,7 @@ def save(self, file_path): self.__impl.save(str(file_path)) @classmethod - def load(cls, file_path, color_format): + def load(cls, file_path, color_format: str) -> Image: r"""Load an image from a file. The supported file types are PNG (.png), JPEG (.jpg, .jpeg), and BMP (.bmp). This method @@ -115,7 +117,7 @@ def load(cls, file_path, color_format): color_format_class = supported_color_formats[color_format] return Image(color_format_class(str(file_path))) - def copy_data(self): + def copy_data(self) -> numpy.ndarray: """Copy image data to numpy array. Returns: @@ -124,7 +126,7 @@ def copy_data(self): self.__impl.assert_not_released() return numpy.array(self.__impl) - def release(self): + def release(self) -> None: """Release the underlying resources.""" try: impl = self.__impl diff --git a/modules/zivid/mask.py b/modules/zivid/mask.py index 94b25466..ec58cdc6 100644 --- a/modules/zivid/mask.py +++ b/modules/zivid/mask.py @@ -1,7 +1,9 @@ """Contains the Mask class.""" +from __future__ import annotations + import _zivid -import numpy as np +import numpy from zivid.resolution import Resolution @@ -37,18 +39,18 @@ def __init__(self, mask_data): # Handle other resolution-like objects resolution = Resolution(mask_data.width, mask_data.height) self.__impl = _zivid.Mask(resolution._to_internal()) # pylint: disable=protected-access - elif isinstance(mask_data, np.ndarray): + elif isinstance(mask_data, numpy.ndarray): if mask_data.ndim != 2: raise ValueError("Mask data must be a 2D array") # Convert boolean mask to uint8 (True -> 1, False -> 0) if mask_data.dtype == bool: - mask_array = mask_data.astype(np.uint8) - elif mask_data.dtype == np.uint8: + mask_array = mask_data.astype(numpy.uint8) + elif mask_data.dtype == numpy.uint8: mask_array = mask_data else: # Convert other numeric types to uint8, treating non-zero as 1 - mask_array = (mask_data != 0).astype(np.uint8) + mask_array = (mask_data != 0).astype(numpy.uint8) height, width = mask_array.shape @@ -63,7 +65,7 @@ def __init__(self, mask_data): ) @property - def width(self): + def width(self) -> int: """Get the width of the mask. Returns: @@ -72,7 +74,7 @@ def width(self): return self.__impl.width() @property - def height(self): + def height(self) -> int: """Get the height of the mask. Returns: @@ -81,7 +83,7 @@ def height(self): return self.__impl.height() @property - def resolution(self): + def resolution(self) -> Resolution: """Get the resolution of the mask. Returns: @@ -89,13 +91,13 @@ def resolution(self): """ return Resolution(self.__impl.width(), self.__impl.height()) - def to_array(self): + def to_array(self) -> numpy.ndarray: """Convert mask to numpy array. Returns: 2D numpy array of uint8 values """ - return np.array(self.__impl) + return numpy.array(self.__impl) def __str__(self): """Get string representation of the mask.""" @@ -105,7 +107,7 @@ def __repr__(self): """Get string representation of the mask.""" return self.__impl.to_string() - def release(self): + def release(self) -> None: """Release the underlying resources.""" try: impl = self.__impl diff --git a/modules/zivid/matrix4x4.py b/modules/zivid/matrix4x4.py index ad40e7da..5ba8bf6f 100644 --- a/modules/zivid/matrix4x4.py +++ b/modules/zivid/matrix4x4.py @@ -1,5 +1,7 @@ """Contains Matrix4x4 class.""" +from __future__ import annotations + import pathlib import _zivid @@ -28,7 +30,7 @@ def __init__(self, arg=None): else: super().__init__(arg) - def inverse(self): + def inverse(self) -> Matrix4x4: """Return the inverse of this matrix. An exception is thrown if the matrix is not invertible. @@ -38,7 +40,7 @@ def inverse(self): """ return Matrix4x4(super().inverse()) - def load(self, file_path): + def load(self, file_path: str) -> None: """Load the matrix from the given file. Args: @@ -46,7 +48,7 @@ def load(self, file_path): """ super().load(str(file_path)) - def save(self, file_path): + def save(self, file_path: str) -> None: """Save the matrix to the given file. Args: @@ -55,7 +57,7 @@ def save(self, file_path): super().save(str(file_path)) @staticmethod - def identity(): + def identity() -> Matrix4x4: """Return the identity matrix. Returns: diff --git a/modules/zivid/network_configuration.py b/modules/zivid/network_configuration.py index 99409c7c..a0747432 100644 --- a/modules/zivid/network_configuration.py +++ b/modules/zivid/network_configuration.py @@ -1,5 +1,7 @@ """Auto generated, do not edit.""" +from __future__ import annotations + # pylint: disable=too-many-lines,protected-access,too-few-public-methods,too-many-arguments,too-many-positional-arguments,line-too-long,missing-function-docstring,missing-class-docstring,redefined-builtin,too-many-branches,too-many-boolean-expressions import _zivid @@ -24,9 +26,9 @@ def valid_values(cls): def __init__( self, - address=_zivid.NetworkConfiguration.IPV4.Address().value, - mode=_zivid.NetworkConfiguration.IPV4.Mode().value, - subnet_mask=_zivid.NetworkConfiguration.IPV4.SubnetMask().value, + address: str = _zivid.NetworkConfiguration.IPV4.Address().value, + mode: str = _zivid.NetworkConfiguration.IPV4.Mode().value, + subnet_mask: str = _zivid.NetworkConfiguration.IPV4.SubnetMask().value, ): if isinstance(address, (str,)): @@ -102,7 +104,7 @@ def __str__(self): def __init__( self, - ipv4=None, + ipv4: NetworkConfiguration.IPV4 | None = None, ): if ipv4 is None: diff --git a/modules/zivid/point_cloud.py b/modules/zivid/point_cloud.py index 37a160a3..e4f2f32a 100644 --- a/modules/zivid/point_cloud.py +++ b/modules/zivid/point_cloud.py @@ -1,5 +1,7 @@ """Contains the PointCloud class.""" +from __future__ import annotations + import _zivid import numpy from zivid.device_array import DeviceArray, _require_stream_or_queue @@ -47,7 +49,7 @@ class Downsampling: # pylint: disable=too-few-public-methods } @classmethod - def valid_values(cls): + def valid_values(cls) -> list: """Get list of allowed values. Returns: @@ -72,7 +74,7 @@ def __init__(self, impl): ) self.__impl = impl - def copy_data(self, data_format): + def copy_data(self, data_format: str) -> numpy.ndarray: """Copy point cloud data from GPU to numpy array. Supported data formats: @@ -128,7 +130,7 @@ def copy_data(self, data_format): ) from ex return numpy.array(data_format_class(self.__impl)) - def copy_image(self, data_format): + def copy_image(self, data_format: str) -> Image: """Copy the point cloud colors as 8-bit image in input format. Supported data formats: @@ -165,7 +167,7 @@ def copy_image(self, data_format): ) ) - def clone(self): + def clone(self) -> PointCloud: """Get a clone of the point cloud. The clone will include a copy of all the point cloud data on the compute device memory. This means that the @@ -183,7 +185,7 @@ def clone(self): """ return PointCloud(self.__impl.clone()) - def transform(self, matrix): + def transform(self, matrix: numpy.ndarray) -> PointCloud: """Transform the point cloud in-place by a 4x4 transformation matrix. The transform matrix must be affine, i.e., the last row of the matrix should be [0, 0, 0, 1]. @@ -197,7 +199,7 @@ def transform(self, matrix): self.__impl.transform(matrix) return self - def transformed(self, matrix): + def transformed(self, matrix: numpy.ndarray) -> PointCloud: """Get a transformed copy of the point cloud. This method is identical to "transform", except the transformed point cloud is @@ -212,7 +214,7 @@ def transformed(self, matrix): return PointCloud(self.__impl.transformed(matrix)) @property - def transformation_matrix(self): + def transformation_matrix(self) -> numpy.ndarray: """Return the current transformation matrix of this point cloud. Returns the transformation matrix from the camera's native coordinate system to the current @@ -228,7 +230,7 @@ def transformation_matrix(self): """ return self.__impl.transformation_matrix() - def downsample(self, downsampling): + def downsample(self, downsampling: str) -> PointCloud: """Downsample the point cloud in-place. Downsampling is used to reduce the number of points in the point cloud. Downsampling is performed @@ -266,7 +268,7 @@ def downsample(self, downsampling): self.__impl.downsample(internal_downsampling) return self - def downsampled(self, downsampling): + def downsampled(self, downsampling: str) -> PointCloud: """Get a downsampled copy of the point cloud. This method is identical to "downsample", except the downsampled point cloud is @@ -281,7 +283,7 @@ def downsampled(self, downsampling): internal_downsampling = PointCloud.Downsampling._valid_values[downsampling] # pylint: disable=protected-access return PointCloud(self.__impl.downsampled(internal_downsampling)) - def mask_by_region_of_interest(self, roi_box): + def mask_by_region_of_interest(self, roi_box) -> PointCloud: """Apply a region of interest box mask to the point cloud in-place. Region of interest masking is used to mask out points that fall outside a specified 3D box region. @@ -303,7 +305,7 @@ def mask_by_region_of_interest(self, roi_box): self.__impl.mask_by_region_of_interest(internal_roi_box) return self - def masked_by_region_of_interest(self, roi_box): + def masked_by_region_of_interest(self, roi_box) -> PointCloud: """Apply region of interest filtering to a copy of the point cloud. This method is identical to "mask_by_region_of_interest", except that the filtering is @@ -319,7 +321,7 @@ def masked_by_region_of_interest(self, roi_box): internal_roi_box = _to_internal_settings_region_of_interest_box(roi_box) return PointCloud(self.__impl.masked_by_region_of_interest(internal_roi_box)) - def mask(self, mask): + def mask(self, mask: numpy.ndarray | Mask) -> PointCloud: """Apply a binary mask to the point cloud in-place. The mask indicates which points in the point cloud should be considered invalid (NaN). @@ -343,7 +345,7 @@ def mask(self, mask): self.__impl.mask(_to_internal_mask(mask_obj)) return self - def masked(self, mask): + def masked(self, mask: numpy.ndarray | Mask) -> PointCloud: """Get a copy of the point cloud with a binary mask applied. This method is identical to "mask", except the masked point cloud is @@ -363,7 +365,7 @@ def masked(self, mask): return PointCloud(self.__impl.masked(_to_internal_mask(mask_obj))) @property - def height(self): + def height(self) -> int: """Get the height of the point cloud (number of rows). Returns: @@ -372,7 +374,7 @@ def height(self): return self.__impl.height() @property - def width(self): + def width(self) -> int: """Get the width of the point cloud (number of columns). Returns: @@ -380,7 +382,7 @@ def width(self): """ return self.__impl.width() - def to_unorganized_point_cloud(self): + def to_unorganized_point_cloud(self) -> UnorganizedPointCloud: """Convert to an UnorganizedPointCloud. The PointCloud class represents an organized point cloud, meaning that it contains 3D data @@ -399,7 +401,7 @@ def to_unorganized_point_cloud(self): """ return UnorganizedPointCloud(self.__impl.to_unorganized_point_cloud()) - def device_points_xyz(self, stream_or_queue): + def device_points_xyz(self, stream_or_queue) -> DeviceArray: """Get a GPU device array containing XYZ point coordinates. Returns a DeviceArray providing access to point cloud data @@ -416,7 +418,7 @@ def device_points_xyz(self, stream_or_queue): _require_stream_or_queue(stream_or_queue) return DeviceArray(self.__impl.device_points_xyz(stream_or_queue)) - def device_points_xyzw(self, stream_or_queue): + def device_points_xyzw(self, stream_or_queue) -> DeviceArray: """Get a GPU device array containing XYZW point coordinates. Returns a DeviceArray providing access to point cloud data @@ -433,7 +435,7 @@ def device_points_xyzw(self, stream_or_queue): _require_stream_or_queue(stream_or_queue) return DeviceArray(self.__impl.device_points_xyzw(stream_or_queue)) - def device_points_z(self, stream_or_queue): + def device_points_z(self, stream_or_queue) -> DeviceArray: """Get a GPU device array containing Z point coordinates. Returns a DeviceArray providing access to point cloud data @@ -450,7 +452,7 @@ def device_points_z(self, stream_or_queue): _require_stream_or_queue(stream_or_queue) return DeviceArray(self.__impl.device_points_z(stream_or_queue)) - def device_snrs(self, stream_or_queue): + def device_snrs(self, stream_or_queue) -> DeviceArray: """Get a GPU device array containing SNR values. Returns a DeviceArray providing access to point cloud data @@ -467,7 +469,7 @@ def device_snrs(self, stream_or_queue): _require_stream_or_queue(stream_or_queue) return DeviceArray(self.__impl.device_snrs(stream_or_queue)) - def device_normals_xyz(self, stream_or_queue): + def device_normals_xyz(self, stream_or_queue) -> DeviceArray: """Get a GPU device array containing normal vectors. Returns a DeviceArray providing access to point cloud data @@ -484,7 +486,7 @@ def device_normals_xyz(self, stream_or_queue): _require_stream_or_queue(stream_or_queue) return DeviceArray(self.__impl.device_normals_xyz(stream_or_queue)) - def device_image(self, stream_or_queue, color_format): + def device_image(self, stream_or_queue, color_format: PixelFormat) -> DeviceArray: """Get a GPU device array containing the organized color image. Returns a DeviceArray providing access to point cloud color data on the GPU device without @@ -505,7 +507,7 @@ def device_image(self, stream_or_queue, color_format): accessor = getattr(self.__impl, "device_image_{}".format(suffix)) return DeviceArray(accessor(stream_or_queue)) - def release(self): + def release(self) -> None: """Release the underlying resources.""" try: impl = self.__impl diff --git a/modules/zivid/presets.py b/modules/zivid/presets.py index e11e6c0d..feeef8fe 100644 --- a/modules/zivid/presets.py +++ b/modules/zivid/presets.py @@ -1,9 +1,11 @@ """Contains the Preset and Category classes.""" +from __future__ import annotations + import _zivid from zivid.camera_info import CameraInfo, _to_internal_camera_info -from zivid.settings import _to_settings -from zivid.settings2d import _to_settings2d +from zivid.settings import Settings, _to_settings +from zivid.settings2d import Settings2D, _to_settings2d class Preset: @@ -47,7 +49,7 @@ def __init__(self, impl): self.__impl = impl @property - def name(self): + def name(self) -> str: """Get the name of the preset. Returns: @@ -56,7 +58,7 @@ def name(self): return self.__impl.name() @property - def settings(self): + def settings(self) -> Settings | Settings2D: """Get the settings of the preset. The settings might change between different releases of the SDK. New presets might be added @@ -116,7 +118,7 @@ def __init__(self, impl): self.__impl = impl @property - def name(self): + def name(self) -> str: """Get the name of the category. Returns: @@ -125,7 +127,7 @@ def name(self): return self.__impl.name() @property - def presets(self): + def presets(self) -> list[Preset]: """Get the presets available in the category. The settings might change between different releases of the SDK. New presets might be added @@ -141,7 +143,7 @@ def __str__(self): return str(self.__impl) -def categories(model): +def categories(model) -> list[Category]: """Get available preset categories for the specified camera model. A preset category contains a collection of presets optimized for one scenario or use case. @@ -160,7 +162,7 @@ def categories(model): return [Category(c) for c in _zivid.presets.categories(_to_internal_camera_info(CameraInfo(model=model)).model)] -def categories2d(model): +def categories2d(model) -> list[Category]: """Get available 2D preset categories for the specified camera model. See `categories` for more information. diff --git a/modules/zivid/projection.py b/modules/zivid/projection.py index 3bb00383..baea91c0 100644 --- a/modules/zivid/projection.py +++ b/modules/zivid/projection.py @@ -1,6 +1,10 @@ """Module for experimental projection features. This API may change in the future.""" +from __future__ import annotations + import _zivid +import numpy +from zivid.camera import Camera from zivid.frame_2d import Frame2D from zivid.settings import Settings, _to_internal_settings from zivid.settings2d import Settings2D, _to_internal_settings2d @@ -34,7 +38,7 @@ def __init__(self, impl): def __str__(self): return str(self.__impl) - def capture_2d(self, settings): + def capture_2d(self, settings: Settings | Settings2D) -> Frame2D: """Capture a single 2D frame without stopping the ongoing image projection. This method returns right after the acquisition of the image is complete. @@ -79,7 +83,7 @@ def capture_2d(self, settings): ) ) - def capture(self, settings2d): + def capture(self, settings2d: Settings2D) -> Frame2D: """Capture a single 2D frame without stopping the ongoing image projection. This method is deprecated as of SDK 2.15 and will be removed in the next SDK major version (3.0). @@ -118,11 +122,11 @@ def capture(self, settings2d): return Frame2D(self.__impl.capture(_to_internal_settings2d(settings2d))) raise TypeError("Unsupported settings type: {}".format(type(settings2d))) - def stop(self): + def stop(self) -> None: """Stop the ongoing image projection.""" self.__impl.stop() - def active(self): + def active(self) -> bool: """Check if a handle is associated with an ongoing image projection. Returns: @@ -130,7 +134,7 @@ def active(self): """ return self.__impl.active() - def release(self): + def release(self) -> None: """Release the underlying resources and stop projection.""" try: impl = self.__impl @@ -149,7 +153,7 @@ def __del__(self): self.release() -def projector_resolution(camera): +def projector_resolution(camera: Camera) -> tuple: """Get the resolution of the internal projector in the Zivid camera. Args: @@ -161,7 +165,7 @@ def projector_resolution(camera): return _zivid.projection.projector_resolution(camera._Camera__impl) # pylint: disable=protected-access -def show_image_bgra(camera, image_bgra): +def show_image_bgra(camera: Camera, image_bgra: numpy.ndarray) -> ProjectedImage: """Display a 2D color image using the projector. The image resolution needs to be the same as the resolution obtained from the projector_resolution @@ -185,7 +189,7 @@ def show_image_bgra(camera, image_bgra): ) -def pixels_from_3d_points(camera, points): +def pixels_from_3d_points(camera: Camera, points: list | numpy.ndarray) -> list: """Get 2D projector pixel coordinates corresponding to 3D points relative to the camera. This function takes 3D points in the camera's reference frame and converts them to the projector frame diff --git a/modules/zivid/resolution.py b/modules/zivid/resolution.py index 5fdfbea1..5672376b 100644 --- a/modules/zivid/resolution.py +++ b/modules/zivid/resolution.py @@ -1,5 +1,7 @@ """Contains the Resolution class.""" +from __future__ import annotations + import _zivid @@ -10,7 +12,7 @@ class Resolution: such as images, point clouds, or masks. """ - def __init__(self, width, height): + def __init__(self, width: int, height: int): """Construct a Resolution from width and height. Args: @@ -30,7 +32,7 @@ def __init__(self, width, height): self.__impl = _zivid.Resolution(width, height) @property - def width(self): + def width(self) -> int: """Get the width value of the resolution. Returns: @@ -39,7 +41,7 @@ def width(self): return self.__impl.width() @property - def height(self): + def height(self) -> int: """Get the height value of the resolution. Returns: @@ -48,7 +50,7 @@ def height(self): return self.__impl.height() @property - def size(self): + def size(self) -> int: """Get the size (area) that is the product of the width and height. Returns: diff --git a/modules/zivid/scene_conditions.py b/modules/zivid/scene_conditions.py index 72c38d93..fbe95610 100644 --- a/modules/zivid/scene_conditions.py +++ b/modules/zivid/scene_conditions.py @@ -1,5 +1,7 @@ """Auto generated, do not edit.""" +from __future__ import annotations + # pylint: disable=too-many-lines,protected-access,too-few-public-methods,too-many-arguments,too-many-positional-arguments,line-too-long,missing-function-docstring,missing-class-docstring,redefined-builtin,too-many-branches,too-many-boolean-expressions import _zivid @@ -30,8 +32,8 @@ def valid_values(cls): def __init__( self, - flicker_classification=_zivid.SceneConditions.AmbientLight.FlickerClassification().value, - flicker_frequency=_zivid.SceneConditions.AmbientLight.FlickerFrequency().value, + flicker_classification: str = _zivid.SceneConditions.AmbientLight.FlickerClassification().value, + flicker_frequency: float | int | None = _zivid.SceneConditions.AmbientLight.FlickerFrequency().value, ): if isinstance(flicker_classification, _zivid.SceneConditions.AmbientLight.FlickerClassification.enum): @@ -120,7 +122,7 @@ def __str__(self): def __init__( self, - ambient_light=None, + ambient_light: SceneConditions.AmbientLight | None = None, ): if ambient_light is None: diff --git a/modules/zivid/settings.py b/modules/zivid/settings.py index 4cb126ec..e3877402 100644 --- a/modules/zivid/settings.py +++ b/modules/zivid/settings.py @@ -1,7 +1,10 @@ """Auto generated, do not edit.""" -# pylint: disable=too-many-lines,protected-access,too-few-public-methods,too-many-arguments,too-many-positional-arguments,line-too-long,missing-function-docstring,missing-class-docstring,redefined-builtin,too-many-branches,too-many-boolean-expressions +from __future__ import annotations + import collections.abc + +# pylint: disable=too-many-lines,protected-access,too-few-public-methods,too-many-arguments,too-many-positional-arguments,line-too-long,missing-function-docstring,missing-class-docstring,redefined-builtin,too-many-branches,too-many-boolean-expressions import datetime import _zivid @@ -14,10 +17,10 @@ class Acquisition: def __init__( self, - aperture=_zivid.Settings.Acquisition.Aperture().value, - brightness=_zivid.Settings.Acquisition.Brightness().value, - exposure_time=_zivid.Settings.Acquisition.ExposureTime().value, - gain=_zivid.Settings.Acquisition.Gain().value, + aperture: float | int | None = _zivid.Settings.Acquisition.Aperture().value, + brightness: float | int | None = _zivid.Settings.Acquisition.Brightness().value, + exposure_time: datetime.timedelta | None = _zivid.Settings.Acquisition.ExposureTime().value, + gain: float | int | None = _zivid.Settings.Acquisition.Gain().value, ): if ( @@ -179,7 +182,7 @@ class Diagnostics: def __init__( self, - enabled=_zivid.Settings.Diagnostics.Enabled().value, + enabled: bool | None = _zivid.Settings.Diagnostics.Enabled().value, ): if isinstance(enabled, (bool,)) or enabled is None: @@ -218,9 +221,9 @@ class Balance: def __init__( self, - blue=_zivid.Settings.Processing.Color.Balance.Blue().value, - green=_zivid.Settings.Processing.Color.Balance.Green().value, - red=_zivid.Settings.Processing.Color.Balance.Red().value, + blue: float | int | None = _zivid.Settings.Processing.Color.Balance.Blue().value, + green: float | int | None = _zivid.Settings.Processing.Color.Balance.Green().value, + red: float | int | None = _zivid.Settings.Processing.Color.Balance.Red().value, ): if ( @@ -377,7 +380,7 @@ def valid_values(cls): def __init__( self, - mode=_zivid.Settings.Processing.Color.Experimental.Mode().value, + mode: str | None = _zivid.Settings.Processing.Color.Experimental.Mode().value, ): if isinstance(mode, _zivid.Settings.Processing.Color.Experimental.Mode.enum) or mode is None: @@ -419,9 +422,9 @@ def __str__(self): def __init__( self, - gamma=_zivid.Settings.Processing.Color.Gamma().value, - balance=None, - experimental=None, + gamma: float | int | None = _zivid.Settings.Processing.Color.Gamma().value, + balance: Settings.Processing.Color.Balance | None = None, + experimental: Settings.Processing.Color.Experimental | None = None, ): if ( @@ -518,9 +521,13 @@ class Removal: def __init__( self, - enabled=_zivid.Settings.Processing.Filters.Cluster.Removal.Enabled().value, - max_neighbor_distance=_zivid.Settings.Processing.Filters.Cluster.Removal.MaxNeighborDistance().value, - min_area=_zivid.Settings.Processing.Filters.Cluster.Removal.MinArea().value, + enabled: bool | None = _zivid.Settings.Processing.Filters.Cluster.Removal.Enabled().value, + max_neighbor_distance: ( + float | int | None + ) = _zivid.Settings.Processing.Filters.Cluster.Removal.MaxNeighborDistance().value, + min_area: ( + float | int | None + ) = _zivid.Settings.Processing.Filters.Cluster.Removal.MinArea().value, ): if isinstance(enabled, (bool,)) or enabled is None: @@ -651,7 +658,7 @@ def __str__(self): def __init__( self, - removal=None, + removal: Settings.Processing.Filters.Cluster.Removal | None = None, ): if removal is None: @@ -686,8 +693,12 @@ class Correction: def __init__( self, - enabled=_zivid.Settings.Processing.Filters.Experimental.ContrastDistortion.Correction.Enabled().value, - strength=_zivid.Settings.Processing.Filters.Experimental.ContrastDistortion.Correction.Strength().value, + enabled: ( + bool | None + ) = _zivid.Settings.Processing.Filters.Experimental.ContrastDistortion.Correction.Enabled().value, + strength: ( + float | int | None + ) = _zivid.Settings.Processing.Filters.Experimental.ContrastDistortion.Correction.Strength().value, ): if isinstance(enabled, (bool,)) or enabled is None: @@ -780,8 +791,12 @@ class Removal: def __init__( self, - enabled=_zivid.Settings.Processing.Filters.Experimental.ContrastDistortion.Removal.Enabled().value, - threshold=_zivid.Settings.Processing.Filters.Experimental.ContrastDistortion.Removal.Threshold().value, + enabled: ( + bool | None + ) = _zivid.Settings.Processing.Filters.Experimental.ContrastDistortion.Removal.Enabled().value, + threshold: ( + float | int | None + ) = _zivid.Settings.Processing.Filters.Experimental.ContrastDistortion.Removal.Threshold().value, ): if isinstance(enabled, (bool,)) or enabled is None: @@ -874,8 +889,10 @@ def __str__(self): def __init__( self, - correction=None, - removal=None, + correction: ( + Settings.Processing.Filters.Experimental.ContrastDistortion.Correction | None + ) = None, + removal: Settings.Processing.Filters.Experimental.ContrastDistortion.Removal | None = None, ): if correction is None: @@ -920,7 +937,7 @@ def __str__(self): def __init__( self, - contrast_distortion=None, + contrast_distortion: Settings.Processing.Filters.Experimental.ContrastDistortion | None = None, ): if contrast_distortion is None: @@ -953,9 +970,9 @@ class Repair: def __init__( self, - enabled=_zivid.Settings.Processing.Filters.Hole.Repair.Enabled().value, - hole_size=_zivid.Settings.Processing.Filters.Hole.Repair.HoleSize().value, - strictness=_zivid.Settings.Processing.Filters.Hole.Repair.Strictness().value, + enabled: bool | None = _zivid.Settings.Processing.Filters.Hole.Repair.Enabled().value, + hole_size: float | int | None = _zivid.Settings.Processing.Filters.Hole.Repair.HoleSize().value, + strictness: int | None = _zivid.Settings.Processing.Filters.Hole.Repair.Strictness().value, ): if isinstance(enabled, (bool,)) or enabled is None: @@ -1062,7 +1079,7 @@ def __str__(self): def __init__( self, - repair=None, + repair: Settings.Processing.Filters.Hole.Repair | None = None, ): if repair is None: @@ -1095,8 +1112,10 @@ class Removal: def __init__( self, - enabled=_zivid.Settings.Processing.Filters.Noise.Removal.Enabled().value, - threshold=_zivid.Settings.Processing.Filters.Noise.Removal.Threshold().value, + enabled: bool | None = _zivid.Settings.Processing.Filters.Noise.Removal.Enabled().value, + threshold: ( + float | int | None + ) = _zivid.Settings.Processing.Filters.Noise.Removal.Threshold().value, ): if isinstance(enabled, (bool,)) or enabled is None: @@ -1177,7 +1196,7 @@ class Repair: def __init__( self, - enabled=_zivid.Settings.Processing.Filters.Noise.Repair.Enabled().value, + enabled: bool | None = _zivid.Settings.Processing.Filters.Noise.Repair.Enabled().value, ): if isinstance(enabled, (bool,)) or enabled is None: @@ -1216,7 +1235,7 @@ class Suppression: def __init__( self, - enabled=_zivid.Settings.Processing.Filters.Noise.Suppression.Enabled().value, + enabled: bool | None = _zivid.Settings.Processing.Filters.Noise.Suppression.Enabled().value, ): if isinstance(enabled, (bool,)) or enabled is None: @@ -1253,9 +1272,9 @@ def __str__(self): def __init__( self, - removal=None, - repair=None, - suppression=None, + removal: Settings.Processing.Filters.Noise.Removal | None = None, + repair: Settings.Processing.Filters.Noise.Repair | None = None, + suppression: Settings.Processing.Filters.Noise.Suppression | None = None, ): if removal is None: @@ -1324,8 +1343,10 @@ class Removal: def __init__( self, - enabled=_zivid.Settings.Processing.Filters.Outlier.Removal.Enabled().value, - threshold=_zivid.Settings.Processing.Filters.Outlier.Removal.Threshold().value, + enabled: bool | None = _zivid.Settings.Processing.Filters.Outlier.Removal.Enabled().value, + threshold: ( + float | int | None + ) = _zivid.Settings.Processing.Filters.Outlier.Removal.Threshold().value, ): if isinstance(enabled, (bool,)) or enabled is None: @@ -1404,7 +1425,7 @@ def __str__(self): def __init__( self, - removal=None, + removal: Settings.Processing.Filters.Outlier.Removal | None = None, ): if removal is None: @@ -1451,8 +1472,8 @@ def valid_values(cls): def __init__( self, - enabled=_zivid.Settings.Processing.Filters.Reflection.Removal.Enabled().value, - mode=_zivid.Settings.Processing.Filters.Reflection.Removal.Mode().value, + enabled: bool | None = _zivid.Settings.Processing.Filters.Reflection.Removal.Enabled().value, + mode: str | None = _zivid.Settings.Processing.Filters.Reflection.Removal.Mode().value, ): if isinstance(enabled, (bool,)) or enabled is None: @@ -1532,7 +1553,7 @@ def __str__(self): def __init__( self, - removal=None, + removal: Settings.Processing.Filters.Reflection.Removal | None = None, ): if removal is None: @@ -1565,8 +1586,8 @@ class Gaussian: def __init__( self, - enabled=_zivid.Settings.Processing.Filters.Smoothing.Gaussian.Enabled().value, - sigma=_zivid.Settings.Processing.Filters.Smoothing.Gaussian.Sigma().value, + enabled: bool | None = _zivid.Settings.Processing.Filters.Smoothing.Gaussian.Enabled().value, + sigma: float | int | None = _zivid.Settings.Processing.Filters.Smoothing.Gaussian.Sigma().value, ): if isinstance(enabled, (bool,)) or enabled is None: @@ -1645,7 +1666,7 @@ def __str__(self): def __init__( self, - gaussian=None, + gaussian: Settings.Processing.Filters.Smoothing.Gaussian | None = None, ): if gaussian is None: @@ -1674,13 +1695,13 @@ def __str__(self): def __init__( self, - cluster=None, - experimental=None, - hole=None, - noise=None, - outlier=None, - reflection=None, - smoothing=None, + cluster: Settings.Processing.Filters.Cluster | None = None, + experimental: Settings.Processing.Filters.Experimental | None = None, + hole: Settings.Processing.Filters.Hole | None = None, + noise: Settings.Processing.Filters.Noise | None = None, + outlier: Settings.Processing.Filters.Outlier | None = None, + reflection: Settings.Processing.Filters.Reflection | None = None, + smoothing: Settings.Processing.Filters.Smoothing | None = None, ): if cluster is None: @@ -1835,7 +1856,7 @@ def valid_values(cls): def __init__( self, - mode=_zivid.Settings.Processing.Resampling.Mode().value, + mode: str | None = _zivid.Settings.Processing.Resampling.Mode().value, ): if isinstance(mode, _zivid.Settings.Processing.Resampling.Mode.enum) or mode is None: @@ -1877,9 +1898,9 @@ def __str__(self): def __init__( self, - color=None, - filters=None, - resampling=None, + color: Settings.Processing.Color | None = None, + filters: Settings.Processing.Filters | None = None, + resampling: Settings.Processing.Resampling | None = None, ): if color is None: @@ -1948,7 +1969,7 @@ class Box: def __init__( self, - enabled=_zivid.Settings.RegionOfInterest.Box.Enabled().value, + enabled: bool | None = _zivid.Settings.RegionOfInterest.Box.Enabled().value, extents=_zivid.Settings.RegionOfInterest.Box.Extents().value, point_a=_zivid.Settings.RegionOfInterest.Box.PointA().value, point_b=_zivid.Settings.RegionOfInterest.Box.PointB().value, @@ -2097,7 +2118,7 @@ class Depth: def __init__( self, - enabled=_zivid.Settings.RegionOfInterest.Depth.Enabled().value, + enabled: bool | None = _zivid.Settings.RegionOfInterest.Depth.Enabled().value, range=_zivid.Settings.RegionOfInterest.Depth.Range().value, ): @@ -2157,8 +2178,8 @@ def __str__(self): def __init__( self, - box=None, - depth=None, + box: Settings.RegionOfInterest.Box | None = None, + depth: Settings.RegionOfInterest.Depth | None = None, ): if box is None: @@ -2249,8 +2270,8 @@ def valid_values(cls): def __init__( self, - color=_zivid.Settings.Sampling.Color().value, - pixel=_zivid.Settings.Sampling.Pixel().value, + color: str | None = _zivid.Settings.Sampling.Color().value, + pixel: str | None = _zivid.Settings.Sampling.Pixel().value, ): if isinstance(color, _zivid.Settings.Sampling.Color.enum) or color is None: @@ -2340,12 +2361,12 @@ def valid_values(cls): def __init__( self, acquisitions=None, - color=None, - engine=_zivid.Settings.Engine().value, - diagnostics=None, - processing=None, - region_of_interest=None, - sampling=None, + color: zivid.settings2d.Settings2D | None = None, + engine: str | None = _zivid.Settings.Engine().value, + diagnostics: Settings.Diagnostics | None = None, + processing: Settings.Processing | None = None, + region_of_interest: Settings.RegionOfInterest | None = None, + sampling: Settings.Sampling | None = None, ): if acquisitions is None: diff --git a/modules/zivid/settings2d.py b/modules/zivid/settings2d.py index 83f0a43f..aac70e58 100644 --- a/modules/zivid/settings2d.py +++ b/modules/zivid/settings2d.py @@ -1,7 +1,10 @@ """Auto generated, do not edit.""" -# pylint: disable=too-many-lines,protected-access,too-few-public-methods,too-many-arguments,too-many-positional-arguments,line-too-long,missing-function-docstring,missing-class-docstring,redefined-builtin,too-many-branches,too-many-boolean-expressions +from __future__ import annotations + import collections.abc + +# pylint: disable=too-many-lines,protected-access,too-few-public-methods,too-many-arguments,too-many-positional-arguments,line-too-long,missing-function-docstring,missing-class-docstring,redefined-builtin,too-many-branches,too-many-boolean-expressions import datetime import _zivid @@ -13,10 +16,10 @@ class Acquisition: def __init__( self, - aperture=_zivid.Settings2D.Acquisition.Aperture().value, - brightness=_zivid.Settings2D.Acquisition.Brightness().value, - exposure_time=_zivid.Settings2D.Acquisition.ExposureTime().value, - gain=_zivid.Settings2D.Acquisition.Gain().value, + aperture: float | int | None = _zivid.Settings2D.Acquisition.Aperture().value, + brightness: float | int | None = _zivid.Settings2D.Acquisition.Brightness().value, + exposure_time: datetime.timedelta | None = _zivid.Settings2D.Acquisition.ExposureTime().value, + gain: float | int | None = _zivid.Settings2D.Acquisition.Gain().value, ): if ( @@ -178,7 +181,7 @@ class Diagnostics: def __init__( self, - enabled=_zivid.Settings2D.Diagnostics.Enabled().value, + enabled: bool | None = _zivid.Settings2D.Diagnostics.Enabled().value, ): if isinstance(enabled, (bool,)) or enabled is None: @@ -217,9 +220,9 @@ class Balance: def __init__( self, - blue=_zivid.Settings2D.Processing.Color.Balance.Blue().value, - green=_zivid.Settings2D.Processing.Color.Balance.Green().value, - red=_zivid.Settings2D.Processing.Color.Balance.Red().value, + blue: float | int | None = _zivid.Settings2D.Processing.Color.Balance.Blue().value, + green: float | int | None = _zivid.Settings2D.Processing.Color.Balance.Green().value, + red: float | int | None = _zivid.Settings2D.Processing.Color.Balance.Red().value, ): if ( @@ -374,7 +377,7 @@ def valid_values(cls): def __init__( self, - mode=_zivid.Settings2D.Processing.Color.Experimental.Mode().value, + mode: str | None = _zivid.Settings2D.Processing.Color.Experimental.Mode().value, ): if isinstance(mode, _zivid.Settings2D.Processing.Color.Experimental.Mode.enum) or mode is None: @@ -418,9 +421,9 @@ def __str__(self): def __init__( self, - gamma=_zivid.Settings2D.Processing.Color.Gamma().value, - balance=None, - experimental=None, + gamma: float | int | None = _zivid.Settings2D.Processing.Color.Gamma().value, + balance: Settings2D.Processing.Color.Balance | None = None, + experimental: Settings2D.Processing.Color.Experimental | None = None, ): if ( @@ -511,7 +514,7 @@ def __str__(self): def __init__( self, - color=None, + color: Settings2D.Processing.Color | None = None, ): if color is None: @@ -544,8 +547,8 @@ class Interval: def __init__( self, - duration=_zivid.Settings2D.Sampling.Interval.Duration().value, - enabled=_zivid.Settings2D.Sampling.Interval.Enabled().value, + duration: datetime.timedelta | None = _zivid.Settings2D.Sampling.Interval.Duration().value, + enabled: bool | None = _zivid.Settings2D.Sampling.Interval.Enabled().value, ): if isinstance(duration, (datetime.timedelta,)) or duration is None: @@ -644,9 +647,9 @@ def valid_values(cls): def __init__( self, - color=_zivid.Settings2D.Sampling.Color().value, - pixel=_zivid.Settings2D.Sampling.Pixel().value, - interval=None, + color: str | None = _zivid.Settings2D.Sampling.Color().value, + pixel: str | None = _zivid.Settings2D.Sampling.Pixel().value, + interval: Settings2D.Sampling.Interval | None = None, ): if isinstance(color, _zivid.Settings2D.Sampling.Color.enum) or color is None: @@ -734,9 +737,9 @@ def __str__(self): def __init__( self, acquisitions=None, - diagnostics=None, - processing=None, - sampling=None, + diagnostics: Settings2D.Diagnostics | None = None, + processing: Settings2D.Processing | None = None, + sampling: Settings2D.Sampling | None = None, ): if acquisitions is None: diff --git a/modules/zivid/unorganized_point_cloud.py b/modules/zivid/unorganized_point_cloud.py index 6d02f071..23b61196 100644 --- a/modules/zivid/unorganized_point_cloud.py +++ b/modules/zivid/unorganized_point_cloud.py @@ -1,5 +1,7 @@ """Contains the UnorganizedPointCloud class.""" +from __future__ import annotations + import _zivid import numpy from zivid.device_array import DeviceArray, _require_stream_or_queue @@ -49,11 +51,11 @@ def __init__(self, impl=None): self.__impl = impl @property - def size(self): + def size(self) -> int: """Get the size of the point cloud (number of points).""" return self.__impl.size() - def extended(self, other): + def extended(self, other: UnorganizedPointCloud) -> UnorganizedPointCloud: """Create a new point cloud containing the combined data of this point cloud and another. Args: @@ -68,7 +70,7 @@ def extended(self, other): ) return UnorganizedPointCloud(self.__impl.extended(other.__impl)) # pylint: disable=protected-access - def extend(self, other): + def extend(self, other: UnorganizedPointCloud) -> UnorganizedPointCloud: """Extend this point cloud in-place by adding the points from another point cloud. Args: @@ -84,7 +86,7 @@ def extend(self, other): self.__impl.extend(other.__impl) # pylint: disable=protected-access return self - def voxel_downsampled(self, voxel_size, min_points_per_voxel): + def voxel_downsampled(self, voxel_size: float, min_points_per_voxel: int) -> UnorganizedPointCloud: """Create a new point cloud that is a voxel downsampling of this point cloud. Voxel downsampling subdivides 3D space into a grid of cubic voxels with a given size. If a given voxel @@ -100,7 +102,7 @@ def voxel_downsampled(self, voxel_size, min_points_per_voxel): """ return UnorganizedPointCloud(self.__impl.voxel_downsampled(voxel_size, min_points_per_voxel)) - def transform(self, matrix): + def transform(self, matrix: numpy.ndarray) -> UnorganizedPointCloud: """Transform the point cloud in-place by a 4x4 transformation matrix. The transform matrix must be affine, i.e., the last row of the matrix should be [0, 0, 0, 1]. @@ -114,7 +116,7 @@ def transform(self, matrix): self.__impl.transform(matrix) return self - def transformed(self, matrix): + def transformed(self, matrix: numpy.ndarray) -> UnorganizedPointCloud: """Get a transformed copy of the point cloud. This method is identical to "transform", except the transformed point cloud is @@ -128,12 +130,12 @@ def transformed(self, matrix): """ return UnorganizedPointCloud(self.__impl.transformed(matrix)) - def center(self): + def center(self) -> UnorganizedPointCloud: """Translate the point cloud in-place so that its centroid lands at the origin (0,0,0).""" self.__impl.center() return self - def centroid(self): + def centroid(self) -> numpy.ndarray | None: """Get the centroid of the point cloud, i.e. average of all XYZ point positions. Returns: @@ -141,7 +143,7 @@ def centroid(self): """ return self.__impl.centroid() - def paint_uniform_color(self, color): + def paint_uniform_color(self, color: list | numpy.ndarray) -> UnorganizedPointCloud: """Set point cloud colors in-place according to the given value. Args: @@ -151,7 +153,7 @@ def paint_uniform_color(self, color): self.__impl.paint_uniform_color(color) return self - def painted_uniform_color(self, color): + def painted_uniform_color(self, color: list | numpy.ndarray) -> UnorganizedPointCloud: """Create a clone of this point cloud with all points colored according to the given value. Args: @@ -160,7 +162,7 @@ def painted_uniform_color(self, color): """ return UnorganizedPointCloud(self.__impl.painted_uniform_color(color)) - def device_points_xyz(self, stream_or_queue): + def device_points_xyz(self, stream_or_queue) -> DeviceArray: """Get a GPU device array containing XYZ point coordinates. Returns a DeviceArray (with shape [1, N, 3]) providing access to unorganized point cloud data @@ -177,7 +179,7 @@ def device_points_xyz(self, stream_or_queue): _require_stream_or_queue(stream_or_queue) return DeviceArray(self.__impl.device_array_xyz(stream_or_queue)) - def device_points_xyzw(self, stream_or_queue): + def device_points_xyzw(self, stream_or_queue) -> DeviceArray: """Get a GPU device array containing XYZW point coordinates. Returns a DeviceArray providing access to unorganized point cloud data @@ -194,7 +196,7 @@ def device_points_xyzw(self, stream_or_queue): _require_stream_or_queue(stream_or_queue) return DeviceArray(self.__impl.device_array_xyzw(stream_or_queue)) - def device_snrs(self, stream_or_queue): + def device_snrs(self, stream_or_queue) -> DeviceArray: """Get a GPU device array containing SNR values. Returns a DeviceArray providing access to unorganized point cloud data @@ -211,7 +213,7 @@ def device_snrs(self, stream_or_queue): _require_stream_or_queue(stream_or_queue) return DeviceArray(self.__impl.device_array_snr(stream_or_queue)) - def device_colors(self, stream_or_queue, color_format): + def device_colors(self, stream_or_queue, color_format: PixelFormat) -> DeviceArray: """Get a GPU device array containing the unorganized point cloud colors. Returns a DeviceArray providing access to unorganized point cloud color data on the GPU @@ -232,7 +234,7 @@ def device_colors(self, stream_or_queue, color_format): accessor = getattr(self.__impl, "device_array_{}".format(suffix)) return DeviceArray(accessor(stream_or_queue)) - def copy_data(self, data_format): + def copy_data(self, data_format: str) -> numpy.ndarray: """Copy point cloud data from GPU to numpy array. Supported data formats: @@ -273,7 +275,7 @@ def copy_data(self, data_format): ) from ex return numpy.array(data_format_class(self.__impl)) - def clone(self): + def clone(self) -> UnorganizedPointCloud: """Get a clone of the point cloud. The clone will include a copy of all the point cloud data on the compute device memory. This means that the @@ -291,7 +293,7 @@ def clone(self): """ return UnorganizedPointCloud(self.__impl.clone()) - def release(self): + def release(self) -> None: """Release the underlying resources.""" try: impl = self.__impl diff --git a/modules/zivid/visualization.py b/modules/zivid/visualization.py index cdfad9e9..f924c232 100644 --- a/modules/zivid/visualization.py +++ b/modules/zivid/visualization.py @@ -1,5 +1,7 @@ """Contains Visualizer class for point cloud visualization.""" +from __future__ import annotations + import _zivid from zivid.frame import Frame from zivid.point_cloud import PointCloud @@ -28,7 +30,7 @@ def __str__(self): """ return str(self.__impl) - def show(self, data=None): + def show(self, data: PointCloud | UnorganizedPointCloud | Frame | None = None) -> None: """Show the visualization window or display data. When called without arguments, shows the visualization window. @@ -48,11 +50,11 @@ def show(self, data=None): else: raise TypeError(f"Unsupported data type for visualization: {type(data)}") - def hide(self): + def hide(self) -> None: """Hide the visualization window.""" self.__impl.hide() - def run(self): + def run(self) -> int: """Run the event loop. Should be called to allow interaction with the point cloud visualization. @@ -63,14 +65,14 @@ def run(self): """ return self.__impl.run() - def close(self): + def close(self) -> None: """Stop the event loop and close the window. The object goes back to idle state. """ self.__impl.close() - def resize(self, height, width): + def resize(self, height: int, width: int) -> None: """Resize the window to specified height and width. Args: @@ -79,7 +81,7 @@ def resize(self, height, width): """ self.__impl.resize(height, width) - def reset_to_fit(self): + def reset_to_fit(self) -> None: """Reset the view so that the point cloud will fit in the window. The view will be reset to the default view, which is looking at the point cloud @@ -87,15 +89,15 @@ def reset_to_fit(self): """ self.__impl.reset_to_fit() - def show_full_screen(self): + def show_full_screen(self) -> None: """Show the window in full screen mode.""" self.__impl.show_full_screen() - def show_maximized(self): + def show_maximized(self) -> None: """Show the window in maximized mode.""" self.__impl.show_maximized() - def set_window_title(self, title): + def set_window_title(self, title: str) -> None: """Set the window title. Args: @@ -104,7 +106,7 @@ def set_window_title(self, title): self.__impl.set_window_title(title) @property - def colors_enabled(self): + def colors_enabled(self) -> bool: """Whether coloring of the points with their accompanying RGB colors is enabled. Returns: @@ -113,7 +115,7 @@ def colors_enabled(self): return self.__impl.colors_enabled @colors_enabled.setter - def colors_enabled(self, enabled): + def colors_enabled(self, enabled: bool) -> None: """Enable or disable coloring of the points with their accompanying RGB colors. Args: @@ -122,7 +124,7 @@ def colors_enabled(self, enabled): self.__impl.colors_enabled = enabled @property - def meshing_enabled(self): + def meshing_enabled(self) -> bool: """Whether meshing is enabled. Meshing is not supported when showing an unorganized point cloud. An exception @@ -134,7 +136,7 @@ def meshing_enabled(self): return self.__impl.meshing_enabled @meshing_enabled.setter - def meshing_enabled(self, enabled): + def meshing_enabled(self, enabled: bool) -> None: """Enable or disable meshing. Meshing is not supported when showing an unorganized point cloud. An exception @@ -146,7 +148,7 @@ def meshing_enabled(self, enabled): self.__impl.meshing_enabled = enabled @property - def axis_indicator_enabled(self): + def axis_indicator_enabled(self) -> bool: """Whether the axis indicator is enabled. Returns: @@ -155,7 +157,7 @@ def axis_indicator_enabled(self): return self.__impl.axis_indicator_enabled @axis_indicator_enabled.setter - def axis_indicator_enabled(self, enabled): + def axis_indicator_enabled(self, enabled: bool) -> None: """Enable or disable the axis indicator. Args: @@ -163,7 +165,7 @@ def axis_indicator_enabled(self, enabled): """ self.__impl.axis_indicator_enabled = enabled - def release(self): + def release(self) -> None: """Release the singleton visualizer resources. This will invalidate all Visualizer instances and free the underlying resources. diff --git a/sdk_version.json b/sdk_version.json index bad3a67d..77b87cf4 100644 --- a/sdk_version.json +++ b/sdk_version.json @@ -2,5 +2,6 @@ "major": 2, "minor": 18, "patch": 0, - "pre_release": "" + "pre_release": "", + "python_wrapper_patch": 1 } diff --git a/setup.py b/setup.py index 373db023..b64cbd2a 100644 --- a/setup.py +++ b/setup.py @@ -28,6 +28,11 @@ def _determine_package_version(): str(sdk_version["patch"]), ] + wrapper_patch_version = str(sdk_version["python_wrapper_patch"]) + + if int(wrapper_patch_version) > 0: + version_segments.append(wrapper_patch_version) + github_repository = os.getenv("GITHUB_REPOSITORY") github_ref = os.getenv("GITHUB_REF")