diff --git a/README.md b/README.md index a59eb61b..faadc85c 100644 --- a/README.md +++ b/README.md @@ -40,18 +40,14 @@ from the camera can be used. - **Camera** - **Basic** - - [Capture](https://github.com/zivid/zivid-cpp-samples/tree/master/source/Camera/Basic/Capture/Capture.cpp) - Capture point clouds, with color, from the Zivid camera. - - [Capture2D](https://github.com/zivid/zivid-cpp-samples/tree/master/source/Camera/Basic/Capture2D/Capture2D.cpp) - Capture 2D images from the Zivid camera. - - [CaptureAssistant](https://github.com/zivid/zivid-cpp-samples/tree/master/source/Camera/Basic/CaptureAssistant/CaptureAssistant.cpp) - Capture Assistant to capture point clouds, with color, - from the Zivid camera. + - [Capture](https://github.com/zivid/zivid-cpp-samples/tree/master/source/Camera/Basic/Capture/Capture.cpp) - Capture colored point cloud, save 2D image, save 3D ZDF, + and export PLY, using the Zivid camera. - [CaptureFromFileCamera](https://github.com/zivid/zivid-cpp-samples/tree/master/source/Camera/Basic/CaptureFromFileCamera/CaptureFromFileCamera.cpp) - Capture point clouds, with color, with the Zivid file camera. - - [CaptureHDR](https://github.com/zivid/zivid-cpp-samples/tree/master/source/Camera/Basic/CaptureHDR/CaptureHDR.cpp) - Capture HDR point clouds, with color, from the Zivid - camera. - [CaptureHDRCompleteSettings](https://github.com/zivid/zivid-cpp-samples/tree/master/source/Camera/Basic/CaptureHDRCompleteSettings/CaptureHDRCompleteSettings.cpp) - Capture point clouds, with color, from the Zivid camera with fully configured settings. - - [CaptureWithSettingsFromYML](https://github.com/zivid/zivid-cpp-samples/tree/master/source/Camera/Basic/CaptureWithSettingsFromYML/CaptureWithSettingsFromYML.cpp) - Capture point clouds, with color, from the Zivid camera, - with settings from YML file. + - [CaptureWithSettingsFromYML](https://github.com/zivid/zivid-cpp-samples/tree/master/source/Camera/Basic/CaptureWithSettingsFromYML/CaptureWithSettingsFromYML.cpp) - Capture images and point clouds, with or without color, + from the Zivid camera with settings from YML file. - **Advanced** - [AllocateMemoryForPointCloudData](https://github.com/zivid/zivid-cpp-samples/tree/master/source/Camera/Advanced/AllocateMemoryForPointCloudData/AllocateMemoryForPointCloudData.cpp) - Two methods to copy point cloud data from GPU memory to CPU memory, to be consumed by OpenCV. diff --git a/source/Applications/PointCloudTutorial.md b/source/Applications/PointCloudTutorial.md index 5a98adf2..35f16a14 100644 --- a/source/Applications/PointCloudTutorial.md +++ b/source/Applications/PointCloudTutorial.md @@ -55,10 +55,10 @@ compute device memory) and the capture and camera information. When you capture with Zivid, you get a frame in return. ([go to -source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/Capture/Capture.cpp#L22)) +source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/Capture/Capture.cpp#L25)) ``` sourceCode cpp -const auto frame = camera.capture(settings); +const auto frame = camera.capture2D3D(settings); ``` Check diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 464996ae..e86efa37 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -22,11 +22,8 @@ option(USE_HALCON "Enable samples which depend on Halcon" OFF) set(SAMPLES Camera/Basic/Capture - Camera/Basic/Capture2D - Camera/Basic/CaptureAssistant Camera/Basic/CaptureFromFileCamera Camera/Basic/CaptureWithSettingsFromYML - Camera/Basic/CaptureHDR Camera/Basic/CaptureHDRCompleteSettings Camera/Advanced/Capture2DAnd3D Camera/Advanced/CaptureHDRLoop diff --git a/source/Camera/Basic/Capture/Capture.cpp b/source/Camera/Basic/Capture/Capture.cpp index 37b1226c..4572cfa3 100644 --- a/source/Camera/Basic/Capture/Capture.cpp +++ b/source/Camera/Basic/Capture/Capture.cpp @@ -1,5 +1,5 @@ /* -Capture point clouds, with color, from the Zivid camera. +Capture colored point cloud, save 2D image, save 3D ZDF, and export PLY, using the Zivid camera. */ #include @@ -16,10 +16,18 @@ int main() auto camera = zivid.connectCamera(); std::cout << "Creating default capture settings" << std::endl; - const auto settings = Zivid::Settings(Zivid::Settings::Acquisitions{ Zivid::Settings::Acquisition{} }); + const auto settings = Zivid::Settings( + Zivid::Settings::Acquisitions{ Zivid::Settings::Acquisition{} }, + Zivid::Settings::Color( + Zivid::Settings2D(Zivid::Settings2D::Acquisitions{ Zivid::Settings2D::Acquisition{} }))); std::cout << "Capturing frame" << std::endl; - const auto frame = camera.capture(settings); + const auto frame = camera.capture2D3D(settings); + + const auto imageRGBA = frame.frame2D().value().imageRGBA(); + const auto imageFile = "ImageRGB.png"; + std::cout << "Saving 2D color image (linear RGB color space) to file: " << imageFile << std::endl; + imageRGBA.save(imageFile); const auto dataFile = "Frame.zdf"; std::cout << "Saving frame to file: " << dataFile << std::endl; diff --git a/source/Camera/Basic/Capture2D/Capture2D.cpp b/source/Camera/Basic/Capture2D/Capture2D.cpp deleted file mode 100644 index 57a69b9d..00000000 --- a/source/Camera/Basic/Capture2D/Capture2D.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* -Capture 2D images from the Zivid camera. - -The color information is provided in linear RGB and sRGB color spaces. - -Color represented in linear RGB space is suitable as input to traditional computer vision algorithms -for specialized tasks that require precise color measurements or high dynamic range. - -Color represented in sRGB color space is suitable for showing an image on a display and for machine -learning based tasks like image classification, object detection, and segmentation as most image -datasets used for training neural networks are in sRGB color space. - -More information about linear RGB and sRGB color spaces is available at: -https://support.zivid.com/en/latest/reference-articles/color-spaces-and-output-formats.html#color-spaces - -Note: While the data of the saved images is provided in linear RGB and sRGB color space, the meta data -information that indicates the color space is not saved in the .PNG. Hence, both images are likely -to be interpreted as if they were saved in sRGB color space and displayed as such. -*/ - -#include - -#include -#include - -int main() -{ - try - { - Zivid::Application zivid; - - std::cout << "Connecting to camera" << std::endl; - auto camera = zivid.connectCamera(); - - std::cout << "Configuring 2D settings" << std::endl; - // Note: The Zivid SDK supports 2D captures with a single acquisition only - const auto settings2D = - Zivid::Settings2D{ Zivid::Settings2D::Acquisitions{ Zivid::Settings2D::Acquisition{ - Zivid::Settings2D::Acquisition::ExposureTime{ std::chrono::microseconds{ 20000 } }, - Zivid::Settings2D::Acquisition::Aperture{ 9.51 }, - Zivid::Settings2D::Acquisition::Brightness{ 1.80 }, - Zivid::Settings2D::Acquisition::Gain{ 2.0 } } }, - Zivid::Settings2D::Processing::Color::Balance::Red{ 1 }, - Zivid::Settings2D::Processing::Color::Balance::Green{ 1 }, - Zivid::Settings2D::Processing::Color::Balance::Blue{ 1 } }; - - std::cout << "Capturing 2D frame" << std::endl; - const auto frame2D = camera.capture(settings2D); - - std::cout << "Getting color image (linear RGB color space)" << std::endl; - const auto image = frame2D.imageRGBA(); - - const auto pixelRow = 100; - const auto pixelCol = 50; - const auto pixelRGB = image(pixelRow, pixelCol); - std::cout << "Color at pixel (" << pixelRow << "," << pixelCol << "): R:" << std::to_string(pixelRGB.r) - << " G:" << std::to_string(pixelRGB.g) << " B:" << std::to_string(pixelRGB.b) - << " A:" << std::to_string(pixelRGB.a) << std::endl; - - const auto imageFile = "ImageRGB.png"; - std::cout << "Saving 2D color image (linear RGB color space) to file: " << imageFile << std::endl; - image.save(imageFile); - - std::cout << "Getting color image (sRGB color space)" << std::endl; - const auto imageSRGB = frame2D.imageSRGB(); - - const auto pixelSRGB = imageSRGB(pixelRow, pixelCol); - std::cout << "Color at pixel (" << pixelRow << "," << pixelCol << "): R:" << std::to_string(pixelSRGB.r) - << " G:" << std::to_string(pixelSRGB.g) << " B:" << std::to_string(pixelSRGB.b) - << " A:" << std::to_string(pixelSRGB.a) << std::endl; - - const auto imageSRGBFile = "ImageSRGB.png"; - std::cout << "Saving 2D color image (sRGB color space) to file: " << imageSRGBFile << std::endl; - imageSRGB.save(imageSRGBFile); - } - catch(const std::exception &e) - { - std::cerr << "Error: " << Zivid::toString(e) << std::endl; - std::cout << "Press enter to exit." << std::endl; - std::cin.get(); - return EXIT_FAILURE; - } - - return EXIT_SUCCESS; -} diff --git a/source/Camera/Basic/CaptureAssistant/CaptureAssistant.cpp b/source/Camera/Basic/CaptureAssistant/CaptureAssistant.cpp deleted file mode 100644 index beea00e9..00000000 --- a/source/Camera/Basic/CaptureAssistant/CaptureAssistant.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* -Capture Assistant to capture point clouds, with color, from the Zivid camera. -*/ - -#include - -#include -#include - -int main() -{ - try - { - Zivid::Application zivid; - - std::cout << "Connecting to camera" << std::endl; - auto camera = zivid.connectCamera(); - - const auto suggestSettingsParameters = Zivid::CaptureAssistant::SuggestSettingsParameters{ - Zivid::CaptureAssistant::SuggestSettingsParameters::AmbientLightFrequency::none, - Zivid::CaptureAssistant::SuggestSettingsParameters::MaxCaptureTime{ std::chrono::milliseconds{ 1200 } } - }; - - std::cout << "Running Capture Assistant with parameters:\n" << suggestSettingsParameters << std::endl; - auto settings = Zivid::CaptureAssistant::suggestSettings(camera, suggestSettingsParameters); - - std::cout << "Settings suggested by Capture Assistant:" << std::endl; - std::cout << settings.acquisitions() << std::endl; - - std::cout << "Manually configuring processing settings (Capture Assistant only suggests acquisition settings)" - << std::endl; - const auto processing = - Zivid::Settings::Processing{ Zivid::Settings::Processing::Filters::Reflection::Removal::Enabled::yes, - Zivid::Settings::Processing::Filters::Reflection::Removal::Mode::global, - Zivid::Settings::Processing::Filters::Smoothing::Gaussian::Enabled::yes, - Zivid::Settings::Processing::Filters::Smoothing::Gaussian::Sigma{ 1.5 } }; - settings.set(processing); - - std::cout << "Capturing frame" << std::endl; - const auto frame = camera.capture(settings); - - const auto dataFile = "Frame.zdf"; - std::cout << "Saving frame to file: " << dataFile << std::endl; - frame.save(dataFile); - } - catch(const std::exception &e) - { - std::cerr << "Error: " << Zivid::toString(e) << std::endl; - std::cout << "Press enter to exit." << std::endl; - std::cin.get(); - return EXIT_FAILURE; - } - - return EXIT_SUCCESS; -} diff --git a/source/Camera/Basic/CaptureFromFileCamera/CaptureFromFileCamera.cpp b/source/Camera/Basic/CaptureFromFileCamera/CaptureFromFileCamera.cpp index 0ece8fd9..0383ce30 100644 --- a/source/Camera/Basic/CaptureFromFileCamera/CaptureFromFileCamera.cpp +++ b/source/Camera/Basic/CaptureFromFileCamera/CaptureFromFileCamera.cpp @@ -34,23 +34,28 @@ int main(int argc, char **argv) Zivid::Application zivid; const auto fileCamera = - userInput ? fileCameraPath : std::string(ZIVID_SAMPLE_DATA_DIR) + "/FileCameraZivid2M70.zfc"; + userInput ? fileCameraPath : std::string(ZIVID_SAMPLE_DATA_DIR) + "/FileCameraZivid2PlusMR60.zfc"; std::cout << "Creating virtual camera using file: " << fileCamera << std::endl; auto camera = zivid.createFileCamera(fileCamera); std::cout << "Configuring settings" << std::endl; - const auto settings = Zivid::Settings{ Zivid::Settings::Acquisitions{ Zivid::Settings::Acquisition{} }, - Zivid::Settings::Processing::Filters::Smoothing::Gaussian::Enabled::yes, - Zivid::Settings::Processing::Filters::Smoothing::Gaussian::Sigma{ 1.5 }, - Zivid::Settings::Processing::Filters::Reflection::Removal::Enabled::yes, - Zivid::Settings::Processing::Filters::Reflection::Removal::Mode::global, - Zivid::Settings::Processing::Color::Balance::Red{ 1 }, - Zivid::Settings::Processing::Color::Balance::Green{ 1 }, - Zivid::Settings::Processing::Color::Balance::Blue{ 1 } }; + Zivid::Settings settings{ + Zivid::Settings::Acquisitions{ Zivid::Settings::Acquisition{} }, + Zivid::Settings::Processing::Filters::Smoothing::Gaussian::Enabled::yes, + Zivid::Settings::Processing::Filters::Smoothing::Gaussian::Sigma{ 1.5 }, + Zivid::Settings::Processing::Filters::Reflection::Removal::Enabled::yes, + Zivid::Settings::Processing::Filters::Reflection::Removal::Mode::global, + }; + Zivid::Settings2D settings2D{ Zivid::Settings2D::Acquisitions{ Zivid::Settings2D::Acquisition{} }, + Zivid::Settings2D::Processing::Color::Balance::Red{ 1 }, + Zivid::Settings2D::Processing::Color::Balance::Green{ 1 }, + Zivid::Settings2D::Processing::Color::Balance::Blue{ 1 } }; + + settings.color() = Zivid::Settings::Color{ settings2D }; std::cout << "Capturing frame" << std::endl; - const auto frame = camera.capture(settings); + const auto frame = camera.capture2D3D(settings); const auto dataFile = "Frame.zdf"; std::cout << "Saving frame to file: " << dataFile << std::endl; diff --git a/source/Camera/Basic/CaptureHDR/CaptureHDR.cpp b/source/Camera/Basic/CaptureHDR/CaptureHDR.cpp deleted file mode 100644 index 7b95796d..00000000 --- a/source/Camera/Basic/CaptureHDR/CaptureHDR.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* -Capture HDR point clouds, with color, from the Zivid camera. - -For scenes with high dynamic range we combine multiple acquisitions to get an HDR point cloud. -*/ - -#include - -#include - -int main() -{ - try - { - Zivid::Application zivid; - - std::cout << "Connecting to camera" << std::endl; - auto camera = zivid.connectCamera(); - - std::cout << "Configuring settings" << std::endl; - Zivid::Settings settings; - for(const auto aperture : { 11.31, 5.66, 2.83 }) - { - std::cout << "Adding acquisition with aperture = " << aperture << std::endl; - const auto acquisitionSettings = Zivid::Settings::Acquisition{ - Zivid::Settings::Acquisition::Aperture{ aperture }, - }; - settings.acquisitions().emplaceBack(acquisitionSettings); - } - - std::cout << "Capturing frame (HDR)" << std::endl; - const auto frame = camera.capture(settings); - - const auto dataFile = "Frame.zdf"; - std::cout << "Saving frame to file: " << dataFile << std::endl; - frame.save(dataFile); - } - catch(const std::exception &e) - { - std::cerr << "Error: " << Zivid::toString(e) << std::endl; - std::cout << "Press enter to exit." << std::endl; - std::cin.get(); - return EXIT_FAILURE; - } - - return EXIT_SUCCESS; -} diff --git a/source/Camera/Basic/CaptureHDRCompleteSettings/CaptureHDRCompleteSettings.cpp b/source/Camera/Basic/CaptureHDRCompleteSettings/CaptureHDRCompleteSettings.cpp index 349d37fc..ab6106f1 100644 --- a/source/Camera/Basic/CaptureHDRCompleteSettings/CaptureHDRCompleteSettings.cpp +++ b/source/Camera/Basic/CaptureHDRCompleteSettings/CaptureHDRCompleteSettings.cpp @@ -110,49 +110,73 @@ int main() auto camera = zivid.connectCamera(); std::cout << "Configuring settings for capture:" << std::endl; + Zivid::Settings2D settings2D{ + Zivid::Settings2D::Sampling::Color::rgb, + Zivid::Settings2D::Sampling::Pixel::all, + + Zivid::Settings2D::Processing::Color::Balance::Blue{ 1.0 }, + Zivid::Settings2D::Processing::Color::Balance::Green{ 1.0 }, + Zivid::Settings2D::Processing::Color::Balance::Red{ 1.0 }, + Zivid::Settings2D::Processing::Color::Gamma{ 1.0 }, + + Zivid::Settings2D::Processing::Color::Experimental::Mode::automatic, + }; + Zivid::Settings settings{ + Zivid::Settings::Color{ settings2D }, + Zivid::Settings::Engine::phase, - Zivid::Settings::Sampling::Color::rgb, + Zivid::Settings::RegionOfInterest::Box::Enabled::yes, Zivid::Settings::RegionOfInterest::Box::PointO{ 1000, 1000, 1000 }, Zivid::Settings::RegionOfInterest::Box::PointA{ 1000, -1000, 1000 }, Zivid::Settings::RegionOfInterest::Box::PointB{ -1000, 1000, 1000 }, Zivid::Settings::RegionOfInterest::Box::Extents{ -1000, 1000 }, + Zivid::Settings::RegionOfInterest::Depth::Enabled::yes, Zivid::Settings::RegionOfInterest::Depth::Range{ 200, 2000 }, - Zivid::Settings::Processing::Filters::Smoothing::Gaussian::Enabled::yes, - Zivid::Settings::Processing::Filters::Smoothing::Gaussian::Sigma{ 1.5 }, + + Zivid::Settings::Processing::Filters::Cluster::Removal::Enabled::yes, + Zivid::Settings::Processing::Filters::Cluster::Removal::MaxNeighborDistance{ 10 }, + Zivid::Settings::Processing::Filters::Cluster::Removal::MinArea{ 100 }, + + Zivid::Settings::Processing::Filters::Hole::Repair::Enabled::yes, + Zivid::Settings::Processing::Filters::Hole::Repair::HoleSize{ 0.2 }, + Zivid::Settings::Processing::Filters::Hole::Repair::Strictness{ 1 }, + Zivid::Settings::Processing::Filters::Noise::Removal::Enabled::yes, Zivid::Settings::Processing::Filters::Noise::Removal::Threshold{ 7.0 }, + Zivid::Settings::Processing::Filters::Noise::Suppression::Enabled::yes, Zivid::Settings::Processing::Filters::Noise::Repair::Enabled::yes, + Zivid::Settings::Processing::Filters::Outlier::Removal::Enabled::yes, Zivid::Settings::Processing::Filters::Outlier::Removal::Threshold{ 5.0 }, + Zivid::Settings::Processing::Filters::Reflection::Removal::Enabled::yes, Zivid::Settings::Processing::Filters::Reflection::Removal::Mode::global, - Zivid::Settings::Processing::Filters::Cluster::Removal::Enabled::yes, - Zivid::Settings::Processing::Filters::Cluster::Removal::MaxNeighborDistance{ 10 }, - Zivid::Settings::Processing::Filters::Cluster::Removal::MinArea{ 100 }, + + Zivid::Settings::Processing::Filters::Smoothing::Gaussian::Enabled::yes, + Zivid::Settings::Processing::Filters::Smoothing::Gaussian::Sigma{ 1.5 }, + Zivid::Settings::Processing::Filters::Experimental::ContrastDistortion::Correction::Enabled::yes, Zivid::Settings::Processing::Filters::Experimental::ContrastDistortion::Correction::Strength{ 0.4 }, + Zivid::Settings::Processing::Filters::Experimental::ContrastDistortion::Removal::Enabled::no, Zivid::Settings::Processing::Filters::Experimental::ContrastDistortion::Removal::Threshold{ 0.5 }, - Zivid::Settings::Processing::Filters::Hole::Repair::Enabled::yes, - Zivid::Settings::Processing::Filters::Hole::Repair::HoleSize{ 0.2 }, - Zivid::Settings::Processing::Filters::Hole::Repair::Strictness{ 1 }, + Zivid::Settings::Processing::Resampling::Mode::upsample2x2, - Zivid::Settings::Processing::Color::Balance::Red{ 1.0 }, - Zivid::Settings::Processing::Color::Balance::Green{ 1.0 }, - Zivid::Settings::Processing::Color::Balance::Blue{ 1.0 }, - Zivid::Settings::Processing::Color::Gamma{ 1.0 }, - Zivid::Settings::Processing::Color::Experimental::Mode::automatic + + Zivid::Settings::Diagnostics::Enabled::no, }; + setSamplingPixel(settings, camera); std::cout << settings << std::endl; std::cout << "Configuring base acquisition with settings same for all HDR acquisition:" << std::endl; const auto baseAcquisition = Zivid::Settings::Acquisition{}; std::cout << baseAcquisition << std::endl; + const auto baseAquisition2D = Zivid::Settings2D::Acquisition{}; std::cout << "Configuring acquisition settings different for all HDR acquisitions" << std::endl; auto exposureValues = getExposureValues(camera); @@ -174,9 +198,15 @@ int main() Zivid::Settings::Acquisition::Brightness{ brightness.at(i) }); settings.acquisitions().emplaceBack(acquisitionSettings); } + const auto acquisitionSettings2D = baseAquisition2D.copyWith( + Zivid::Settings2D::Acquisition::Aperture{ 2.83 }, + Zivid::Settings2D::Acquisition::ExposureTime{ microseconds{ 10000 } }, + Zivid::Settings2D::Acquisition::Brightness{ 1.8 }, + Zivid::Settings2D::Acquisition::Gain{ 1.0 }); + settings.color().value().acquisitions().emplaceBack(acquisitionSettings2D); std::cout << "Capturing frame (HDR)" << std::endl; - const auto frame = camera.capture(settings); + const auto frame = camera.capture2D3D(settings); std::cout << "Complete settings used:" << std::endl; std::cout << frame.settings() << std::endl; diff --git a/source/Camera/Basic/CaptureTutorial.md b/source/Camera/Basic/CaptureTutorial.md index edd72525..0589b156 100644 --- a/source/Camera/Basic/CaptureTutorial.md +++ b/source/Camera/Basic/CaptureTutorial.md @@ -13,7 +13,7 @@ tutorial see: [**Initialize**](#Initialize) | [**Connect**](#Connect) | [**Configure**](#Configure) | -[**Capture**](#Capture) | +[**Capture**](#Capture-2D3D) | [**Save**](#Save) | [**Multithreading**](#Multithreading) | [**Conclusion**](#Conclusion) @@ -27,18 +27,6 @@ tutorial see: This tutorial describes how to use the Zivid SDK to capture point clouds and 2D images. -For MATLAB see [Zivid Capture Tutorial for -MATLAB](https://github.com/zivid/zivid-matlab-samples/blob/master/source/Camera/Basic/CaptureTutorial.md). - ------ - -Tip: - -> If you prefer watching a video, our webinar [Making 3D captures easy - -> A tour of Zivid Studio and Zivid -> SDK](https://www.zivid.com/webinars-page?wchannelid=ffpqbqc7sg&wmediaid=ce68dbjldk) -> covers the same content as the Capture Tutorial. - **Prerequisites** - Install [Zivid @@ -128,7 +116,7 @@ source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Ba ``` sourceCode cpp const auto fileCamera = - userInput ? fileCameraPath : std::string(ZIVID_SAMPLE_DATA_DIR) + "/FileCameraZivid2M70.zfc"; + userInput ? fileCameraPath : std::string(ZIVID_SAMPLE_DATA_DIR) + "/FileCameraZivid2PlusMR60.zfc"; ``` ([go to @@ -142,17 +130,21 @@ The acquisition settings should be initialized like shown below, but you are free to alter the processing settings. ([go to -source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/CaptureFromFileCamera/CaptureFromFileCamera.cpp#L43-L50)) +source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/CaptureFromFileCamera/CaptureFromFileCamera.cpp#L43-L55)) ``` sourceCode cpp -const auto settings = Zivid::Settings{ Zivid::Settings::Acquisitions{ Zivid::Settings::Acquisition{} }, - Zivid::Settings::Processing::Filters::Smoothing::Gaussian::Enabled::yes, - Zivid::Settings::Processing::Filters::Smoothing::Gaussian::Sigma{ 1.5 }, - Zivid::Settings::Processing::Filters::Reflection::Removal::Enabled::yes, - Zivid::Settings::Processing::Filters::Reflection::Removal::Mode::global, - Zivid::Settings::Processing::Color::Balance::Red{ 1 }, - Zivid::Settings::Processing::Color::Balance::Green{ 1 }, - Zivid::Settings::Processing::Color::Balance::Blue{ 1 } }; +Zivid::Settings settings{ + Zivid::Settings::Acquisitions{ Zivid::Settings::Acquisition{} }, + Zivid::Settings::Processing::Filters::Smoothing::Gaussian::Enabled::yes, + Zivid::Settings::Processing::Filters::Smoothing::Gaussian::Sigma{ 1.5 }, + Zivid::Settings::Processing::Filters::Reflection::Removal::Enabled::yes, + Zivid::Settings::Processing::Filters::Reflection::Removal::Mode::global, +}; +Zivid::Settings2D settings2D{ Zivid::Settings2D::Acquisitions{ Zivid::Settings2D::Acquisition{} }, + Zivid::Settings2D::Processing::Color::Balance::Red{ 1 }, + Zivid::Settings2D::Processing::Color::Balance::Green{ 1 }, + Zivid::Settings2D::Processing::Color::Balance::Blue{ 1 } }; +settings.color() = Zivid::Settings::Color{ settings2D }; ``` You can read more about the file camera option in [File @@ -166,45 +158,44 @@ As with all cameras there are settings that can be configured. The recommendation is to use [Presets](https://support.zivid.com/latest/reference-articles/presets-settings.html) -available in Zivid Studio and as .yml files (see `load_yml_label` -below). Alternatively, you can use our Capture Assistant, or you may -configure the settings manually. +available in Zivid Studio and as .yml files (see below). Presets are +designed to work well for most cases right away, making them a great +starting point. If needed, you can easily fine-tune the settings for +better results. You can edit the YAML files in any text editor or code +the settings manually. -### Capture Assistant +### Load -It can be difficult to know what settings to configure. Luckily we have -the Capture Assistant. This is available in the Zivid SDK to help -configure camera settings. +You can export camera settings to .yml files from Zivid Studio. These +can be loaded and applied in the API. ([go to -source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/CaptureAssistant/CaptureAssistant.cpp#L19-L25)) +source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/CaptureHDRCompleteSettings/CaptureHDRCompleteSettings.cpp#L218-L223)) ``` sourceCode cpp -const auto suggestSettingsParameters = Zivid::CaptureAssistant::SuggestSettingsParameters{ - Zivid::CaptureAssistant::SuggestSettingsParameters::AmbientLightFrequency::none, - Zivid::CaptureAssistant::SuggestSettingsParameters::MaxCaptureTime{ std::chrono::milliseconds{ 1200 } } -}; -std::cout << "Running Capture Assistant with parameters:\n" << suggestSettingsParameters << std::endl; -auto settings = Zivid::CaptureAssistant::suggestSettings(camera, suggestSettingsParameters); +const auto settingsFile = "Settings.yml"; +std::cout << "Loading settings from file: " << settingsFile << std::endl; +const auto settingsFromFile = Zivid::Settings(settingsFile); ``` -There are only two parameters to configure with Capture Assistant: - -1. **Maximum Capture Time** in number of milliseconds. - 1. Minimum capture time is 200 ms. This allows only one - acquisition. - 2. The algorithm will combine multiple acquisitions if the budget - allows. - 3. The algorithm will attempt to cover as much of the dynamic range - in the scene as possible. - 4. A maximum capture time of more than 1 second will get good - coverage in most scenarios. -2. **Ambient light compensation** - 1. May restrict capture assistant to exposure periods that are - multiples of the ambient light period. - 2. 60Hz is found in Japan, Americas, Taiwan, South Korea and - Philippines. - 3. 50Hz is common in the rest of the world. +### Save + +You can also save settings to .yml file. + +([go to +source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/CaptureHDRCompleteSettings/CaptureHDRCompleteSettings.cpp#L218-L220)) + +``` sourceCode cpp +const auto settingsFile = "Settings.yml"; +std::cout << "Saving settings to file: " << settingsFile << std::endl; +settings.save(settingsFile); +``` + +----- + +Caution\!: + +> Zivid settings files must use .yml file extension ( not .yaml). ### Manual configuration @@ -214,15 +205,18 @@ Settings](https://support.zivid.com/latest/reference-articles/camera-settings.ht Then, the next step it's [Capturing High Quality Point Clouds](https://support.zivid.com/latest/academy/camera/capturing-high-quality-point-clouds.html) -#### Single Acquisition +#### Single 2D and 3D Acquisition - Default settings We can create settings for a single acquisition capture. ([go to -source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/Capture/Capture.cpp#L19)) +source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/Capture/Capture.cpp#L19-L22)) ``` sourceCode cpp -const auto settings = Zivid::Settings(Zivid::Settings::Acquisitions{ Zivid::Settings::Acquisition{} }); +const auto settings = Zivid::Settings( + Zivid::Settings::Acquisitions{ Zivid::Settings::Acquisition{} }, + Zivid::Settings::Color( + Zivid::Settings2D(Zivid::Settings2D::Acquisitions{ Zivid::Settings2D::Acquisition{} }))); ``` #### Multi Acquisition HDR @@ -231,11 +225,11 @@ We may also create settings to be used in a multi-acquisition HDR capture. ([go to -source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/CaptureHDR/CaptureHDR.cpp#L21-L29)) +source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Advanced/CaptureHDRPrintNormals/CaptureHDRPrintNormals.cpp#L39-L47)) ``` sourceCode cpp Zivid::Settings settings; -for(const auto aperture : { 11.31, 5.66, 2.83 }) +for(const auto aperture : { 9.57, 4.76, 2.59 }) { std::cout << "Adding acquisition with aperture = " << aperture << std::endl; const auto acquisitionSettings = Zivid::Settings::Acquisition{ @@ -248,148 +242,189 @@ for(const auto aperture : { 11.31, 5.66, 2.83 }) Fully configured settings are demonstrated below. ([go to -source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/CaptureHDRCompleteSettings/CaptureHDRCompleteSettings.cpp#L112-L176)) +source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/CaptureHDRCompleteSettings/CaptureHDRCompleteSettings.cpp#L112-L206)) ``` sourceCode cpp std::cout << "Configuring settings for capture:" << std::endl; -Zivid::Settings settings{ - Zivid::Settings::Engine::phase, - Zivid::Settings::Sampling::Color::rgb, - Zivid::Settings::RegionOfInterest::Box::Enabled::yes, - Zivid::Settings::RegionOfInterest::Box::PointO{ 1000, 1000, 1000 }, - Zivid::Settings::RegionOfInterest::Box::PointA{ 1000, -1000, 1000 }, - Zivid::Settings::RegionOfInterest::Box::PointB{ -1000, 1000, 1000 }, - Zivid::Settings::RegionOfInterest::Box::Extents{ -1000, 1000 }, - Zivid::Settings::RegionOfInterest::Depth::Enabled::yes, - Zivid::Settings::RegionOfInterest::Depth::Range{ 200, 2000 }, - Zivid::Settings::Processing::Filters::Smoothing::Gaussian::Enabled::yes, - Zivid::Settings::Processing::Filters::Smoothing::Gaussian::Sigma{ 1.5 }, - Zivid::Settings::Processing::Filters::Noise::Removal::Enabled::yes, - Zivid::Settings::Processing::Filters::Noise::Removal::Threshold{ 7.0 }, - Zivid::Settings::Processing::Filters::Noise::Suppression::Enabled::yes, - Zivid::Settings::Processing::Filters::Noise::Repair::Enabled::yes, - Zivid::Settings::Processing::Filters::Outlier::Removal::Enabled::yes, - Zivid::Settings::Processing::Filters::Outlier::Removal::Threshold{ 5.0 }, - Zivid::Settings::Processing::Filters::Reflection::Removal::Enabled::yes, - Zivid::Settings::Processing::Filters::Reflection::Removal::Mode::global, - Zivid::Settings::Processing::Filters::Cluster::Removal::Enabled::yes, - Zivid::Settings::Processing::Filters::Cluster::Removal::MaxNeighborDistance{ 10 }, - Zivid::Settings::Processing::Filters::Cluster::Removal::MinArea{ 100 }, - Zivid::Settings::Processing::Filters::Experimental::ContrastDistortion::Correction::Enabled::yes, - Zivid::Settings::Processing::Filters::Experimental::ContrastDistortion::Correction::Strength{ 0.4 }, - Zivid::Settings::Processing::Filters::Experimental::ContrastDistortion::Removal::Enabled::no, - Zivid::Settings::Processing::Filters::Experimental::ContrastDistortion::Removal::Threshold{ 0.5 }, - Zivid::Settings::Processing::Filters::Hole::Repair::Enabled::yes, - Zivid::Settings::Processing::Filters::Hole::Repair::HoleSize{ 0.2 }, - Zivid::Settings::Processing::Filters::Hole::Repair::Strictness{ 1 }, - Zivid::Settings::Processing::Resampling::Mode::upsample2x2, - Zivid::Settings::Processing::Color::Balance::Red{ 1.0 }, - Zivid::Settings::Processing::Color::Balance::Green{ 1.0 }, - Zivid::Settings::Processing::Color::Balance::Blue{ 1.0 }, - Zivid::Settings::Processing::Color::Gamma{ 1.0 }, - Zivid::Settings::Processing::Color::Experimental::Mode::automatic -}; -setSamplingPixel(settings, camera); -std::cout << settings << std::endl; -std::cout << "Configuring base acquisition with settings same for all HDR acquisition:" << std::endl; -const auto baseAcquisition = Zivid::Settings::Acquisition{}; -std::cout << baseAcquisition << std::endl; - -std::cout << "Configuring acquisition settings different for all HDR acquisitions" << std::endl; -auto exposureValues = getExposureValues(camera); -const std::vector aperture = std::get<0>(exposureValues); -const std::vector gain = std::get<1>(exposureValues); -const std::vector exposureTime = std::get<2>(exposureValues); -const std::vector brightness = std::get<3>(exposureValues); -for(size_t i = 0; i < aperture.size(); ++i) -{ - std::cout << "Acquisition " << i + 1 << ":" << std::endl; - std::cout << " Exposure Time: " << exposureTime.at(i).count() << std::endl; - std::cout << " Aperture: " << aperture.at(i) << std::endl; - std::cout << " Gain: " << gain.at(i) << std::endl; - std::cout << " Brightness: " << brightness.at(i) << std::endl; - const auto acquisitionSettings = baseAcquisition.copyWith( - Zivid::Settings::Acquisition::Aperture{ aperture.at(i) }, - Zivid::Settings::Acquisition::Gain{ gain.at(i) }, - Zivid::Settings::Acquisition::ExposureTime{ exposureTime.at(i) }, - Zivid::Settings::Acquisition::Brightness{ brightness.at(i) }); - settings.acquisitions().emplaceBack(acquisitionSettings); -} +Zivid::Settings2D settings2D{ + Zivid::Settings2D::Sampling::Color::rgb, + Zivid::Settings2D::Sampling::Pixel::all, +Zivid::Settings2D::Processing::Color::Balance::Blue{ 1.0 }, +Zivid::Settings2D::Processing::Color::Balance::Green{ 1.0 }, +Zivid::Settings2D::Processing::Color::Balance::Red{ 1.0 }, +Zivid::Settings2D::Processing::Color::Gamma{ 1.0 }, + +Zivid::Settings2D::Processing::Color::Experimental::Mode::automatic, ``` -#### 2D Settings +> }; +> +> - Zivid::Settings settings{ +> Zivid::Settings::Color{ settings2D }, +> +> Zivid::Settings::Engine::phase, +> +> Zivid::Settings::RegionOfInterest::Box::Enabled::yes, +> Zivid::Settings::RegionOfInterest::Box::PointO{ 1000, 1000, 1000 +> }, Zivid::Settings::RegionOfInterest::Box::PointA{ 1000, -1000, +> 1000 }, Zivid::Settings::RegionOfInterest::Box::PointB{ -1000, +> 1000, 1000 }, Zivid::Settings::RegionOfInterest::Box::Extents{ +> -1000, 1000 }, +> +> Zivid::Settings::RegionOfInterest::Depth::Enabled::yes, +> Zivid::Settings::RegionOfInterest::Depth::Range{ 200, 2000 }, +> +> Zivid::Settings::Processing::Filters::Cluster::Removal::Enabled::yes, +> Zivid::Settings::Processing::Filters::Cluster::Removal::MaxNeighborDistance{ +> 10 }, +> Zivid::Settings::Processing::Filters::Cluster::Removal::MinArea{ +> 100 }, +> +> Zivid::Settings::Processing::Filters::Hole::Repair::Enabled::yes, +> Zivid::Settings::Processing::Filters::Hole::Repair::HoleSize{ 0.2 +> }, Zivid::Settings::Processing::Filters::Hole::Repair::Strictness{ +> 1 }, +> +> Zivid::Settings::Processing::Filters::Noise::Removal::Enabled::yes, +> Zivid::Settings::Processing::Filters::Noise::Removal::Threshold{ +> 7.0 }, +> +> Zivid::Settings::Processing::Filters::Noise::Suppression::Enabled::yes, +> Zivid::Settings::Processing::Filters::Noise::Repair::Enabled::yes, +> +> Zivid::Settings::Processing::Filters::Outlier::Removal::Enabled::yes, +> Zivid::Settings::Processing::Filters::Outlier::Removal::Threshold{ +> 5.0 }, +> +> Zivid::Settings::Processing::Filters::Reflection::Removal::Enabled::yes, +> Zivid::Settings::Processing::Filters::Reflection::Removal::Mode::global, +> +> Zivid::Settings::Processing::Filters::Smoothing::Gaussian::Enabled::yes, +> Zivid::Settings::Processing::Filters::Smoothing::Gaussian::Sigma{ +> 1.5 }, +> +> Zivid::Settings::Processing::Filters::Experimental::ContrastDistortion::Correction::Enabled::yes, +> Zivid::Settings::Processing::Filters::Experimental::ContrastDistortion::Correction::Strength{ +> 0.4 }, +> +> Zivid::Settings::Processing::Filters::Experimental::ContrastDistortion::Removal::Enabled::no, +> Zivid::Settings::Processing::Filters::Experimental::ContrastDistortion::Removal::Threshold{ +> 0.5 }, +> +> Zivid::Settings::Processing::Resampling::Mode::upsample2x2, +> +> Zivid::Settings::Diagnostics::Enabled::no, +> +> }; +> +> setSamplingPixel(settings, camera); std::cout \<\< settings \<\< +> std::endl; std::cout \<\< "Configuring base acquisition with settings +> same for all HDR acquisition:" \<\< std::endl; const auto +> baseAcquisition = Zivid::Settings::Acquisition{}; std::cout \<\< +> baseAcquisition \<\< std::endl; const auto baseAquisition2D = +> Zivid::Settings2D::Acquisition{}; +> +> std::cout \<\< "Configuring acquisition settings different for all HDR +> acquisitions" \<\< std::endl; auto exposureValues = +> getExposureValues(camera); const std::vector\ aperture = +> std::get\<0\>(exposureValues); const std::vector\ gain = +> std::get\<1\>(exposureValues); const +> std::vector\ exposureTime = +> std::get\<2\>(exposureValues); const std::vector\ brightness +> = std::get\<3\>(exposureValues); for(size\_t i = 0; i \< +> aperture.size(); ++i) { std::cout \<\< "Acquisition " \<\< i + 1 \<\< +> ":" \<\< std::endl; std::cout \<\< " Exposure Time: " \<\< +> exposureTime.at(i).count() \<\< std::endl; std::cout \<\< " Aperture: +> " \<\< aperture.at(i) \<\< std::endl; std::cout \<\< " Gain: " \<\< +> gain.at(i) \<\< std::endl; std::cout \<\< " Brightness: " \<\< +> brightness.at(i) \<\< std::endl; const auto acquisitionSettings = +> baseAcquisition.copyWith( Zivid::Settings::Acquisition::Aperture{ +> aperture.at(i) }, Zivid::Settings::Acquisition::Gain{ gain.at(i) }, +> Zivid::Settings::Acquisition::ExposureTime{ exposureTime.at(i) }, +> Zivid::Settings::Acquisition::Brightness{ brightness.at(i) }); +> settings.acquisitions().emplaceBack(acquisitionSettings); } const auto +> acquisitionSettings2D = baseAquisition2D.copyWith( +> Zivid::Settings2D::Acquisition::Aperture{ 2.83 }, +> Zivid::Settings2D::Acquisition::ExposureTime{ microseconds{ 10000 } }, +> Zivid::Settings2D::Acquisition::Brightness{ 1.8 }, +> Zivid::Settings2D::Acquisition::Gain{ 1.0 }); +> settings.color().value().acquisitions().emplaceBack(acquisitionSettings2D); + +## Capture 2D3D + +Now we can capture a 2D and 3D image (point cloud with color). Whether +there is a single acquisition or multiple acquisitions (HDR) is given by +the number of `acquisitions` in `settings`. -It is possible to only capture a 2D image. This is faster than a 3D -capture. 2D settings are configured as follows. +([go to +source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/Capture/Capture.cpp#L25)) + +``` sourceCode cpp +const auto frame = camera.capture2D3D(settings); +``` + +The `Zivid::Frame` contains the point cloud, the color image, the +capture, and the camera information (all of which are stored on the +compute device memory). + +### Capture 3D + +If we only want to capture 3D, the points cloud without color, we can do +so via the `capture3D` API. ([go to -source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/Capture2D/Capture2D.cpp#L37-L45)) +source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/CaptureWithSettingsFromYML/CaptureWithSettingsFromYML.cpp#L72)) ``` sourceCode cpp -const auto settings2D = - Zivid::Settings2D{ Zivid::Settings2D::Acquisitions{ Zivid::Settings2D::Acquisition{ - Zivid::Settings2D::Acquisition::ExposureTime{ std::chrono::microseconds{ 20000 } }, - Zivid::Settings2D::Acquisition::Aperture{ 9.51 }, - Zivid::Settings2D::Acquisition::Brightness{ 1.80 }, - Zivid::Settings2D::Acquisition::Gain{ 2.0 } } }, - Zivid::Settings2D::Processing::Color::Balance::Red{ 1 }, - Zivid::Settings2D::Processing::Color::Balance::Green{ 1 }, - Zivid::Settings2D::Processing::Color::Balance::Blue{ 1 } }; +const auto frame3D = camera.capture3D(settings); ``` -### Load +### Capture 2D -Zivid Studio can store the current settings to .yml files. These can be -read and applied in the API. You may find it easier to modify the -settings in these (human-readable) yaml-files in your preferred editor. -Check out -[Presets](https://support.zivid.com/latest/reference-articles/presets-settings.html) -for recommended .yml files tuned for your application. +If we only want to capture a 2D image, which is faster than 3D, we can +do so via the `capture2D` API. ([go to -source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/CaptureHDRCompleteSettings/CaptureHDRCompleteSettings.cpp#L188-L193)) +source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/CaptureWithSettingsFromYML/CaptureWithSettingsFromYML.cpp#L52)) ``` sourceCode cpp -const auto settingsFile = "Settings.yml"; -std::cout << "Loading settings from file: " << settingsFile << std::endl; -const auto settingsFromFile = Zivid::Settings(settingsFile); +const auto frame2D = camera.capture2D(settings); ``` -### Save +## Save -You can also save settings to .yml file. +We can now save our results. ([go to -source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/CaptureHDRCompleteSettings/CaptureHDRCompleteSettings.cpp#L188-L190)) +source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/Capture/Capture.cpp#L32-L34)) ``` sourceCode cpp -const auto settingsFile = "Settings.yml"; -std::cout << "Saving settings to file: " << settingsFile << std::endl; -settings.save(settingsFile); +const auto dataFile = "Frame.zdf"; +frame.save(dataFile); ``` ----- -Caution\!: +Tip: -> Zivid settings files must use .yml file extension ( not .yaml). +> You can open and view `Frame.zdf` file in [Zivid +> Studio](https://support.zivid.com/latest//getting-started/studio-guide.html). -## Capture +### Export -Now we can capture a 3D image. Whether there is a single acquisition or -multiple acquisitions (HDR) is given by the number of `acquisitions` in -`settings`. +In the next code example, the point cloud is exported to the .ply +format. For other exporting options, see [Point +Cloud](https://support.zivid.com/latest//reference-articles/point-cloud-structure-and-output-formats.html) +for a list of supported formats. ([go to -source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/Capture/Capture.cpp#L22)) +source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/Capture/Capture.cpp#L36-L38)) ``` sourceCode cpp -const auto frame = camera.capture(settings); +const auto dataFilePLY = "PointCloud.ply"; +frame.save(dataFilePLY); ``` -The `Zivid::Frame` contains the point cloud and color image (stored on -compute device memory) and the capture and camera information. - ### Load Once saved, the frame can be loaded from a ZDF file. @@ -403,82 +438,64 @@ std::cout << "Reading ZDF frame from file: " << dataFile << std::endl; const auto frame = Zivid::Frame(dataFile); ``` -Saving to a ZDF file is addressed later in the tutorial. - -### Capture 2D +### Save 2D -If we only want to capture a 2D image, which is faster than 3D, we can -do so via the 2D API. +We can get the 2D color image from `Frame2D`, which is part of the +`Frame` object, obtained from `capture2D3D()`. -([go to -source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/Capture2D/Capture2D.cpp#L48)) +([go to source]()) ``` sourceCode cpp -const auto frame2D = camera.capture(settings2D); +const auto image2D = frame.frame2D().value().imageBGRA(); ``` -## Save - -We can now save our results. +We can get 2D color image directly from the point cloud. This image will +have the same resolution as the point cloud. -([go to -source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/Capture/Capture.cpp#L24-L26)) +([go to source]()) ``` sourceCode cpp -const auto dataFile = "Frame.zdf"; -frame.save(dataFile); +const auto pointCloud = frame.pointCloud(); +const auto image2DInPointCloudResolution = pointCloud.copyImageRGBA(); ``` ------ - -Tip: - -> You can open and view `Frame.zdf` file in [Zivid -> Studio](https://support.zivid.com/latest//getting-started/studio-guide.html). - -### Export - -The API detects which format to use. See [Point -Cloud](https://support.zivid.com/latest//reference-articles/point-cloud-structure-and-output-formats.html) -for a list of supported formats. For example, we can export the point -cloud to .ply format. +2D captures also produce 2D color images in linear RGB and sRGB color +space. ([go to -source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/Capture/Capture.cpp#L28-L30)) +source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/Capture/Capture.cpp#L27)) ``` sourceCode cpp -const auto dataFilePLY = "PointCloud.ply"; -frame.save(dataFilePLY); +const auto imageRGBA = frame.frame2D().value().imageRGBA(); +.. tab-item:: sRGB ``` -### Save 2D - -We can get 2D color image from a 3D capture. - -([go to source]()) +([go to +source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/CaptureWithSettingsFromYML/CaptureWithSettingsFromYML.cpp#L54)) ``` sourceCode cpp -const auto image = pointCloud.copyImageRGBA(); +const auto imageSRGB = frame2D.imageSRGB(); ``` -2D captures also produce 2D color images. +Then, we can save the 2D image in linear RGB or sRGB color space. ([go to -source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/Capture2D/Capture2D.cpp#L51)) +source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/Capture/Capture.cpp#L28-L30)) ``` sourceCode cpp -const auto image = frame2D.imageRGBA(); +const auto imageFile = "ImageRGB.png"; +std::cout << "Saving 2D color image (linear RGB color space) to file: " << imageFile << std::endl; +imageRGBA.save(imageFile); +.. tab-item:: sRGB ``` -Then, we can save the 2D image. - ([go to -source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/Capture2D/Capture2D.cpp#L60-L62)) +source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/CaptureWithSettingsFromYML/CaptureWithSettingsFromYML.cpp#L55-L57)) ``` sourceCode cpp -const auto imageFile = "ImageRGB.png"; -std::cout << "Saving 2D color image (linear RGB color space) to file: " << imageFile << std::endl; -image.save(imageFile); +const auto imageFile = "ImageSRGB.png"; +std::cout << "Saving 2D color image (sRGB color space) to file: " << imageFile << std::endl; +imageSRGB.save(imageFile); ``` ## Multithreading diff --git a/source/Camera/Basic/CaptureWithSettingsFromYML/CaptureWithSettingsFromYML.cpp b/source/Camera/Basic/CaptureWithSettingsFromYML/CaptureWithSettingsFromYML.cpp index c5aa36bb..c4ba2811 100644 --- a/source/Camera/Basic/CaptureWithSettingsFromYML/CaptureWithSettingsFromYML.cpp +++ b/source/Camera/Basic/CaptureWithSettingsFromYML/CaptureWithSettingsFromYML.cpp @@ -1,9 +1,10 @@ /* -Capture point clouds, with color, from the Zivid camera, with settings from YML file. +Capture images and point clouds, with or without color, from the Zivid camera with settings from YML file. The YML files for this sample can be found under the main Zivid sample instructions. */ +#include #include #include @@ -46,12 +47,55 @@ int main() std::string(ZIVID_SAMPLE_DATA_DIR) + "/Settings/" + settingsFolder(camera) + "/Settings01.yml"; const auto settings = Zivid::Settings(settingsFile); - std::cout << "Capturing frame" << std::endl; - const auto frame = camera.capture(settings); + std::cout << "Capturing 2D frame" << std::endl; + { + const auto frame2D = camera.capture2D(settings); + + const auto imageSRGB = frame2D.imageSRGB(); + const auto imageFile = "ImageSRGB.png"; + std::cout << "Saving 2D color image (sRGB color space) to file: " << imageFile << std::endl; + imageSRGB.save(imageFile); + + // More information about linear RGB and sRGB color spaces is available at: + // https://support.zivid.com/en/latest/reference-articles/color-spaces-and-output-formats.html#color-spaces + + const auto pixelRow = 100; + const auto pixelCol = 50; + const auto pixelSRGB = imageSRGB(pixelRow, pixelCol); + std::cout << "Color at pixel (" << pixelRow << "," << pixelCol << "): R:" << std::to_string(pixelSRGB.r) + << " G:" << std::to_string(pixelSRGB.g) << " B:" << std::to_string(pixelSRGB.b) + << " A:" << std::to_string(pixelSRGB.a) << std::endl; + } + + std::cout << "Capturing 3D frame" << std::endl; + { + const auto frame3D = camera.capture3D(settings); - const auto dataFile = "Frame.zdf"; - std::cout << "Saving frame to file: " << dataFile << std::endl; - frame.save(dataFile); + const auto dataFile = "Frame3D.zdf"; + std::cout << "Saving frame to file: " << dataFile << std::endl; + frame3D.save(dataFile); + + const auto dataFilePly = "PointCloudWithoutColor.ply"; + std::cout << "Exporting point cloud (default pink colored points) to file: " << dataFilePly << std::endl; + frame3D.save(dataFilePly); + } + + std::cout << "Capturing 2D3D frame" << std::endl; + { + const auto frame = camera.capture2D3D(settings); + + const auto dataFile = "Frame.zdf"; + std::cout << "Saving frame to file: " << dataFile << std::endl; + frame.save(dataFile); + + Zivid::Experimental::PointCloudExport::FileFormat::PLY plyFile{ + "PointCloudWithColor.ply", + Zivid::Experimental::PointCloudExport::FileFormat::PLY::Layout::ordered, + Zivid::Experimental::PointCloudExport::ColorSpace::sRGB + }; + std::cout << "Exporting point cloud to file: " << plyFile.fileName() << std::endl; + Zivid::Experimental::PointCloudExport::exportFrame(frame, plyFile); + } } catch(const std::exception &e) { diff --git a/source/Camera/Basic/QuickCaptureTutorial.md b/source/Camera/Basic/QuickCaptureTutorial.md index 60b679b4..5957d97c 100644 --- a/source/Camera/Basic/QuickCaptureTutorial.md +++ b/source/Camera/Basic/QuickCaptureTutorial.md @@ -14,7 +14,8 @@ tutorial see: [**Connect**](#Connect) | [**Configure**](#Configure) | [**Capture**](#Capture) | -[**Save**](#Save) +[**Save**](#Save) | +[**Utilize**](#Utilize) --- @@ -25,9 +26,6 @@ tutorial see: This tutorial describes the most basic way to use the Zivid SDK to capture point clouds. -For MATLAB see [Zivid Quick Capture Tutorial for -MATLAB](https://github.com/zivid/zivid-matlab-samples/blob/master/source/Camera/Basic/QuickCaptureTutorial.md) - **Prerequisites** - Install [Zivid @@ -59,45 +57,62 @@ auto camera = zivid.connectCamera(); ## Configure ([go to -source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/CaptureAssistant/CaptureAssistant.cpp#L19-L25)) +source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/CaptureWithSettingsFromYML/CaptureWithSettingsFromYML.cpp#L48)) ``` sourceCode cpp -const auto suggestSettingsParameters = Zivid::CaptureAssistant::SuggestSettingsParameters{ - Zivid::CaptureAssistant::SuggestSettingsParameters::AmbientLightFrequency::none, - Zivid::CaptureAssistant::SuggestSettingsParameters::MaxCaptureTime{ std::chrono::milliseconds{ 1200 } } -}; -std::cout << "Running Capture Assistant with parameters:\n" << suggestSettingsParameters << std::endl; -auto settings = Zivid::CaptureAssistant::suggestSettings(camera, suggestSettingsParameters); +const auto settings = Zivid::Settings(settingsFile); ``` ## Capture ([go to -source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/Capture/Capture.cpp#L22)) +source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/Capture/Capture.cpp#L25)) ``` sourceCode cpp -const auto frame = camera.capture(settings); +const auto frame = camera.capture2D3D(settings); ``` ## Save ([go to -source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/Capture/Capture.cpp#L24-L26)) +source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/Capture/Capture.cpp#L32-L34)) ``` sourceCode cpp const auto dataFile = "Frame.zdf"; frame.save(dataFile); +.. tab-item:: Export ``` -The API detects which format to use. See [Point +([go to +source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Camera/Basic/Capture/Capture.cpp#L36-L38)) + +``` sourceCode cpp +const auto dataFilePLY = "PointCloud.ply"; +frame.save(dataFilePLY); +``` + +For other exporting options, see [Point Cloud](https://support.zivid.com/latest//reference-articles/point-cloud-structure-and-output-formats.html) -for a list of supported formats. +for a list of supported formats + +## Utilize + +([go to +source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Applications/Basic/FileFormats/ReadIterateZDF/ReadIterateZDF.cpp#L22-L23)) + +``` sourceCode cpp +const auto pointCloud = frame.pointCloud(); +const auto data = pointCloud.copyData(); +``` ----- Tip: -You can open and view `Frame.zdf` file in [Zivid +1. You can export Preset settings to YML from [Zivid + Studio](https://support.zivid.com/latest//getting-started/studio-guide.html) + +\#. You can open and view `Frame.zdf` file in [Zivid Studio](https://support.zivid.com/latest//getting-started/studio-guide.html). .. rubric:: Conclusion