This guide will show you how to use a python script for segmentation and descriptor node types.

On a Windows machine, you need to install Python version 3 or higher and be able to run the py command from the console.

Descriptor

First select Descriptor as node type and then select Python script as the method. Select the python script file using the Browse button or type the path to the script file directly.

Simple python script for a descriptor

import sys

try:
    with open(sys.argv[1], "r") as f:
        frames = f.read().splitlines()
    count = 0
    totSum = 0
    result = []
    for frame in frames:
        values = list(map(float, frame.split(";")))
        totSum += sum(values)
        count += len(values)

    result.append(totSum / count)
    print(result)

except Exception as inst:
    exc_type, exc_obj, exc_tb = sys.exc_info()
    print("Error: {0}, at line {1}".format(inst, exc_tb.tb_lineno))
PY

Example input to the script

The input to the script is saved to a temp file and the absolute path to the file is passed as an argument to the script.

Is in an array:

[1.0;1.5]

Example output from the script

The output has to be printed from the python script to be returned to Breeze: print(result).

[1.25]


Segmentation

First, select Segmentation as node type and then select Python script as the method. Select the python script file using the Browse button or type the path to the script file directly.

Simple python script for segmentation

import sys

try:
    with open(sys.argv[1], "r") as f:
        frames = f.read().splitlines()
    result = []
    for frame in frames:
        values = list(map(float, frame.split(";")))
        if len(values) > 0 and values[1] < 18.0:
            result.append(1)
        else:
            result.append(0)

    print(result)

except Exception as inst:
    exc_type, exc_obj, exc_tb = sys.exc_info()
    print("Error: {0}, at line {1}".format(inst, exc_tb.tb_lineno))         
PY

Example input to the script

The input to the script is saved to a temp file. The path to the temp file is then passed as a parameter to the python script. The script has to read this file to collect the input from Breeze. This is since the max parameter length is too short to hold all data needed. This type of segmentation is not recommended if performance is an priority as it has a lot of overhead.

[[17.0, 16.0, 19.0], [18.0, 17.0, 21.0], [19.0, 18.0, 22.0]]

Example output from the script

The output has to be printed from the python script to be returned to Breeze: print(result).

[1, 1, 0]

Everything inside the yellow line has now been selected as a sample.