Starling developer guide: how to to add a new vision module

Principle

The basic principle is that one vision module is written in C++, and compiled in its own library. Its interface provides an initialization function (called once at program beginning), a processing function (called for each frame) and a cleaning function (called once at program end). Each module is shown as a block in Starling, and described in a block description file. When the processing chain is executed, Starling generates a standard C++ code structure and includes calls to the initialization, processing and cleaning functions of the blocks that participate. If one block in the workflow is a stream, then a loop is performed to apply the processing function to all frames.

The typical structure of Starling generated C++ code is described below.

Block description file

A block is fully described in one xml file. It mainly contains the includes, functions, initializations, processings and cleanings sections for the block, and some extra informations.

The structure of this xml file is explained below.

  • 'type' attribute is the block type identifier ; choose a value between 2000 and 2999 to avoid conflict with already defined blocks
  • 'property' items are the block parameters ; they must have a default value ; they can have a short description in 'desc' attribute ; if they have a type='filename' attribute, they are treated as a file name ; if they have a type='selector' attribute, and a values='value1;value2;...' attribute, a value selector will be displayed
  • parameter names (_PARAMx_ in this example) will be replaced by their values when code of sections initializations, processings and cleanings will be generated
  • help text is displayed in the block properties window
  • 'label' is a short name for the block
  • one line per block output and per block input ; id from 1 to n ; type is an existing opencv type
  • the optional 'desc'ription will be displayed in a tooltip
  • inputs have an 'optional' field that indicates if the input is required or not ; optional='true' means that the input is NOT required
  • 'istream' tag contains true if the block is an image stream source, else false
  • 'icon' tag contains block icon name ; use images/liris.png as default value ; icons must be placed in 'app_data/images' directory
  • 'description' tag contains a short description of the block
  • 'treegroup' tag contains the category name in which the block will be listed in the left panel ; the category may not exist, it will be created on fly
  • specific include paths, where headers will be searched (like gcc -I option) ; one line per path ; the '_LV_DIR_' keyword will be replaced by LIRIS-VISION directory name when code is generated
  • specific libraries (aka not opencv library) paths, where libraries will be searched (like gcc -L option) ; one line per library path ; the keyword _LV_DIR_ will be replaced by LIRIS-VISION directory name when code is generated
  • added to include section of the C++ code
  • added to function section of the C++ code
  • this section contains all helper functions which can be called by the main processing function ; this section is supposed to be rather small, and the major part of the code is supposed to be in the block library
  • the function used in processings section must fulfill some constraint: inputs are of pointer type and can be NULL (you should test them); outputs are of pointer type and can NOT be NULL, because output variables are automatically created
  • added to initializations section of the C++ code ; executed just one time, even in case of stream input
  • data structures can be created by the initialization code, and used by the processing code ; however, several instances of a given block might be present in a given workflow, so these data structures need to be unique for each block ; this can be done by putting the template _BLOCKID_ in all relevant variable names
  • _BLOCKID_ keywords and parameter names will be replaced by their value when code is generated ; _BLOCKID_ is the instantiated block identifier, aka two blocks in the same graph will have different identifiers, even if they are of the same type
  • added to processings section of the C++ code ; executed for each frame in case of stream input, or executed a single time in case of single image input
  • intermediate variables, corresponding to blocks outputs, are automatically created ; _INPUTx_ and _OUTPUTx_ keywords will be replaced by the right variables when code is generated, according to connections between blocks
  • added to cleanings section of the C++ code ; executed just one time, even in case of stream input
  • _BLOCKID_ keyword will be replaced by its value when code is generated

The places where special keywords can be used, and are replaced by there value, is summarized below:

Additional informations on block parameters:

Generated code

The C++ code is generated by putting together all code sections of all blocks participating in the processing graph. Some keywords are replaced by their values (in particular blocks parameters), and all blocks outputs variables are automatically created.

The table below is an illustration of how the block definition xml structure is translated int C++ source code.

A compilation script is also generated using informations from the xml block description file, as shown below.

gcc -x c++ -o executable `pkg-config --cflags opencv` -I/LIRIS-VISION/svn/ModulesAndBricks -I/LIRIS-VISION/svn/External -I/LIRIS-VISION/svn/External/libfreenect/include source_code.cpp `pkg-config --libs opencv` -L/LIRIS-VISION/svn/ModulesAndBricks/Apicamera/build -L/LIRIS-VISION/svn/External/libfreenect/build/lib -lcameraKinect -lapicamera -Xlinker -rpath="/LIRIS-VISION/svn/ModulesAndBricks/Apicamera/build:/LIRIS-VISION/svn/External/libfreenect/build/lib:"

Add a new block

To add a new block, you just have to place the xml file which describes the block in 'app_data/blocks.private' directory, and restart Starling.

You can use a copy of the xml code below and edit it to create your own xml block description file.

Examples

Read image from file: no input, one output, only 'functions' and 'processings' section used.

Background substract: one input, two outputs, all sections used.