Calling scripted cli module Output

I create a scripted cli module according to SlicerPythonCLIExample, and set print in .py file.

#!/usr/bin/env python-real  `
import os  
print("call vessel segment!")`

Then in a cpp file , it is called as below:

PythonQt::init();
PythonQtObjectPtr context = PythonQt::self()->getMainModule();
context.evalScript(QString(
    "slicer.cli.run(slicer.modules.ctaseg, None, None)\n"
));

But there is no output string in console window. just

Found CommandLine Module, target is C:/PilotImage/Release/Slicer-build/lib/Slicer-5.4/cli-modules/Release/CTASeg.py
ModuleType: CommandLineModule
No input data assigned to "Input Volume"

Does this script run correctly? or the input volume is necessary

Thanks

Later

vtkMRMLNode* dummyNode = qSlicerApplication::application()->mrmlScene()->GetFirstNodeByClass("vtkMRMLScalarVolumeNode");

PythonQt::init();
PythonQtObjectPtr context = PythonQt::self()->getMainModule();
context.evalScript(QString(
    "param={}\n"
    "param['inputVolume']=%1\n"
    "slicer.cli.runSync(slicer.modules.ctaseg, None, parameters=param)\n"
).arg(dummyNode->GetID()));

it says name ‘vtkMRMLScalarVolumeNode1’ is not defined

Process output is logged into the application log and also available in the CLI module node.

If you develop in C++ then you can use the C++ API (no need to call out to Python).

I try to call the custom AI-module in python script.
Now I cant find the generated result image, so i set an print to check if it works. it seems fails .
I try to find in log later.
Thanks

We have many modules that segment images by using xuatom AI models. I would recommend to start from a similar module.

Does the segmentation tool use nn-unet, monai, or just pyrorch directly?

The module is developped by other guy and i was required to make an integration. Maybe is some unet module.
I just call “slicer.util.launchConsoleProcess” to implement it

Thanks very much

If it is nnunet then I would recommend to use GitHub - gaudot/SlicerDentalSegmentator: 3D Slicer extension for fully-automatic segmentation of CT and CBCT dental volumes. extension as an example, and if anything else then the GitHub - lassoan/SlicerMONAIAuto3DSeg: Extension for 3D Slicer for running MONAI Auto3DSeg models extension.

1 Like