Context

Context is an application variable that passes through each active module during image processing.

In the module, it is possible to develop custom solutions for your project using Python and context data.

The user can add or modify custom attributes.

Do not change the structure (type) of the objects when modifying the attributes.

Context Data in PEKAT VISION Projects

A series of context data examples displayed in PEKAT VISION projects (JSON Format), is available in our module article, as shown in the example below:

inspection showcase.png

Context Data Glossary

image [Numpy Array]

Image in NumPy array.

detectedRectangles [Array]

A field containing the detected objects.

result [Boolean]

Evaluation of the image - ‘True’ if the image is ok, ‘False’ for the defective image.

exit [Boolean]

Early termination, for details, read the article .

It is not returned in response to an HTTP request, nor does it appear in the inspection.

heatmaps [Array of Numpy Array]

A field containing numpy arrays that represent heatmaps.

data

Internal argument.

Appears during processing, but does not respond to the HTTP request, nor does it appear in the inspection.

production_mode [Boolean]

If an image received through the HTTP API is processed, the parameter becomes True, otherwise False.

operatorInput [Dictionary]

If there are any active inputs/selects/sliders in the Operator View, the values they had during the processing of the image will be displayed in this dictionary. More info is in the article.

completeTime [Float]

Processing time of the image in seconds.

 

Usecase example

One of the usecases may be to end evaluation early based on a predetermined condition. In case of a flow containing it is possible to stop certain branches and let others freely into evaluation. Notice the following flow:

Context flow example.png

In this case the module can be used to distinguish two separate parts. On one part it is necessary to detect damaged parts, that’s what the Detector is used for. On a different part it is necessary to detect the expiration date, this is done by OCR.

By implementing a module before with the following code:

def main(context): # to get the class look at the previous JSON structure # change the string "Expiration Date" based on your real class expiration_date_class = context['detectedRectangles'][0]['classNames'][0]['label'] == "Expiration Date" if expiration_date_class: context['exit'] = True

The important line here is context['exit'] = True. This way it is possible to stop the image from further evaluation, saving time as a result.