Skip to content

Commit 07c3072

Browse files
csu-bot-zividGerman Moreno
authored andcommitted
Samples : load YML capture settings based on camera model Halcon (cpp)
- Detect camera model at runtime and load matching YML preset - Remove hardcoded capture settings
1 parent 6fdc09a commit 07c3072

2 files changed

Lines changed: 74 additions & 31 deletions

File tree

source/Camera/Advanced/CaptureHalconViaGenICam/CaptureHalconViaGenICam.cpp

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,44 @@ Capture and save a point cloud, with colors, using GenICam interface and Halcon
55
#include <Zivid/Zivid.h>
66
#include <halconcpp/HalconCpp.h>
77

8-
#include <chrono>
98
#include <iostream>
109

10+
std::string presetPath(const std::string &model)
11+
{
12+
const std::string presetsPath = std::string(ZIVID_SAMPLE_DATA_DIR) + "/Settings";
13+
14+
if(model.find("zividTwoL100") != std::string::npos)
15+
return presetsPath + "/Zivid_Two_L100_ManufacturingSpecular.yml";
16+
17+
if(model.find("zividTwo") != std::string::npos) return presetsPath + "/Zivid_Two_M70_ManufacturingSpecular.yml";
18+
19+
if(model.find("zivid2PlusM130") != std::string::npos)
20+
return presetsPath + "/Zivid_Two_Plus_M130_ConsumerGoodsQuality.yml";
21+
22+
if(model.find("zivid2PlusM60") != std::string::npos)
23+
return presetsPath + "/Zivid_Two_Plus_M60_ConsumerGoodsQuality.yml";
24+
25+
if(model.find("zivid2PlusL110") != std::string::npos)
26+
return presetsPath + "/Zivid_Two_Plus_L110_ConsumerGoodsQuality.yml";
27+
28+
if(model.find("zivid2PlusMR130") != std::string::npos)
29+
return presetsPath + "/Zivid_Two_Plus_MR130_ConsumerGoodsQuality.yml";
30+
31+
if(model.find("zivid2PlusMR60") != std::string::npos)
32+
return presetsPath + "/Zivid_Two_Plus_MR60_ConsumerGoodsQuality.yml";
33+
34+
if(model.find("zivid2PlusLR110") != std::string::npos)
35+
return presetsPath + "/Zivid_Two_Plus_LR110_ConsumerGoodsQuality.yml";
36+
37+
if(model.find("zivid3XL250") != std::string::npos)
38+
return presetsPath + "/Zivid_Three_XL250_DepalletizationQuality.yml";
39+
40+
if(model.find("zividOnePlus") != std::string::npos)
41+
throw std::runtime_error("Unsupported Zivid One+ model: " + model);
42+
43+
throw std::invalid_argument("Invalid camera model: " + model);
44+
}
45+
1146
void savePointCloud(const HalconCpp::HObjectModel3D &model, const std::string &fileName)
1247
{
1348
model.WriteObjectModel3d(
@@ -77,12 +112,14 @@ int main()
77112
std::cout << "Configuring settings" << std::endl;
78113
HalconCpp::SetFramegrabberParam(framegrabber, "create_objectmodel3d", "enable");
79114
HalconCpp::SetFramegrabberParam(framegrabber, "add_objectmodel3d_overlay_attrib", "enable");
80-
HalconCpp::SetFramegrabberParam(framegrabber, "AcquisitionMode", "SingleFrame");
81115

82-
HalconCpp::SetFramegrabberParam(framegrabber, "Aperture", 3.0);
83-
HalconCpp::SetFramegrabberParam(framegrabber, "ExposureTime", 5000);
84-
HalconCpp::SetFramegrabberParam(framegrabber, "Gain", 1);
85-
HalconCpp::SetFramegrabberParam(framegrabber, "Brightness", 1.8);
116+
HalconCpp::HTuple modelTuple;
117+
HalconCpp::GetFramegrabberParam(framegrabber, "CameraInfoModel", &modelTuple);
118+
119+
const std::string modelName = modelTuple.ToString().Text();
120+
const HalconCpp::HString settingFile(presetPath(modelName).c_str());
121+
122+
HalconCpp::SetFramegrabberParam(framegrabber, "LoadSettingsFromFile", settingFile);
86123

87124
std::cout << "Capturing frame" << std::endl;
88125
auto region = HalconCpp::HRegion();

source/Camera/Advanced/CaptureHalconViaZivid/CaptureHalconViaZivid.cpp

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,54 +6,59 @@ Capture a point cloud, with colors, using Zivid SDK, transform it to a Halcon po
66
#include <halconcpp/HalconCpp.h>
77

88
#include <algorithm>
9-
#include <chrono>
109
#include <iostream>
1110

1211
namespace
1312
{
14-
Zivid::Settings get2DAnd3DSettings(const Zivid::Camera &camera)
13+
std::string presetPath(const Zivid::Camera &camera)
1514
{
16-
auto settings = Zivid::Settings{ Zivid::Settings::Acquisitions{ Zivid::Settings::Acquisition{} },
17-
Zivid::Settings::Color{ Zivid::Settings2D{
18-
Zivid::Settings2D::Acquisitions{ Zivid::Settings2D::Acquisition{} } } } };
15+
const std::string presetsPath = std::string(ZIVID_SAMPLE_DATA_DIR) + "/Settings";
1916

20-
auto model = camera.info().model();
21-
switch(model.value())
17+
switch(camera.info().model().value())
2218
{
2319
case Zivid::CameraInfo::Model::ValueType::zividTwo:
20+
{
21+
return presetsPath + "/Zivid_Two_M70_ManufacturingSpecular.yml";
22+
}
2423
case Zivid::CameraInfo::Model::ValueType::zividTwoL100:
2524
{
26-
settings.set(Zivid::Settings::Sampling::Pixel::all);
27-
settings.color().value().set(Zivid::Settings2D::Sampling::Pixel::all);
28-
break;
25+
return presetsPath + "/Zivid_Two_L100_ManufacturingSpecular.yml";
2926
}
3027
case Zivid::CameraInfo::Model::ValueType::zivid2PlusM130:
28+
{
29+
return presetsPath + "/Zivid_Two_Plus_M130_ConsumerGoodsQuality.yml";
30+
}
3131
case Zivid::CameraInfo::Model::ValueType::zivid2PlusM60:
32+
{
33+
return presetsPath + "/Zivid_Two_Plus_M60_ConsumerGoodsQuality.yml";
34+
}
3235
case Zivid::CameraInfo::Model::ValueType::zivid2PlusL110:
3336
{
34-
settings.set(Zivid::Settings::Sampling::Pixel::blueSubsample2x2);
35-
settings.color().value().set(Zivid::Settings2D::Sampling::Pixel::blueSubsample2x2);
36-
break;
37+
return presetsPath + "/Zivid_Two_Plus_L110_ConsumerGoodsQuality.yml";
3738
}
3839
case Zivid::CameraInfo::Model::ValueType::zivid2PlusMR130:
40+
{
41+
return presetsPath + "/Zivid_Two_Plus_MR130_ConsumerGoodsQuality.yml";
42+
}
3943
case Zivid::CameraInfo::Model::ValueType::zivid2PlusMR60:
44+
{
45+
return presetsPath + "/Zivid_Two_Plus_MR60_ConsumerGoodsQuality.yml";
46+
}
4047
case Zivid::CameraInfo::Model::ValueType::zivid2PlusLR110:
48+
{
49+
return presetsPath + "/Zivid_Two_Plus_LR110_ConsumerGoodsQuality.yml";
50+
}
4151
case Zivid::CameraInfo::Model::ValueType::zivid3XL250:
4252
{
43-
settings.set(Zivid::Settings::Sampling::Pixel::by2x2);
44-
settings.color().value().set(Zivid::Settings2D::Sampling::Pixel::by2x2);
45-
break;
53+
return presetsPath + "/Zivid_Three_XL250_DepalletizationQuality.yml";
4654
}
4755
case Zivid::CameraInfo::Model::ValueType::zividOnePlusSmall:
4856
case Zivid::CameraInfo::Model::ValueType::zividOnePlusMedium:
49-
case Zivid::CameraInfo::Model::ValueType::zividOnePlusLarge:
50-
{
51-
throw std::runtime_error("Unsupported camera model '" + model.toString() + "'");
52-
}
53-
default: throw std::runtime_error("Unhandled enum value '" + model.toString() + "'");
54-
}
57+
case Zivid::CameraInfo::Model::ValueType::zividOnePlusLarge: break;
5558

56-
return settings;
59+
default: throw std::runtime_error("Unhandled enum value '" + camera.info().model().toString() + "'");
60+
}
61+
throw std::invalid_argument("Invalid camera model");
5762
}
5863

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

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

8388
int numberOfValidPoints =
@@ -175,7 +180,8 @@ int main()
175180
auto camera = zivid.connectCamera();
176181

177182
std::cout << "Configuring capture settings" << std::endl;
178-
const auto settings = get2DAnd3DSettings(camera);
183+
const auto settingsPath = presetPath(camera);
184+
const auto settings = Zivid::Settings(settingsPath);
179185

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

0 commit comments

Comments
 (0)