def test_to_internal_settings_to_settings_modified(random_settings):
    from zivid import Settings
    from zivid._settings_converter import to_settings, to_internal_settings

    converted_settings = to_settings(to_internal_settings(random_settings))
    assert random_settings == converted_settings
    assert isinstance(converted_settings, Settings)
    assert isinstance(random_settings, Settings)
Example #2
0
    def settings(self, settings):
        """Update the camera settings.

        Args:
            settings: New settings for the camera

        """
        self.__impl.settings = _settings_converter.to_internal_settings(  # pylint: disable=protected-access
            settings)
def test_to_internal_settings_to_settings_default():
    from zivid import Settings
    from zivid._settings_converter import to_settings, to_internal_settings

    default_settings = Settings()
    converted_settings = to_settings(to_internal_settings(default_settings))
    assert default_settings == converted_settings
    assert isinstance(converted_settings, Settings)
    assert isinstance(default_settings, Settings)
Example #4
0
    def connect(self, settings=None):
        """Connect to the camera.

        Args:
            settings: New settings for the camera

        """
        if settings is None:
            self.__impl.connect()
        else:
            self.__impl.connect(
                _settings_converter.to_internal_settings(  # pylint: disable=protected-access
                    settings))
def test_to_internal_settings_to_settings_modified():
    import datetime
    from zivid import Settings
    from zivid._settings_converter import to_settings, to_internal_settings

    modified_settings = Settings(acquisitions=[
        Settings.Acquisition(),
        Settings.Acquisition(exposure_time=datetime.timedelta(
            milliseconds=100)),
    ])

    converted_settings = to_settings(to_internal_settings(modified_settings))
    assert modified_settings == converted_settings
    assert isinstance(converted_settings, Settings)
    assert isinstance(modified_settings, Settings)
Example #6
0
    def create_file_camera(self, frame_file, settings=None):
        """Create a virtual camera to simulate Zivid measurements by reading data from a file.

        Args:
            frame_file: Data file in ZDF format containing Zivid data
            settings: Settings for the camera

        Returns:
            Zivid virtual camera instance

        """
        if settings is None:
            return Camera(self.__impl.create_file_camera(str(frame_file)))
        return Camera(
            self.__impl.create_file_camera(
                str(frame_file),
                settings=_settings_converter.to_internal_settings(settings),
            ))
Example #7
0
    def capture(self, settings_collection=None):
        """Capture a single frame.

        Args:
            settings_collection: A collection of settings to be captured and merged into a HDR frame.
                If None, then current settings will be used instead

        Returns:
            A frame containing a 3D image and metadata

        """
        if settings_collection is not None:
            return Frame(
                self.__impl.capture([
                    _settings_converter.to_internal_settings(settings)
                    for settings in settings_collection
                ]))
        return Frame(self.__impl.capture())
Example #8
0
def capture(camera, settings_list):
    """Capture and merge frames.

    Args:
        camera: an instance of zivid.Camera
        settings_list: a list of zivid.Settings instances

    Returns:
        a single frame (when single setting given) or high dynamic range frame (when multiple settings given)

    """
    return Frame(
        _zivid.hdr.capture(
            camera._Camera__impl,  # pylint: disable=protected-access
            [
                _settings_converter.to_internal_settings(settings)
                for settings in settings_list
            ],
        )
    )
Example #9
0
    def capture(self, settings):
        """Capture a single frame or a single 2D frame.

        Args:
            settings: Settings to be used to capture. Can be either a Settings or Settings2D instance

        Returns:
            A Frame containing a 3D image plus metadata or a Frame2D containing a 2D image plus metadata.

        Raises:
            TypeError: If argument is neither a Settings or a Settings2D
        """
        if isinstance(settings, zivid.Settings):
            return Frame(
                self.__impl.capture(
                    _settings_converter.to_internal_settings(settings)))
        if isinstance(settings, Settings2D):
            return Frame2D(
                self.__impl.capture(
                    _settings_2d_converter.to_internal_settings2_d(settings)))
        raise TypeError("Unsupported settings type: {}".format(type(settings)))
Example #10
0
    def connect_camera(self, serial_number=None, settings=None):
        """Connect to the next available Zivid Camera.

        Args:
            serial_number: Connect to the camera with this serial number
            settings: Settings for the camera

        Returns:
            Zivid camera instance

        """
        internal_settings = (_settings_converter.to_internal_settings(settings)
                             if settings else None)
        if serial_number is not None and internal_settings is not None:
            return Camera(
                self.__impl.connect_camera(serial_number=serial_number,
                                           settings=internal_settings))
        if serial_number is not None:
            return Camera(self.__impl.connect_camera(serial_number))
        if internal_settings is not None:
            return Camera(
                self.__impl.connect_camera(settings=internal_settings))
        return Camera(self.__impl.connect_camera())