This repository contains cpp code samples for Zivid SDK v2.18.0. For tested compatibility with earlier SDK versions, please check out accompanying releases.
Contents: Tutorials | Samples | Installation | Support | License | Development
- Camera
- Applications
There are two main categories of samples: Camera and Applications. The samples in the Camera category focus only on how to use the camera. The samples in the Applications category use the output generated by the camera, such as the 3D point cloud, a 2D image or other data from the camera. These samples shows how the data from the camera can be used.
- Camera
- Basic
- Capture - Capture colored point cloud, save 2D image, save 3D ZDF, and export PLY, using the Zivid camera.
- CaptureFromFileCamera - Capture point clouds, with color, with the Zivid file camera.
- CaptureHDRCompleteSettings - Capture point clouds, with color, from the Zivid camera with fully configured settings.
- CaptureWithSettingsFromYML - Capture images and point clouds, with and without color, from the Zivid camera with settings from YML file.
- Connect - Connect to a Zivid camera using the different available methods.
- CreateFileCameraFromZDFWithDiagnostics - Capture a frame with diagnostics enabled and create a file camera from it.
- Advanced
- AllocateMemoryForPointCloudData - Two methods to copy point cloud data from GPU memory to CPU memory, to be consumed by OpenCV.
- Capture2DAnd3D - Capture 2D and 3D with the Zivid camera.
- CaptureAndPrintNormals - Capture Zivid point clouds, compute normals and print a subset.
- CaptureHalconViaGenICam - Capture and save a point cloud, with colors, using GenICam interface and Halcon C++ SDK.
- CaptureHalconViaZivid - Capture a colored point cloud with the Zivid SDK, convert it to a HALCON point cloud and save it.
- CaptureViaGenICam - Capture using the GenICam interface.
- MultiCamera
- MultiCameraCaptureInParallel - Capture point clouds with multiple cameras in parallel.
- MultiCameraCaptureSequentially - Capture point clouds with multiple cameras sequentially.
- MultiCameraCaptureSequentiallyWithInterleavedProcessing - Capture point clouds with multiple cameras sequentially with interleaved processing.
- InfoUtilOther
- CameraInfo - List connected cameras and print camera version and state information for each connected camera.
- CameraUserData - Store user data on the Zivid camera.
- CaptureWithDiagnostics - Capture a 2D+3D frame and a 2D frame from the Zivid camera with diagnostics enabled.
- CheckHealth - Poll the camera health check from a separate thread while capturing, printing statuses and values each second.
- ExploreSettingsMetaData - Recursively iterates through all leaf parameters in a Zivid camera’s settings.
- FirmwareUpdater - Update firmware on the Zivid camera.
- FrameInfo - Read frame info from the Zivid camera.
- GetCameraIntrinsics - Read intrinsic parameters from the Zivid camera (OpenCV model) or estimate them from the point cloud.
- MeasureSceneConditions - Measure ambient light in the scene and report the flickering frequency when flickering is detected.
- SettingsInfo - Read settings info from the Zivid camera.
- Warmup - Short example of a basic way to warm up the camera with specified time and capture cycle.
- ZividBenchmark - Zividbenchmark is a sample that will test the average speed of different operations on your computer.
- Network
- AutomaticNetworkConfigurationForCameras - Automatically configure the IP addresses of connected cameras to match the network of the user's PC.
- NetworkConfiguration - Uses Zivid API to change the IP address of the Zivid camera.
- Maintenance
- CorrectCameraInField - Correct the dimension trueness of a Zivid camera.
- ResetCameraInField - Reset infield correction on a camera.
- VerifyCameraInField - Check the dimension trueness of a Zivid camera.
- VerifyCameraInFieldFromZDF - Check the dimension trueness of a Zivid camera from a ZDF file.
- Basic
- Applications
- Basic
- Visualization
- CaptureAndVisualizeNormals - Capture Zivid point clouds, with color and normals, and visualize it in 3D and as a normal map.
- CaptureFromFileCameraVis3D - Capture point clouds, with color, with the Zivid file camera and visualize them.
- CaptureVis3D - Capture point clouds, with color, from the Zivid camera, and visualize it.
- CaptureWritePCLVis3D - Capture point clouds, with color, from the Zivid camera, save it to PCD file format, and visualize it.
- ProjectImageStartAndStop - Start the Image Projection and Stop it.
- ReadPCLVis3D - Read point cloud from PCL file and visualize it.
- FileFormats
- ConvertZDF - Convert point cloud data from a ZDF file to your preferred format.
- ReadIterateZDF - Read point cloud data from a ZDF file, iterate through it, and extract individual points.
- Visualization
- Advanced
- CaptureUndistort2D - Use camera intrinsics to undistort a 2D image.
- CreateDepthMap - Convert point cloud from a ZDF file to OpenCV format, extract depth map and visualize it.
- Downsample - Downsample point cloud from a ZDF file.
- GammaCorrection - Capture 2D image with gamma correction.
- MaskPointCloud - Mask point cloud from a ZDF file using the Mask API and visualize it with Zivid::Visualizer.
- Visualization
- CaptureVis3DInLoop - Capture point clouds, with color, from the Zivid camera, and visualize them in a loop.
- CaptureVis3DInLoopWithKeypressExit - Capture point clouds, with color, from the Zivid camera, and visualize them in a loop. Press 'q' to exit.
- Cuda
- CaptureAndConvertImageWithOpenCVOnCuda - Capture a 2D image with the Zivid SDK and perform RGBA to grayscale conversion on a CUDA device using OpenCV.
- CaptureAndConvertToDlpackTensorOnCuda - Capture a 2D+3D frame and build DLPack tensors directly from the Zivid DeviceArrays on the CUDA device.
- Transform
- TransformPointCloudFromMillimetersToMeters - Transform point cloud data from millimeters to meters.
- TransformPointCloudViaArucoMarker - Transform a point cloud from camera to ArUco marker coordinate frame using the marker's estimated pose.
- TransformPointCloudViaCheckerboard - Transform a point cloud from camera to checkerboard coordinate frame using the pose from the API.
- Roi
- ROIBoxViaArucoMarker - Filter the point cloud based on a ROI box given relative to the ArUco marker on a Zivid Calibration Board.
- ROIBoxViaCheckerboard - Filter the point cloud based on a ROI box given relative to the Zivid Calibration Board.
- Stitching
- StitchContinuouslyRotatingObject - Stitch point clouds from a continuously rotating object using Local Point Cloud Registration, then downsample.
- StitchUsingRobotMountedCamera - Stitch multiple point clouds captured with a robot mounted camera.
- StitchViaLocalPointCloudRegistration - Stitch two point clouds using a transformation estimated by Local Point Cloud Registration and apply Voxel Downsample.
- Barcode
- BarcodeDetector - Detect and decode linear and matrix barcodes from a 2D capture.
- HandEyeCalibration
- HandEyeCalibration - Perform Hand-Eye calibration.
- PoseConversions - Convert to/from Transformation Matrix (Rotation Matrix + Translation Vector).
- UtilizeHandEyeCalibration - Transform a data point or entire point cloud from camera to robot base frame using the Hand-Eye calibration matrix.
- MultiCamera
- MultiCameraCalibration - Generate transformation matrices to a single coordinate frame from captures by multiple connected cameras.
- MultiCameraCalibrationFromZDF - Use captures of a calibration object to generate transformation matrices to a single coordinate frame, from a ZDF files.
- StitchByTransformation - Transform point clouds from connected cameras into one coordinate frame using Multi-Camera calibration.
- StitchByTransformationFromZDF - Transform point clouds from ZDF files into one coordinate frame using Multi-Camera calibration.
- Projector
- ProjectAndFindMarker - Show a marker using the projector, capture a set of 2D images to find the marker coordinates (2D and 3D).
- ReadProjectAndCaptureImage - Read a 2D image from file and project it using the camera projector.
- ReprojectPoints - Illuminate checkerboard (Zivid Calibration Board) centers by getting the checkerboard feature points.
- Basic
Windows
Launch the Command Prompt by pressing Win + R keys on the keyboard,
then type cmd and press Enter.
Navigate to a location where you want to clone the repository, then run the following command:
git clone https://github.com/zivid/zivid-cpp-samplesConfigure the sample solution with CMake, open it in Visual Studio, build it, run it. For more information see Configure C++ Samples With CMake and Build Them in Visual Studio in Windows.
Ubuntu
Open the Terminal by pressing Ctrl + Alt + T keys on the keyboard.
Navigate to a location where you want to clone the repository, then run the following command:
git clone https://github.com/zivid/zivid-cpp-samples
cd zivid-cpp-samplesBuild the project:
mkdir build
cd build
cmake <options, see below> ../source
cmake --build .Some of the samples depend on external libraries, in particular Eigen 3,
OpenCV, PCL or HALCON. If you don't want to install those, you can
disable the samples depending on them by passing the following options,
respectively, to cmake: -DUSE_EIGEN3=OFF, -DUSE_OPENCV=OFF,
-DUSE_PCL=OFF, -DUSE_HALCON=OFF.
See Configure C++ Samples With Optional Dependencies for instructions on how to install the optional dependencies and configure the samples to use them.
The samples can now be run from the build directory, for instance like this:
./CaptureFromFileCameraVis3DZivid offers two ways of interfacing with HALCON:
- Through the Zivid SDK, utilizing the C++/C# libraries available for HALCON. We provide samples for both C++ and C#. (Recommended)
- Directly through a GenICam GenTL producer that comes with the Zivid Software.
Zivid and HALCON are compatible with Windows 10 and 11, and Ubuntu 20.04, 22.04, 24.04, 26.04.
Note:
Support for Ubuntu 18.04 is removed since SDK 2.10.
To set up and use Zivid in one of these operating systems, please follow their respective instructions on the following pages:
- Install Zivid + HALCON for Windows
- Install Zivid + HALCON for Linux
- Create a HALCON "Hello World" Program
- How to Run a HALCON Sample
- Capture Settings in HALCON
- Debug in HALCON
- HALCON Sample Videos
The following HALCON versions have been tested and confirmed to work with Zivid cameras:
- 19.05 Progress, 20.05 Progress, 21.11 Progress, 24.05 Progress, 24.11 Progress-Steady, 25.05 Progress, 25.11 Progress, 26.05 Progress
We recommend using one of the HALCON versions we have tested.
For more information about the Zivid cameras, please visit our Knowledge Base. If you run into any issues please check out Troubleshooting.
Zivid Samples are distributed under the BSD license.
To run continuous integration locally, use Docker. With Docker installed, run this command:
docker run -it -v <unix-style-repo-path>:/host -w /host/continuous-integration/linux ubuntu:20.04Where <unix-style-repo-path> is the unix-style path to the repo on
your computer. On Linux, use $PWD for this. On Windows you need to
translate the windows-style path to a unix-style one (e.g.
/c/Users/alice/Documents/zivid-cpp-samples).
Now run ./setup.sh to install dependencies. Once setup has completed,
you can run ./lint.sh && ./build.sh repeatedly to check your code.
Tip:
If your build hangs, try to increase the memory available to Docker.
