Python API reference🔗
In addition to Python’s native types (
list), the 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
buffer type is accepted. Most notably, the types work as
the data buffer for a
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
Typeenumerator class and a
They can be created with
T(typeId, shape), where
typeIdis one of the
Typeenumerator values and
shapeis a list of buffer dimension sizes.
Tis the name of the type class, e.g.
They have a
shapeproperty that contains the dimensions of the internal buffer as a
Elements can be accessed using the indexing operator, e.g.
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))