Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

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 in article /wiki/spaces/CONFLUENCE/pages/7569551 .

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.

  • No labels

0 Comments

You are not logged in. Any changes you make will be marked as anonymous. You may want to Log In if you already have an account.