Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 71 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,47 +1,61 @@
cmake_minimum_required(VERSION 3.24 FATAL_ERROR)

if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan_provider.cmake")
message(STATUS "Downloading conan_provider.cmake from https://github.com/conan-io/cmake-conan")
file(
DOWNLOAD
"https://raw.githubusercontent.com/conan-io/cmake-conan/develop2/conan_provider.cmake"
"${CMAKE_BINARY_DIR}/conan_provider.cmake"
)
endif()
if(TARGET Zivid::Core)
message(STATUS "Building Python wrapper as part of Zivid SDK - using existing Zivid::Core target")
set(ZIVID_PYTHON_SDK_BUILD TRUE)
else()
message(STATUS "Building Python wrapper in standalone mode")
set(ZIVID_PYTHON_SDK_BUILD FALSE)

set(CMAKE_PROJECT_TOP_LEVEL_INCLUDES ${CMAKE_BINARY_DIR}/conan_provider.cmake)
if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan_provider.cmake")
message(STATUS "Downloading conan_provider.cmake from https://github.com/conan-io/cmake-conan")
file(
DOWNLOAD
"https://raw.githubusercontent.com/conan-io/cmake-conan/develop2/conan_provider.cmake"
"${CMAKE_BINARY_DIR}/conan_provider.cmake"
)
endif()
set(CMAKE_PROJECT_TOP_LEVEL_INCLUDES ${CMAKE_BINARY_DIR}/conan_provider.cmake)
endif()

project(zivid LANGUAGES CXX)
project(ZividPython LANGUAGES CXX)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

include(ReadZividVersion)
include(CompilerWarningOptions)
include(TargetUtilities)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(NOT ZIVID_PYTHON_SDK_BUILD)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()

option(ZIVID_PYTHON_VERSION "Version number to be compiled into the module" "UNKNOWN")

zivid_read_sdk_version(JSON_FILE "${CMAKE_CURRENT_SOURCE_DIR}/sdk_version.json")
if("${ZIVID_SDK_VERSION}" STREQUAL "")
message(FATAL_ERROR "ZIVID_SDK_VERSION is not set. Please ensure sdk_version.json is present and valid.")
if(NOT ZIVID_PYTHON_SDK_BUILD)
zivid_read_sdk_version(JSON_FILE "${CMAKE_CURRENT_SOURCE_DIR}/sdk_version.json")
if("${ZIVID_SDK_VERSION}" STREQUAL "")
message(FATAL_ERROR "ZIVID_SDK_VERSION is not set. Please ensure sdk_version.json is present and valid.")
endif()
message(STATUS "Standalone build - Using Zivid SDK version: ${ZIVID_SDK_VERSION}")
endif()

if(MSVC)
add_compile_options(/bigobj)
endif()

find_package(
Python3
"${PYTHON_INTERPRETER_VERSION}"
EXACT
REQUIRED
COMPONENTS
Interpreter
Development
)
if(NOT ZIVID_PYTHON_SDK_BUILD)
find_package(
Python3
"${PYTHON_INTERPRETER_VERSION}"
EXACT
REQUIRED
COMPONENTS
Interpreter
Development
)
endif()
if(WIN32)
# If "debug" libraries for Python are installed on Windows, `find_package(Python3 ...)`
# above will find debug version `_d` of imported python library during linking. `pybind11`
Expand All @@ -59,6 +73,38 @@ endif()

find_package(Eigen3 3.4.0 CONFIG REQUIRED)
find_package(pybind11 2.12.0 CONFIG REQUIRED)
find_package(Zivid ${ZIVID_SDK_VERSION} EXACT COMPONENTS Core REQUIRED)

if(NOT ZIVID_PYTHON_SDK_BUILD)
find_package(Zivid ${ZIVID_SDK_VERSION} EXACT COMPONENTS Core REQUIRED)
endif()

add_subdirectory(src)

if(DEFINED ZIVID_PYTHON_OUTPUT_DIR AND ZIVID_PYTHON_OUTPUT_DIR)
include(Zivid_PythonStage)

zivid_stage_python_sources(
TARGET ZividPythonStage_zivid
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/modules/zivid"
DEST_DIR "${ZIVID_PYTHON_OUTPUT_DIR}/zivid"
)

zivid_stage_python_sources(
TARGET ZividPythonStage_zivid_init
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/modules/_zivid"
DEST_DIR "${ZIVID_PYTHON_OUTPUT_DIR}/_zivid"
)

add_dependencies(
_zividcore
ZividPythonStage_zivid
ZividPythonStage_zivid_init
)
if(TARGET _zividvisualization)
add_dependencies(
_zividvisualization
ZividPythonStage_zivid
ZividPythonStage_zivid_init
)
endif()
endif()
4 changes: 2 additions & 2 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
"description": "Build python wrapper with latest sdk on Linux",
"inherits": "common_opts",
"cacheVariables": {
"CMAKE_C_COMPILER": "clang-20",
"CMAKE_CXX_COMPILER": "clang++-20",
"CMAKE_C_COMPILER": "clang-21",
"CMAKE_CXX_COMPILER": "clang++-21",
"CMAKE_EXE_LINKER_FLAGS": "-fuse-ld=mold",
"CMAKE_MODULE_LINKER_FLAGS": "-fuse-ld=mold",
"CMAKE_SHARED_LINKER_FLAGS": "-fuse-ld=mold"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ at [zivid.com](https://www.zivid.com/).
### Dependencies

* [Python](https://www.python.org/) version 3.7 or higher
* [Zivid SDK][zivid-download-software-url] version 2.17.2 (see [docs][zivid-software-installation-url] for help)
* [Zivid SDK][zivid-download-software-url] version 2.18.0 (see [docs][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
3 changes: 3 additions & 0 deletions cmake/CompilerWarningOptions.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include_guard()

option(WARNINGS "Enable compiler warnings" OFF)

if(WARNINGS)
Expand Down Expand Up @@ -34,6 +36,7 @@ elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(WARNINGS_THAT_SHOULD_BE_IGNORED # WHY it is ok to ignore
c++98-compat # Code base should be modern
c++98-compat-pedantic # Code base should be modern
nrvo # TODO(ZIVID-11540): Reenable when fixed - return value optimization warning
)

foreach(WARNING ${WARNINGS_THAT_SHOULD_BE_FIXED})
Expand Down
2 changes: 2 additions & 0 deletions cmake/ReadZividVersion.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include_guard()

# Reads the zivid sdk version from a json file. Sets `ZIVID_SDK_VERSION` CMake variable in parent
# scope to the version read from the file.
function(zivid_read_sdk_version)
Expand Down
23 changes: 23 additions & 0 deletions cmake/TargetUtilities.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include_guard()

function(_zivid_python_library)
set(OPTIONS "")
set(ONE_VALUE_ARGUMENTS
Expand Down Expand Up @@ -37,6 +39,12 @@ function(_zivid_python_library)
NO_EXTRAS
)

# Avoid STB_GNU_UNIQUE on guard variables for function-local statics in inline/template
# functions: when two Python extension .so files are loaded into the same process, the
# unified guard otherwise makes the second module skip initialization of its own
# (hidden, per-DSO) copy. See pybind11 PR #949.
target_compile_options(${MODULE_NAME} PRIVATE $<$<CXX_COMPILER_ID:GNU>:-fno-gnu-unique>)

add_library("ZividPython::${ARG_NAME}" ALIAS ${MODULE_NAME})

target_link_libraries(${MODULE_NAME} PRIVATE ${ARG_LINK_LIBRARIES})
Expand All @@ -50,6 +58,21 @@ function(_zivid_python_library)
""
)

if(DEFINED ZIVID_PYTHON_OUTPUT_DIR AND ZIVID_PYTHON_OUTPUT_DIR)
set_target_properties(
${MODULE_NAME}
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY
"${ZIVID_PYTHON_OUTPUT_DIR}/_zivid"
RUNTIME_OUTPUT_DIRECTORY
"${ZIVID_PYTHON_OUTPUT_DIR}/_zivid"
)
endif()

if(TARGET zivid-python)
add_dependencies(zivid-python ${MODULE_NAME})
endif()

target_include_directories(
${MODULE_NAME}
PUBLIC
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.17.2
2.18.0
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ function fedora_install_www_deb {
rm -r $TMP_DIR || exit $?
}

fedora_install_www_deb "https://downloads.zivid.com/sdk/releases/${ZIVID_SDK_EXACT_VERSION}/u20/zivid_${ZIVID_SDK_EXACT_VERSION}_amd64.deb" || exit $?
fedora_install_www_deb "https://downloads.zivid.com/sdk/releases/${ZIVID_SDK_EXACT_VERSION}/u20/amd64/zivid-opencl_${ZIVID_SDK_EXACT_VERSION}_amd64.deb" || exit $?
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ function ubuntu_install_www_deb {
rm -r $TMP_DIR || exit $?
}

ubuntu_install_www_deb "https://downloads.zivid.com/sdk/releases/${ZIVID_SDK_EXACT_VERSION}/u20/zivid_${ZIVID_SDK_EXACT_VERSION}_amd64.deb" || exit $?
ubuntu_install_www_deb "https://downloads.zivid.com/sdk/releases/${ZIVID_SDK_EXACT_VERSION}/u20/amd64/zivid-opencl_${ZIVID_SDK_EXACT_VERSION}_amd64.deb" || exit $?
2 changes: 1 addition & 1 deletion continuous-integration/versions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"ZIVID_SDK_EXACT_VERSION": "2.17.2+440b2367-1"
"ZIVID_SDK_EXACT_VERSION": "2.18.0+1b44dbef-1"
}
38 changes: 38 additions & 0 deletions modules/_zivid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,25 +93,63 @@ def __repr__(self):
Array2DPointXYZW,
Array2DPointZ,
Array2DSNR,
BoundingBox,
Camera,
CameraAddress,
CameraHealth,
CameraInfo,
CameraIntrinsics,
CameraState,
ComputeBackend,
ComputeDevice,
CUDAContextPtr,
CUDAStreamPtr,
DeviceArrayNormalXYZ,
DeviceArrayPointXYZ,
DeviceArrayPointXYZW,
DeviceArrayPointZ,
DeviceArraySNR,
DeviceArrayViewBGR,
DeviceArrayViewBGR_SRGB,
DeviceArrayViewBGRA,
DeviceArrayViewBGRA_SRGB,
DeviceArrayViewRGB,
DeviceArrayViewRGB_SRGB,
DeviceArrayViewRGBA,
DeviceArrayViewRGBA_SRGB,
DeviceArrayViewRGBAf,
Frame,
Frame2D,
FrameInfo,
ImageBGR,
ImageBGR_SRGB,
ImageBGRA,
ImageBGRA_SRGB,
ImageDeviceArrayBGR,
ImageDeviceArrayBGR_SRGB,
ImageDeviceArrayBGRA,
ImageDeviceArrayBGRA_SRGB,
ImageDeviceArrayRGB,
ImageDeviceArrayRGB_SRGB,
ImageDeviceArrayRGBA,
ImageDeviceArrayRGBA_SRGB,
ImageDeviceArrayRGBAf,
ImageRGB,
ImageRGB_SRGB,
ImageRGBA,
ImageRGBA_SRGB,
Mask,
Matrix4x4,
NetworkConfiguration,
OpenCLCommandQueuePtr,
PixelMapping,
PointCloud,
ProjectedImage,
Resolution,
SceneConditions,
Settings,
Settings2D,
StreamOrQueue,
UnorganizedPointCloud,
__version__,
calibration,
Expand Down
17 changes: 17 additions & 0 deletions modules/zivid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,35 @@
import zivid.presets
import zivid.projection
import zivid.visualization
from _zivid._zividcore import (
ComputeBackend,
CUDAContextPtr,
CUDAStreamPtr,
FrameFileType,
OpenCLCommandQueuePtr,
StreamOrQueue,
read_frame_file_type,
synchronize_stream,
)
from zivid.application import Application
from zivid.bounding_box import BoundingBox
from zivid.camera import Camera
from zivid.camera_address import CameraAddress
from zivid.camera_health import CameraHealth
from zivid.camera_info import CameraInfo
from zivid.camera_intrinsics import CameraIntrinsics
from zivid.camera_state import CameraState
from zivid.device_array_view import DeviceArrayView, create_device_array_view
from zivid.frame import Frame
from zivid.frame_2d import Frame2D
from zivid.frame_info import FrameInfo
from zivid.image import Image
from zivid.mask import Mask
from zivid.matrix4x4 import Matrix4x4
from zivid.network_configuration import NetworkConfiguration
from zivid.pixel_format import PixelFormat
from zivid.point_cloud import PointCloud
from zivid.resolution import Resolution
from zivid.scene_conditions import SceneConditions
from zivid.sdk_version import SDKVersion
from zivid.settings import Settings
Expand Down
16 changes: 12 additions & 4 deletions modules/zivid/_calibration/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,14 @@ def centroid(self):
def pose(self):
"""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.

Pose calculation works for official Zivid calibration boards only.
An exception will be thrown if valid() is false or if the board is not supported.

For an illustration of where the origin of the pose is located, see Zivid Calibration Object:
https://support.zivid.com/en/latest/academy/applications/hand-eye/calibration-object.html

Returns:
The Pose of the top left corner (4x4 transformation matrix)
"""
Expand Down Expand Up @@ -187,6 +192,9 @@ def pose(self):
The returned pose will be positioned at the center of the marker, and have an orientation such that its z-axis
points perpendicularly into the face of the marker.

For an illustration of where the origin of the pose is located, see Zivid Calibration Object:
https://support.zivid.com/en/latest/academy/applications/hand-eye/calibration-object.html

Returns:
The Pose of the marker center (4x4 transformation matrix)
"""
Expand Down Expand Up @@ -353,8 +361,8 @@ def detect_calibration_board(source):
For further information please visit https://support.zivid.com.

Args:
source: A frame containing an image of a calibration board or a camera pointed at
a calibration board
source: A Frame containing an image of a calibration board,
or a Camera pointed at a calibration board

Raises:
TypeError: If source is not of type Camera or Frame
Expand Down Expand Up @@ -410,10 +418,10 @@ def detect_markers(frame, allowed_marker_ids, marker_dictionary):
For more information on ArUco markers specifically, see the OpenCV documentation on ArUco markers:
https://docs.opencv.org/4.x/d5/dae/tutorial_aruco_detection.html,

Frame need not contain all markers listed in allowedMarkerIds for a successful detection.
The frame need not contain all markers listed in allowedMarkerIds for a successful detection.

Args:
frame: A frame containing an image of one or several fiducial markers
frame: A Frame containing an image of one or several fiducial markers
allowed_marker_ids: List of the IDs of markers to be detected
marker_dictionary: The name of the marker dictionary to use. The name must be one of the values returned by
MarkerDictionary.valid_values()
Expand Down
Loading
Loading