Python API reference🔗

The Python API provides wrappers for the core data types. The Tool class can be used to add new analysis tools to the VisionAppster runtime.

In addition to Python’s native types (int, float, bool, str, dict and list), there are three buffer-like data types that can be used to pass data between Python and the VisionAppster runtime: Image, Matrix and Tensor. These classes implement the Python buffer protocol and can thus be used wherever a buffer type is accepted. Most notably, the types work as the data buffer for a numpy.array.

When a buffer-like type is passed from the VisionAppster runtime to Python, the buffer will not be copied. The most efficient way of passing a buffer back is to allocate one of the VisionAppster types beforehand and use it as an output buffer. If a buffer is created internally by a Python library, the VisionAppster runtime cannot take the ownership of the buffer and must copy data.

All buffer-like types share certain properties:

  • They have a Type enumerator class and a type property.

  • They can be created with T(typeId, shape), where typeId is one of the Type enumerator values and shape is a list of buffer dimension sizes. T is the name of the type class, e.g. Image.

  • They have a shape property that contains the dimensions of the internal buffer as a list.

  • Elements can be accessed using the indexing operator, e.g. matrix[2, 3].

import visionappster as va
import numpy as np

# Uniform constructor syntax
matrix = va.Matrix(va.Matrix.DOUBLE, [480, 640])
tensor = va.Tensor(va.Tensor.FLOAT16, [480, 640, 1])
image = va.Image(va.Image.GRAY8, [480, 640])

# Type-specific constructors
matrix2 = va.Matrix.Double(480, 640)
image2 = va.Image(va.Image.GRAY8, 640, 480) # note argument order

# Uniform access syntax
val = matrix[479, 639]
val = tensor[470, 639, 0]
val = image[479, 639]

# Image provides (x, y) access:
val = image.pixel(639, 479)

# Using Images as input and output buffers to a numpy call
input = va.Image(va.Image.GRAY8, [500, 500])
# Fill input somehow here
binarized = va.Image.uninitialized(va.Image.GRAY8, input)
np.greater(input, 127, np.array(binarized, copy=False))