Generate a PartFinder model and search for it

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.0500000000000000028,
 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 the Copy as JSON button inside the Model 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       "MinimumAspectRatio": 0,
 7       "MinimumLeadingScore": 0,
 8       "Scaling": 1
 9     },
10     "CoverageDistanceThreshold": 0,
11     "DistanceRatio": 1.19999999999999996,
12     "Function": "Find",
13     "Hypothesis": {
14       "Count": 20000,
15       "Score": 0.699999999999999956
16     },
17     "ModelId": 0,
18     "Refinement": {
19       "Refine3D": true
20     },
21     "CombinedScore": 0.609999999999999987
22   }
23)";
24
25NxLibCommand find(cmdPartFinder);
26find.parameters() << findParams;
27find.parameters()[itmModelId] = generatedModelId;
28find.execute();
  • The marked section below findParams can be replaced with the generated parameter representation of the Copy as JSON button inside the Search tab.

  • ModelId has to be set to fit to a model currently available in NxLib, either by a previous GenerateModel or LoadModel subcommand. generatedModelId refers to the read out result of the GenerateModel call from above.