Code Example: Generating Models and Searching¶
Parameters can be exported from NxView using the Copy as Json
buttons and used in examples as described below.
1. Generating a Model¶
To successfully generate a model, a stereo camera must be opened and a disparity map must be calculated together with a previous capture command.
1std::string generateModelParams = R"(
2 {
3 "AngularResolution": 0.349065850398865896,
4 "Filename": "<PATH_TO_STL/PLY>",
5 "Function": "GenerateModel",
6 "RelativeModelSamplingDistance": 0.05,
7 "Subsampling": 0,
8 "Viewpoints": "All"
9 }
10)";
11
12NxLibCommand generateModel(cmdPartFinder);
13generateModel.parameters() << generateModelParams;
14generateModel.execute();
15int generatedModelId = generateModel.result()[itmModelId].asInt();
The marked section below
generateModelParams
can be replaced with the generated parameter representation of theCopy as JSON
button inside theModel Generation
tab.generatedModelId
is read out to be used to reference the ModelId in an upcoming Find subcommand.
2. Search for Parts¶
1std::string findParams = R"(
2 {
3 "Cluster": {
4 "Count": 0,
5 "MaximumClusterSize": 0
6 },
7 "CoverageDistanceThreshold": 0,
8 "Function": "Find",
9 "Hypothesis": {
10 "Count": 20000,
11 "Score": 0.7
12 },
13 "ModelId": 0,
14 "CombinedScore": 0.61
15 }
16)";
17
18NxLibCommand find(cmdPartFinder);
19find.parameters() << findParams;
20find.parameters()[itmModelId] = generatedModelId;
21find.execute();
The marked section below
findParams
can be replaced with the generated parameter representation of theCopy as JSON
button inside theSearch
tab.ModelId has to be set to fit to a model currently available in NxLib, either by a previous GenerateModel or LoadModel subcommand. In this example,
generatedModelId
refers to the result of the GenerateModel execution above.