Code

Using theย Pythonย programming language, the Code module allows you to customize the application context as you choose. In a new project, there are several ready-made sample codes available that work with OpenCV. The context structure is described atย Context.

Structure

The main method is โ€˜main(context, module_item)โ€™. Its role is to edit the context that comes in as a parameter. Additional auxiliary methods can be added to the code. Standard libraries can be imported, typically together with the โ€˜cv2โ€™ library. In the context, the image is under the โ€˜imageโ€™ attribute and its structure is a numpy array, seeย OpenCV documentation.

You can use the keyboard shortcut โ€˜Ctrl+Sโ€™ for saving.

Example of image reduction to half of its size.

import cv2 def main(context, module_item): context['image'] = cv2.resize(context['image'], None, fx=0.5, fy=0.5)

Early Flow Termination

If the โ€˜exitโ€™ attribute is set to โ€˜Trueโ€™ in the context, the subsequent modules are skipped. If the code uses parallelism, only the current branch is terminated.

Example of termination if no objects were found in the previous modules.

import cv2 def main(context, module_item): if len(context['detectedRectangles']) == 0: context['exit'] = True

OpenCV

To work with the image, you can use the OpenCV library offering a variety of editing methods.

Console

Some errors and text outputs can be seen in the console which can be enabled by the โ€˜show consoleโ€™ button.