Skip to content

Commit fbb0e88

Browse files
authored
Merge pull request #286 from zivid/2026-02-05-update-cpp-samples
Samples: Add a new C++ sample and update others Conclude the modifications made to which settings are used to capture in the samples. The new sample is a direct translation for the same script in python. It takes a ZDF file in input and then converts to different selected file formats, or all of the file formats if none is given. There are also options to control colorspace and if you want to use unordered point clouds.
2 parents 1c32a21 + 6ef01c1 commit fbb0e88

7 files changed

Lines changed: 417 additions & 97 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ from the camera can be used.
106106
- [ProjectImageStartAndStop](https://github.com/zivid/zivid-cpp-samples/tree/master/source/Applications/Basic/Visualization/ProjectImageStartAndStop/ProjectImageStartAndStop.cpp) - Start the Image Projection and Stop it.
107107
- [ReadPCLVis3D](https://github.com/zivid/zivid-cpp-samples/tree/master/source/Applications/Basic/Visualization/ReadPCLVis3D/ReadPCLVis3D.cpp) - Read point cloud from PCL file and visualize it.
108108
- **FileFormats**
109+
- [ConvertZDF](https://github.com/zivid/zivid-cpp-samples/tree/master/source/Applications/Basic/FileFormats/ConvertZDF/ConvertZDF.cpp) - Convert point cloud data from a ZDF file to your
110+
preferred format
109111
- [ReadIterateZDF](https://github.com/zivid/zivid-cpp-samples/tree/master/source/Applications/Basic/FileFormats/ReadIterateZDF/ReadIterateZDF.cpp) - Read point cloud data from a ZDF file, iterate through
110112
it, and extract individual points.
111113
- **Advanced**

source/Applications/Advanced/MultiCamera/MultiCameraCalibration/MultiCameraCalibration.cpp

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,25 @@ namespace
4343
};
4444

4545
// Detect checkerboard feature points from each camera capture
46-
std::vector<Detection> getDetections(const std::vector<Zivid::Camera> &connectedCameras)
46+
std::vector<Detection> getDetections(
47+
const std::vector<Zivid::Camera> &connectedCameras,
48+
const std::string &settingsPath)
4749
{
4850
auto detectionsList = std::vector<Detection>();
4951

5052
for(auto camera : connectedCameras)
5153
{
5254
const auto serial = camera.info().serialNumber().toString();
5355
std::cout << "Capturing frame with camera: " << serial << std::endl;
56+
if(settingsPath.empty())
57+
{
58+
const auto frame = Zivid::Calibration::captureCalibrationBoard(camera);
59+
}
60+
else
61+
{
62+
const auto settings = Zivid::Settings(settingsPath);
63+
const auto frame = camera.capture2D3D(settings);
64+
}
5465
const auto frame = Zivid::Calibration::captureCalibrationBoard(camera);
5566
std::cout << "Detecting checkerboard in point cloud" << std::endl;
5667
const auto detectionResult = Zivid::Calibration::detectCalibrationBoard(frame);
@@ -111,25 +122,31 @@ int main(int argc, char **argv)
111122
{
112123
try
113124
{
114-
Zivid::Application zivid;
115-
125+
bool showHelp = false;
116126
std::string transformationMatricesSavePath;
117-
118-
clipp::group cli;
119-
cli.push_back(
120-
clipp::values("Path to YAML files", transformationMatricesSavePath)
121-
% "Path where the transformation matrices YAML files will be saved");
122-
123-
if(!parse(argc, argv, cli))
127+
std::string settingsPath;
128+
auto cli =
129+
(clipp::option("-h", "--help").set(showHelp) % "Show help message",
130+
clipp::values("Path to YAML files", transformationMatricesSavePath)
131+
% "Path where the transformation matrices YAML files will be saved",
132+
clipp::option("--settings-path")
133+
& clipp::value("path", settingsPath) % "Path to the camera settings YML file");
134+
if(!clipp::parse(argc, argv, cli))
124135
{
125136
auto fmt = clipp::doc_formatting{}.alternatives_min_split_size(1).surround_labels("\"", "\"");
126137
std::cout << "SYNOPSIS:" << std::endl;
127138
std::cout << clipp::usage_lines(cli, "MultiCameraCalibration", fmt) << std::endl;
128139
std::cout << "OPTIONS:" << std::endl;
129140
std::cout << clipp::documentation(cli) << std::endl;
141+
if(showHelp)
142+
{
143+
return EXIT_SUCCESS;
144+
}
130145
throw std::runtime_error("No path provided.");
131146
}
132147

148+
Zivid::Application zivid;
149+
133150
std::cout << "Finding cameras" << std::endl;
134151
auto cameras = zivid.cameras();
135152
std::cout << "Number of cameras found: " << cameras.size() << std::endl;
@@ -142,7 +159,7 @@ int main(int argc, char **argv)
142159
std::cout << "Number of connected cameras: " << connectedCameras.size() << std::endl;
143160

144161
// detect checkerboard feature points from Capture for each camera
145-
const auto detections = getDetections(connectedCameras);
162+
const auto detections = getDetections(connectedCameras, settingsPath);
146163

147164
// Perform multi-camera calibration
148165
runMultiCameraCalibration(detections, transformationMatricesSavePath);

source/Applications/Advanced/MultiCamera/MultiCameraCalibrationFromZDF/MultiCameraCalibrationFromZDF.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,9 @@ int main(int argc, char **argv)
9292
{
9393
try
9494
{
95-
Zivid::Application zivid;
96-
95+
auto zdfFileList = std::vector<std::string>{};
9796
std::string transformationMatricesSavePath;
9897

99-
auto zdfFileList = std::vector<std::string>{};
10098
auto cli =
10199
(clipp::required("-zdf")
102100
& clipp::values("ZDF filenames", zdfFileList)
@@ -116,6 +114,7 @@ int main(int argc, char **argv)
116114
throw std::runtime_error("No files provided.");
117115
}
118116

117+
Zivid::Application zivid;
119118
// Read from ZDF and detect checkerboard feature
120119
const auto detections = getDetectionsFromZDF(zdfFileList);
121120

source/Applications/Advanced/MultiCamera/StitchByTransformation/StitchByTransformation.cpp

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ namespace
2424
using Model = Zivid::CameraInfo::Model::ValueType;
2525
switch(camera.info().model().value())
2626
{
27+
// Not using [[fallthrough]] because of clang-tidy bug: https://github.com/llvm/llvm-project/issues/47588
28+
case Model::zividOnePlusSmall: // intentional fallthrough
29+
case Model::zividOnePlusMedium: // intentional fallthrough
30+
case Model::zividOnePlusLarge: throw std::invalid_argument("Invalid camera model");
2731
case Model::zividTwo: return "Zivid_Two_M70";
2832
case Model::zividTwoL100: return "Zivid_Two_L100";
2933
case Model::zivid2PlusM130: return "Zivid_Two_Plus_M130";
@@ -33,9 +37,6 @@ namespace
3337
case Model::zivid2PlusMR60: return "Zivid_Two_Plus_MR60";
3438
case Model::zivid2PlusLR110: return "Zivid_Two_Plus_LR110";
3539
case Model::zivid3XL250: return "Zivid_Three_XL250";
36-
case Model::zividOnePlusSmall: return "Zivid_One_Plus_Small";
37-
case Model::zividOnePlusMedium: return "Zivid_One_Plus_Medium";
38-
case Model::zividOnePlusLarge: return "Zivid_One_Plus_Large";
3940

4041
default: throw std::runtime_error("Unhandled camera model: " + camera.info().model().toString());
4142
}
@@ -107,26 +108,39 @@ int main(int argc, char **argv)
107108
{
108109
try
109110
{
110-
Zivid::Application zivid;
111-
111+
bool showHelp = false;
112112
auto transformationMatricesfileList = std::vector<std::string>{};
113113
std::string stitchedPointCloudFileName;
114-
auto saveStitched = false;
115-
auto cli = (clipp::values("File Names", transformationMatricesfileList)
116-
% "List of YAML files containing the corresponding transformation matrices.",
117-
clipp::required("-o", "--output-file").set(saveStitched)
118-
% "Save the stitched point cloud to a file with this name. (.ply)")
119-
& clipp::value("Output point cloud (PLY) file name", stitchedPointCloudFileName);
120-
121-
if(!parse(argc, argv, cli))
114+
std::string settingsPath;
115+
auto cli =
116+
(clipp::option("-h", "--help").set(showHelp) % "Show help message",
117+
clipp::values("File Names", transformationMatricesfileList)
118+
% "List of YAML files containing the corresponding transformation matrices",
119+
clipp::option("-o", "--output-file")
120+
& clipp::value("Output point cloud (PLY) file name", stitchedPointCloudFileName)
121+
% "Save the stitched point cloud to a file with this name (.ply)",
122+
clipp::option("--settings-path")
123+
& clipp::value("path", settingsPath) % "Path to the camera settings YML file");
124+
125+
if(!parse(argc, argv, cli) || showHelp)
122126
{
123127
std::cout << "SYNOPSIS:" << std::endl;
124128
std::cout << clipp::usage_lines(cli, "StitchByTransformation") << std::endl;
125129
std::cout << "OPTIONS:" << std::endl;
126130
std::cout << clipp::documentation(cli) << std::endl;
127-
throw std::runtime_error("No file provided.");
131+
if(showHelp)
132+
{
133+
return EXIT_SUCCESS;
134+
}
135+
136+
throw std::runtime_error("No path provided.");
128137
}
129138

139+
Zivid::Application zivid;
140+
141+
bool pathNotProvided = settingsPath.empty();
142+
bool saveStitched = !stitchedPointCloudFileName.empty();
143+
130144
auto cameras = zivid.cameras();
131145
std::cout << "Number of cameras found: " << cameras.size() << std::endl;
132146

@@ -139,8 +153,12 @@ int main(int argc, char **argv)
139153

140154
for(auto &camera : connectedCameras)
141155
{
142-
const auto settingsPath = std::string(ZIVID_SAMPLE_DATA_DIR) + "/Settings/" + sanitizedModelName(camera)
143-
+ "_ManufacturingSpecular.yml";
156+
if(pathNotProvided)
157+
{
158+
settingsPath = std::string(ZIVID_SAMPLE_DATA_DIR) + "/Settings/" + sanitizedModelName(camera)
159+
+ "_ManufacturingSpecular.yml";
160+
}
161+
144162
std::cout << "Imaging from camera: " << camera.info().serialNumber() << std::endl;
145163
const auto frame = camera.capture2D3D(Zivid::Settings(settingsPath));
146164
const auto unorganizedPointCloud = frame.pointCloud().toUnorganizedPointCloud();

0 commit comments

Comments
 (0)