Load a PartFinder model file saved from NxView¶
A short code example of how to use PartFinder model files exported from NxView using the Save model
button. The example will use the search parameters exported along with the model.
1. Loading the 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.
1NxLibCommand loadModel(cmdPartFinder);
2loadModel.parameters()[itmFunction] = valLoadModel;
3loadModel.parameters()[itmFilename] = examplesDir + "/C++/nxPartFinder/SphereModel.zip";
4loadModel.execute();
5int loadedModelId = generateModel.result()[itmModelId].asInt();
6std::string findParamsAsJson = generateModel.result()[itmSupplementary][itmFind].asJson();
The file name and path in the highlighted section can be customized to point to your own saved model file saved from inside the NxView
PartFinder / Search
tab.loadedModelId
is read out to be used to reference the ModelId in an upcoming Find subcommand.findParamsAsJson
keeps the search settings which were stored by NxView along with the model to use them in an upcoming Find subcommand.
1. Search for Parts¶
1NxLibCommand find(cmdPartFinder);
2find.parameters() << findParamsAsJson;
3find.parameters()[itmFunction] = valFind;
4find.parameters()[itmModelId] = loadedModelId;
5find.execute();
Parameters will be filled with the search parameters kept in the
findParamsAsJson
variable of the LoadModel call from above.ModelId has to be set to fit to a model currently available in NxLib, either by a previous GenerateModel or LoadModel subcommand.
loadedModelId
refers to the read out result of the GenerateModel call from above.