Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,44 @@ Capture and save a point cloud, with colors, using GenICam interface and Halcon
#include <Zivid/Zivid.h>
#include <halconcpp/HalconCpp.h>

#include <chrono>
#include <iostream>

std::string presetPath(const std::string &model)
{
const std::string presetsPath = std::string(ZIVID_SAMPLE_DATA_DIR) + "/Settings";

if(model.find("zividTwoL100") != std::string::npos)
return presetsPath + "/Zivid_Two_L100_ManufacturingSpecular.yml";

if(model.find("zividTwo") != std::string::npos) return presetsPath + "/Zivid_Two_M70_ManufacturingSpecular.yml";

if(model.find("zivid2PlusM130") != std::string::npos)
return presetsPath + "/Zivid_Two_Plus_M130_ConsumerGoodsQuality.yml";

if(model.find("zivid2PlusM60") != std::string::npos)
return presetsPath + "/Zivid_Two_Plus_M60_ConsumerGoodsQuality.yml";

if(model.find("zivid2PlusL110") != std::string::npos)
return presetsPath + "/Zivid_Two_Plus_L110_ConsumerGoodsQuality.yml";

if(model.find("zivid2PlusMR130") != std::string::npos)
return presetsPath + "/Zivid_Two_Plus_MR130_ConsumerGoodsQuality.yml";

if(model.find("zivid2PlusMR60") != std::string::npos)
return presetsPath + "/Zivid_Two_Plus_MR60_ConsumerGoodsQuality.yml";

if(model.find("zivid2PlusLR110") != std::string::npos)
return presetsPath + "/Zivid_Two_Plus_LR110_ConsumerGoodsQuality.yml";

if(model.find("zivid3XL250") != std::string::npos)
return presetsPath + "/Zivid_Three_XL250_DepalletizationQuality.yml";

if(model.find("zividOnePlus") != std::string::npos)
throw std::runtime_error("Unsupported Zivid One+ model: " + model);

throw std::invalid_argument("Invalid camera model: " + model);
}

void savePointCloud(const HalconCpp::HObjectModel3D &model, const std::string &fileName)
{
model.WriteObjectModel3d(
Expand Down Expand Up @@ -77,12 +112,14 @@ int main()
std::cout << "Configuring settings" << std::endl;
HalconCpp::SetFramegrabberParam(framegrabber, "create_objectmodel3d", "enable");
HalconCpp::SetFramegrabberParam(framegrabber, "add_objectmodel3d_overlay_attrib", "enable");
HalconCpp::SetFramegrabberParam(framegrabber, "AcquisitionMode", "SingleFrame");

HalconCpp::SetFramegrabberParam(framegrabber, "Aperture", 3.0);
HalconCpp::SetFramegrabberParam(framegrabber, "ExposureTime", 5000);
HalconCpp::SetFramegrabberParam(framegrabber, "Gain", 1);
HalconCpp::SetFramegrabberParam(framegrabber, "Brightness", 1.8);
HalconCpp::HTuple modelTuple;
HalconCpp::GetFramegrabberParam(framegrabber, "CameraInfoModel", &modelTuple);

const std::string modelName = modelTuple.ToString().Text();
const HalconCpp::HString settingFile(presetPath(modelName).c_str());

HalconCpp::SetFramegrabberParam(framegrabber, "LoadSettingsFromFile", settingFile);

std::cout << "Capturing frame" << std::endl;
auto region = HalconCpp::HRegion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,59 @@ Capture a point cloud, with colors, using Zivid SDK, transform it to a Halcon po
#include <halconcpp/HalconCpp.h>

#include <algorithm>
#include <chrono>
#include <iostream>

namespace
{
Zivid::Settings get2DAnd3DSettings(const Zivid::Camera &camera)
std::string presetPath(const Zivid::Camera &camera)
{
auto settings = Zivid::Settings{ Zivid::Settings::Acquisitions{ Zivid::Settings::Acquisition{} },
Zivid::Settings::Color{ Zivid::Settings2D{
Zivid::Settings2D::Acquisitions{ Zivid::Settings2D::Acquisition{} } } } };
const std::string presetsPath = std::string(ZIVID_SAMPLE_DATA_DIR) + "/Settings";

auto model = camera.info().model();
switch(model.value())
switch(camera.info().model().value())
{
case Zivid::CameraInfo::Model::ValueType::zividTwo:
{
return presetsPath + "/Zivid_Two_M70_ManufacturingSpecular.yml";
}
case Zivid::CameraInfo::Model::ValueType::zividTwoL100:
{
settings.set(Zivid::Settings::Sampling::Pixel::all);
settings.color().value().set(Zivid::Settings2D::Sampling::Pixel::all);
break;
return presetsPath + "/Zivid_Two_L100_ManufacturingSpecular.yml";
}
case Zivid::CameraInfo::Model::ValueType::zivid2PlusM130:
{
return presetsPath + "/Zivid_Two_Plus_M130_ConsumerGoodsQuality.yml";
}
case Zivid::CameraInfo::Model::ValueType::zivid2PlusM60:
{
return presetsPath + "/Zivid_Two_Plus_M60_ConsumerGoodsQuality.yml";
}
case Zivid::CameraInfo::Model::ValueType::zivid2PlusL110:
{
settings.set(Zivid::Settings::Sampling::Pixel::blueSubsample2x2);
settings.color().value().set(Zivid::Settings2D::Sampling::Pixel::blueSubsample2x2);
break;
return presetsPath + "/Zivid_Two_Plus_L110_ConsumerGoodsQuality.yml";
}
case Zivid::CameraInfo::Model::ValueType::zivid2PlusMR130:
{
return presetsPath + "/Zivid_Two_Plus_MR130_ConsumerGoodsQuality.yml";
}
case Zivid::CameraInfo::Model::ValueType::zivid2PlusMR60:
{
return presetsPath + "/Zivid_Two_Plus_MR60_ConsumerGoodsQuality.yml";
}
case Zivid::CameraInfo::Model::ValueType::zivid2PlusLR110:
{
return presetsPath + "/Zivid_Two_Plus_LR110_ConsumerGoodsQuality.yml";
}
case Zivid::CameraInfo::Model::ValueType::zivid3XL250:
{
settings.set(Zivid::Settings::Sampling::Pixel::by2x2);
settings.color().value().set(Zivid::Settings2D::Sampling::Pixel::by2x2);
break;
return presetsPath + "/Zivid_Three_XL250_DepalletizationQuality.yml";
}
case Zivid::CameraInfo::Model::ValueType::zividOnePlusSmall:
case Zivid::CameraInfo::Model::ValueType::zividOnePlusMedium:
case Zivid::CameraInfo::Model::ValueType::zividOnePlusLarge:
{
throw std::runtime_error("Unsupported camera model '" + model.toString() + "'");
}
default: throw std::runtime_error("Unhandled enum value '" + model.toString() + "'");
}
case Zivid::CameraInfo::Model::ValueType::zividOnePlusLarge: break;

return settings;
default: throw std::runtime_error("Unhandled enum value '" + camera.info().model().toString() + "'");
}
throw std::invalid_argument("Invalid camera model");
}

void savePointCloud(const HalconCpp::HObjectModel3D &model, const std::string &fileName)
Expand All @@ -77,7 +82,7 @@ namespace

if(colorsRGBA.height() != height || colorsRGBA.width() != width)
{
throw std::runtime_error("Color image size does not match point cloud size");
throw std::runtime_error("the 2D image resolution must match the 3D point cloud resolution");
}

int numberOfValidPoints =
Expand Down Expand Up @@ -175,7 +180,8 @@ int main()
auto camera = zivid.connectCamera();

std::cout << "Configuring capture settings" << std::endl;
const auto settings = get2DAnd3DSettings(camera);
const auto settingsPath = presetPath(camera);
const auto settings = Zivid::Settings(settingsPath);

std::cout << "Capturing frame" << std::endl;
const auto frame = camera.capture2D3D(settings);
Expand Down