Calc Results By Python

Function

This Step runs a user-defined script through Python and outputs the calculation results to Mech-Vision.

The characteristics of this Step are as follows:

  • Multi-threading supported

  • Loading Python script in real time

  • Support various data type conversions when transferring data between C++ and Python

  • Support to display the Python’s log in the log panel of Mech-Vision

Usage Scenario

When a custom calculation is required, this Step can be used to run the user-defined Python script and the workflow of the Steps can be simplified in the project.

Input and Output

  • Input: determined by the data type input in the Input Port(s) parameter

  • Output: determined by the data type input in the Output Port(s) parameter

Hint

You can specify the data type of the input/output port according to the data type of the prior or succeeding Steps’ input/output port.

Installtion and Usage

Installation

Python 3.6.8 is built into Mech-Vision, and this Step will use the built-in Python environment of Mech-Vision. If there is any missing Python library when you use this Step, you need to install the library in the Mech-Vision’s built-in Python environment. The procedures for installation are as follows:

  1. Open the command prompt window.

  2. Use the CD command to go to the directory where Python is stored in Mech-Vision.

  3. Type “python -m pip install Python name of the library” on the command line to install the missing Python library.

Hint

The two frequently-used Python libraries, NumPy and OpenCv, are built into Mech-Vision.

Usage

The basic procedures for using this Step are as follows:

  1. Set the data type for the input and output ports. Enter the data type for Input Port(s) and Output Port(s) according to the data type of the prior or succeeding Steps’ input/output port.

  2. Specify the file path of the Python script. Select the file path of the script to be loaded in the Script File Path parameter.

  3. Set the name of the function to be called. Once the Script File Path has been specified, this Step will retrieve the function names in the script automatically, and you can select the name of the function to be called in the drop-down list of Func Name.

  4. Run the Step.

Tip

When the Python script is modified, and you want to use the new script to run this Step in real time, click Reload File in the Execution Flags parameter group.

Hint

Please refer to Parameter Description for details.

Notes

Please pay attention to the following issues when you write the Python script and run the script in this Step.

Use the NumPy Library

If you want to use some complicated types of data that require the NumPy library to import, you should add the import numpy statement at the beginning of the script, or else an error will occur.

Pay Attention to the Data Dimension when Writing the Script

When writing the Python script, please note the dimension of data corresponding to each port of the Step.

  • 0 dimension by default: Image, Cloud(XYZ), Cloud(XYZ-Normal)

  • 1 dimension by default: NumberList, BoolList, IndexList, StringList

  • 2 dimensions by default: PoseList, Pose2DList, Size3DList

Hint

Use “[]” after the data type to add a dimension.

For example, the data dimension of NumberList is 1, while the data dimension of NumberList[] is 2.

Parameter Description

Input Port(s)
Description: This parameter is used to specify the data type(s) of the input port(s). The input data types will be passed to the called function as parameters in the corresponding order.
Default value: Null.
Output Port(s)
Description: This parameter is used to specify the data type(s) of the output port(s). Data returned by the function will be returned to the Step in the corresponding order and will be parsed according to the corresponding data type.
Default value: Null.

Hint

The currently supported data types are as follows:

PoseList, Pose2DList, NumberList, StringList, Image,Cloud(XYZ), Cloud(XYZ-Normal), Size3DList, StringList, BoolList

Script File Path
Description: This parameter is used to select the file path of the script to be loaded.
Default value: Null.
Func Name
Description: This parameter is used to set the name of the function to be called.
Default value: Null.