Skip to content

Commit

Permalink
Merge pull request #253 from zivid/add-srgb-and-image-load
Browse files Browse the repository at this point in the history
Support for Zivid SDK 2.11 and some new Image class functions
  • Loading branch information
vawale authored Dec 15, 2023
2 parents dec9d49 + 8101fef commit 92fb24f
Show file tree
Hide file tree
Showing 24 changed files with 473 additions and 24 deletions.
5 changes: 2 additions & 3 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ ignore-long-lines="[^"]{80,}"
# While camera.capture() can return both Frame and Frame2D, since pylint does not do code path
# analysis it mistakenly thinks it can only return Frame. This causes false-positive "no-member"
# warnings when we access methods that only exist on Frame2D (for now this is only image_rgba()
# and image_bgra()).
generated-members=image_rgba,image_bgra
# warnings when we access methods that only exist on Frame2D.
generated-members=image_rgba,image_bgra,image_srgb
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Zivid Python is the official Python package for Zivid 3D cameras. Read more abou
### Dependencies

* [Python](https://www.python.org/) version 3.7 or higher
* [Zivid SDK][zivid-download-software-url] version 2.10.1 (see [here][zivid-software-installation-url] for help)
* [Zivid SDK][zivid-download-software-url] version 2.11.0 (see [here][zivid-software-installation-url] for help)
* [Compiler](doc/CompilerInstallation.md) with C++17 support

*Ubuntu users must install Python headers (`apt install python3-dev`) in addition to the regular `python3` package.*
Expand Down
2 changes: 1 addition & 1 deletion continuous-integration/deployment/expected-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.10.1.2.10.1
2.11.0.2.11.0
4 changes: 2 additions & 2 deletions continuous-integration/linux/lint-cpp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ fi

#Todo: buildDir=$1

cppFiles=$(find "$ROOT_DIR" -name '*.cpp' |grep --invert-match src/3rd-party |grep --invert-match _skbuild)
hFiles=$(find "$ROOT_DIR" -name '*.h' |grep --invert-match src/3rd-party |grep --invert-match _skbuild)
cppFiles=$(find "$ROOT_DIR" -name '*.cpp' | grep --invert-match src/3rd-party | grep --invert-match _skbuild | grep --invert-match build)
hFiles=$(find "$ROOT_DIR" -name '*.h' | grep --invert-match src/3rd-party | grep --invert-match _skbuild | grep --invert-match build)

if [ -z "$cppFiles" ] || [ -z "$hFiles" ]; then
echo Error: Cannot find C++ source files
Expand Down
2 changes: 1 addition & 1 deletion continuous-integration/versions.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"ZIVID_SDK_EXACT_VERSION": "2.10.1+50b274e8-7",
"ZIVID_SDK_EXACT_VERSION": "2.11.0+95829246-1",
"ZIVID_TELICAM_EXACT_VERSION": "3.0.1.1-3"
}
2 changes: 2 additions & 0 deletions modules/_zivid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
Application,
Array2DColorRGBA,
Array2DColorBGRA,
Array2DColorSRGB,
Array2DNormalXYZ,
Array2DPointXYZ,
Array2DPointXYZColorRGBA,
Expand All @@ -59,6 +60,7 @@
Frame2D,
ImageRGBA,
ImageBGRA,
ImageSRGB,
CameraInfo,
infield_correction,
Matrix4x4,
Expand Down
249 changes: 249 additions & 0 deletions modules/zivid/camera_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,72 @@


class CameraState:
class Network:
class IPV4:
def __init__(
self,
address=_zivid.CameraState.Network.IPV4.Address().value,
):
if isinstance(address, (str,)):
self._address = _zivid.CameraState.Network.IPV4.Address(address)
else:
raise TypeError(
"Unsupported type, expected: (str,), got {value_type}".format(
value_type=type(address)
)
)

@property
def address(self):
return self._address.value

@address.setter
def address(self, value):
if isinstance(value, (str,)):
self._address = _zivid.CameraState.Network.IPV4.Address(value)
else:
raise TypeError(
"Unsupported type, expected: str, got {value_type}".format(
value_type=type(value)
)
)

def __eq__(self, other):
if self._address == other._address:
return True
return False

def __str__(self):
return str(_to_internal_camera_state_network_ipv4(self))

def __init__(
self,
ipv4=None,
):
if ipv4 is None:
ipv4 = self.IPV4()
if not isinstance(ipv4, self.IPV4):
raise TypeError("Unsupported type: {value}".format(value=type(ipv4)))
self._ipv4 = ipv4

@property
def ipv4(self):
return self._ipv4

@ipv4.setter
def ipv4(self, value):
if not isinstance(value, self.IPV4):
raise TypeError("Unsupported type {value}".format(value=type(value)))
self._ipv4 = value

def __eq__(self, other):
if self._ipv4 == other._ipv4:
return True
return False

def __str__(self):
return str(_to_internal_camera_state_network(self))

class Temperature:
def __init__(
self,
Expand Down Expand Up @@ -207,10 +273,57 @@ def __eq__(self, other):
def __str__(self):
return str(_to_internal_camera_state_temperature(self))

class InaccessibleReason:
ipConflictWithAnotherCamera = "ipConflictWithAnotherCamera"
ipConflictWithLocalNetworkAdapter = "ipConflictWithLocalNetworkAdapter"
ipInMultipleLocalSubnets = "ipInMultipleLocalSubnets"
ipNotInLocalSubnet = "ipNotInLocalSubnet"

_valid_values = {
"ipConflictWithAnotherCamera": _zivid.CameraState.InaccessibleReason.ipConflictWithAnotherCamera,
"ipConflictWithLocalNetworkAdapter": _zivid.CameraState.InaccessibleReason.ipConflictWithLocalNetworkAdapter,
"ipInMultipleLocalSubnets": _zivid.CameraState.InaccessibleReason.ipInMultipleLocalSubnets,
"ipNotInLocalSubnet": _zivid.CameraState.InaccessibleReason.ipNotInLocalSubnet,
}

@classmethod
def valid_values(cls):
return list(cls._valid_values.keys())

class Status:
available = "available"
busy = "busy"
connected = "connected"
connecting = "connecting"
disappeared = "disappeared"
disconnecting = "disconnecting"
firmwareUpdateRequired = "firmwareUpdateRequired"
inaccessible = "inaccessible"
updatingFirmware = "updatingFirmware"

_valid_values = {
"available": _zivid.CameraState.Status.available,
"busy": _zivid.CameraState.Status.busy,
"connected": _zivid.CameraState.Status.connected,
"connecting": _zivid.CameraState.Status.connecting,
"disappeared": _zivid.CameraState.Status.disappeared,
"disconnecting": _zivid.CameraState.Status.disconnecting,
"firmwareUpdateRequired": _zivid.CameraState.Status.firmwareUpdateRequired,
"inaccessible": _zivid.CameraState.Status.inaccessible,
"updatingFirmware": _zivid.CameraState.Status.updatingFirmware,
}

@classmethod
def valid_values(cls):
return list(cls._valid_values.keys())

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,
):
if isinstance(available, (bool,)):
Expand All @@ -231,6 +344,41 @@ def __init__(
)
)

if (
isinstance(inaccessible_reason, _zivid.CameraState.InaccessibleReason.enum)
or inaccessible_reason is None
):
self._inaccessible_reason = _zivid.CameraState.InaccessibleReason(
inaccessible_reason
)
elif isinstance(inaccessible_reason, str):
self._inaccessible_reason = _zivid.CameraState.InaccessibleReason(
self.InaccessibleReason._valid_values[inaccessible_reason]
)
else:
raise TypeError(
"Unsupported type, expected: str or None, got {value_type}".format(
value_type=type(inaccessible_reason)
)
)

if isinstance(status, _zivid.CameraState.Status.enum):
self._status = _zivid.CameraState.Status(status)
elif isinstance(status, str):
self._status = _zivid.CameraState.Status(self.Status._valid_values[status])
else:
raise TypeError(
"Unsupported type, expected: str, got {value_type}".format(
value_type=type(status)
)
)

if network is None:
network = self.Network()
if not isinstance(network, self.Network):
raise TypeError("Unsupported type: {value}".format(value=type(network)))
self._network = network

if temperature is None:
temperature = self.Temperature()
if not isinstance(temperature, self.Temperature):
Expand All @@ -245,6 +393,30 @@ def available(self):
def connected(self):
return self._connected.value

@property
def inaccessible_reason(self):
if self._inaccessible_reason.value is None:
return None
for key, internal_value in self.InaccessibleReason._valid_values.items():
if internal_value == self._inaccessible_reason.value:
return key
raise ValueError(
"Unsupported value {value}".format(value=self._inaccessible_reason)
)

@property
def status(self):
if self._status.value is None:
return None
for key, internal_value in self.Status._valid_values.items():
if internal_value == self._status.value:
return key
raise ValueError("Unsupported value {value}".format(value=self._status))

@property
def network(self):
return self._network

@property
def temperature(self):
return self._temperature
Expand All @@ -271,6 +443,43 @@ def connected(self, value):
)
)

@inaccessible_reason.setter
def inaccessible_reason(self, value):
if isinstance(value, str):
self._inaccessible_reason = _zivid.CameraState.InaccessibleReason(
self.InaccessibleReason._valid_values[value]
)
elif (
isinstance(value, _zivid.CameraState.InaccessibleReason.enum)
or value is None
):
self._inaccessible_reason = _zivid.CameraState.InaccessibleReason(value)
else:
raise TypeError(
"Unsupported type, expected: str or None, got {value_type}".format(
value_type=type(value)
)
)

@status.setter
def status(self, value):
if isinstance(value, str):
self._status = _zivid.CameraState.Status(self.Status._valid_values[value])
elif isinstance(value, _zivid.CameraState.Status.enum):
self._status = _zivid.CameraState.Status(value)
else:
raise TypeError(
"Unsupported type, expected: str, got {value_type}".format(
value_type=type(value)
)
)

@network.setter
def network(self, value):
if not isinstance(value, self.Network):
raise TypeError("Unsupported type {value}".format(value=type(value)))
self._network = value

@temperature.setter
def temperature(self, value):
if not isinstance(value, self.Temperature):
Expand All @@ -288,6 +497,9 @@ def __eq__(self, other):
if (
self._available == other._available
and self._connected == other._connected
and self._inaccessible_reason == other._inaccessible_reason
and self._status == other._status
and self._network == other._network
and self._temperature == other._temperature
):
return True
Expand All @@ -297,6 +509,18 @@ def __str__(self):
return str(_to_internal_camera_state(self))


def _to_camera_state_network_ipv4(internal_ipv4):
return CameraState.Network.IPV4(
address=internal_ipv4.address.value,
)


def _to_camera_state_network(internal_network):
return CameraState.Network(
ipv4=_to_camera_state_network_ipv4(internal_network.ipv4),
)


def _to_camera_state_temperature(internal_temperature):
return CameraState.Temperature(
dmd=internal_temperature.dmd.value,
Expand All @@ -309,12 +533,30 @@ def _to_camera_state_temperature(internal_temperature):

def _to_camera_state(internal_camera_state):
return CameraState(
network=_to_camera_state_network(internal_camera_state.network),
temperature=_to_camera_state_temperature(internal_camera_state.temperature),
available=internal_camera_state.available.value,
connected=internal_camera_state.connected.value,
inaccessible_reason=internal_camera_state.inaccessible_reason.value,
status=internal_camera_state.status.value,
)


def _to_internal_camera_state_network_ipv4(ipv4):
internal_ipv4 = _zivid.CameraState.Network.IPV4()

internal_ipv4.address = _zivid.CameraState.Network.IPV4.Address(ipv4.address)

return internal_ipv4


def _to_internal_camera_state_network(network):
internal_network = _zivid.CameraState.Network()

internal_network.ipv4 = _to_internal_camera_state_network_ipv4(network.ipv4)
return internal_network


def _to_internal_camera_state_temperature(temperature):
internal_temperature = _zivid.CameraState.Temperature()

Expand All @@ -338,7 +580,14 @@ def _to_internal_camera_state(camera_state):
internal_camera_state.connected = _zivid.CameraState.Connected(
camera_state.connected
)
internal_camera_state.inaccessible_reason = _zivid.CameraState.InaccessibleReason(
camera_state._inaccessible_reason.value
)
internal_camera_state.status = _zivid.CameraState.Status(camera_state._status.value)

internal_camera_state.network = _to_internal_camera_state_network(
camera_state.network
)
internal_camera_state.temperature = _to_internal_camera_state_temperature(
camera_state.temperature
)
Expand Down
8 changes: 8 additions & 0 deletions modules/zivid/frame_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ def image_bgra(self):
"""
return Image(self.__impl.image_bgra())

def image_srgb(self):
"""Get color (RGBA) image from the frame in the sRGB color space.
Returns:
An image instance containing RGBA data in sRGB color space
"""
return Image(self.__impl.image_srgb())

@property
def settings(self):
"""Get the settings used to capture this frame.
Expand Down
Loading

0 comments on commit 92fb24f

Please sign in to comment.