Skip to content

buffer Lua Interface


get

Get a pointer to the BufferLua object

Arguments:
buffer ptr Pointer to Module object
Returns:
buffer ptr Pointer to casted BufferLua object

Example

ptr = buffer:.get(ptr)


copy

Get a copy of a buffer, or of a buffer's region

Arguments:
buffer ptr Pointer to a buffer
number x X Position for region to get (Optional for region)
number y Y Position for region to get (Optional for region)
number width Width for region to get (Optional for region)
number height Height for region to get (Optional for region)
boolean relative Specify if the region coordinates are relative (Optional for region)
Returns:
buffer ptr Pointer to casted BufferLua object

Example

ptr = buffer:.copy(ptr,x,y,width,height,relative)


region

Get a non-copying ROI view of a buffer

Arguments:
buffer ptr Pointer to a buffer
number x X Position for region to get
number y Y Position for region to get
number width Width for region to get
number height Height for region to get
boolean relative Specify if the region coordinates are relative
Returns:
buffer ptr BufferLua that references the ROI view

Example

ptr = buffer:.region(ptr,x,y,width,height,relative)


copyToRegion

Copy a buffer's region to another buffer's region (Should be the same size)

Arguments:
buffer ptr Pointer to a buffer
number x X Position for region to copy from
number y Y Position for region to copy from
number width Width for region to copy from
number height Height for region to copy from
boolean relative Specify if the region coordinates to copy from are relative
buffer dest_buffer Pointer to a buffer to copy to
number dx X Position for region to copy to
number dy Y Position for region to copy to
number dwidth Width for region to copy to
number dheight Height for region to copy to
boolean drelative Specify if the region coordinates to copy to are relative (optional)
Returns:
boolean success If the copy was successful

Example

success = buffer:.copyToRegion(ptr,x,y,width,height,relative,dest_buffer,dx,dy,dwidth,dheight,drelative)


is_valid

Check if a buffer pointer has valid data

Arguments:
buffer ptr Pointer to a buffer
Returns:
boolean valid Is valid data

Example

valid = buffer:.is_valid(ptr)


supportsImageOperations

Check whether generic image operations are supported by the current storage backend. Relay-only

Arguments:

Returns:
boolean true when the buffer supports generic image operations

Example

true = buffer:.supportsImageOperations()


persist

Mark buffer as persistent so it survives per-frame cleanup

Arguments:
buffer ptr Pointer to a buffer
string origin Optional owner name included in lifecycle diagnostics

Example

buffer:.persist(ptr,origin)


release

Explicitly release buffer GPU memory and mark invalid

Arguments:
buffer ptr Pointer to a buffer

Example

buffer:.release(ptr)


getSize

Get buffer size

Arguments:
buffer ptr Pointer to a buffer
Returns:
number[] size Buffer size

Example

size = buffer:.getSize(ptr)


base64Encode

Encode buffer contents as a base64 JPEG string

Arguments:
buffer ptr Pointer to a buffer
Returns:
string b64 Base64-encoded JPEG, or nil when encoding fails

Example

b64 = buffer:.base64Encode(ptr)


downloadAsGrayscale

Download buffer as grayscale cv::Mat

Arguments:
buffer ptr Pointer to a buffer
Returns:
buffer ptr Pointer to new grayscale buffer (Mat storage)

Example

ptr = buffer:.downloadAsGrayscale(ptr)


resize

Resize buffer

Arguments:
buffer ptr Pointer to a buffer
number[] size Buffer size
string method (optional) Resize method: "SQUASH" (default), "FIT", or "PLACE"
string interpolation (optional) Interpolation method: "LINEAR" (default), "NEAREST", "AREA", "CUBIC", or "LANCZOS4"

Example

buffer:.resize(ptr,size,method,interpolation)


resizeAndCopy

Resize buffer and return a new buffer

Arguments:
buffer ptr Pointer to a buffer
number[] size Target size as {width, height}
string method (optional) Resize method: "SQUASH" (default), "FIT", or "PLACE"
string interpolation (optional) Interpolation method: "LINEAR" (default), "NEAREST", "AREA", "CUBIC", or "LANCZOS4"
Returns:
buffer ptr New resized buffer

Example

ptr = buffer:.resizeAndCopy(ptr,size,method,interpolation)


resizeAndCopyRegion

Resize/crop (optional) and return a new buffer

Arguments:
buffer ptr Pointer to a buffer
number[] size Target size as {width, height}
string method (optional) Resize method: "SQUASH" (default), "FIT", or "PLACE"
string interpolation (optional) Interpolation method: "LINEAR" (default), "NEAREST", "AREA", "CUBIC", or "LANCZOS4"
number[] region (optional) ROI as {x, y, w, h}; relative if 'relative' is true
boolean relative (optional) Treat region as relative coordinates (default false)
number destType (optional) Destination BufferDataType (0=UNKNOWN,8=GRAY,12=NV12,13=YV12,16=BGR,24=BGRA)
Returns:
buffer ptr New resized/cropped buffer

Example

ptr = buffer:.resizeAndCopyRegion(ptr,size,method,interpolation,region,relative,destType)


drawRect

Draw a rectangle on a specific buffer from the instance

Arguments:
buffer ptr Pointer to a buffer
number x Rectangle X position (Relative)
number y Rectangle Y position (Relative)
number width Rectangle Width (Relative)
number height Rectangle Height (Relative)
number[] color Object color (Array with 3 values)
number thickness Rectangle thickness

Example

buffer:.drawRect(ptr,x,y,width,height,color,thickness)


drawPoly

Draw a polygon on a specific buffer from the instance

Arguments:
buffer ptr Pointer to a buffer
number[][] shape Vector of points for shape ([:][2]) (Relative)
number[] color Object color (Array with 3 values between 0 and 255)
number alpha Polygon color alpha (0.0 - 1.0)

Example

buffer:.drawPoly(ptr,shape,color,alpha)


fill

Fill a specific buffer with a color

Arguments:
buffer ptr Pointer to a buffer
number[] color Color to fill the buffer (Array with 3 values)
number opacity Opacity of color to fill the buffer

Example

buffer:.fill(ptr,color,opacity)


drawLine

Draw a line on a specific buffer from the instance

Arguments:
buffer ptr Pointer to a buffer
number[] srcPt Line starting point (Array with 2 values) (Relative)
number[] dstPt Line ending point (Array with 2 values) (Relative)
number[] color Line color (Array with 3 values)
number thickness Line thickness

Example

buffer:.drawLine(ptr,srcPt,dstPt,color,thickness)


drawPolyLine

Draw a line consisting of multiple points example: outputimg:drawPolyLine({{0,0},{10,0},{10,10},{20,10},{20,200}}, {255, 255, 0}, 1)

Arguments:
buffer ptr Pointer to a buffer
number[][] pts Line points (Array of Array with 2 values) (Relative)
number[] color Line color (Array with 3 values)
number thickness Line thickness

Example

buffer:.drawPolyLine(ptr,pts,color,thickness)


drawCircle

Draw a circle on a specific buffer from the instance

Arguments:
buffer ptr Pointer to a buffer
number[] centerPt Circle center point (Array with 2 values) (Relative)
number radius Circle radius (Relative)
number[] color Object color (Array with 3 values)
number thickness Circle thickness

Example

buffer:.drawCircle(ptr,centerPt,radius,color,thickness)


writeText

Write text on a specific buffer from the instance

Arguments:
buffer ptr Pointer to a buffer
number[] srcPt Text starting point (Array with 2 values) (Relative)
string text Text to write to buffer
number[] color Object color (Array with 3 values)
number fontscale Text font scale
number thickness Text thickness
number fontface Text font face

Example

buffer:.writeText(ptr,srcPt,text,color,fontscale,thickness,fontface)


writeTextAutoSize

Write text on a specific buffer from the instance with auto adjusted size for different screens

Arguments:
buffer ptr Pointer to a buffer
number[] srcPt Text starting point (Array with 2 values) (Relative)
string text Text to write to buffer
number[] color Object color (Array with 3 values)
number fontface Text font face
number generic_size Size of text (0-Small 1-Normal 2-Big)

Example

buffer:.writeTextAutoSize(ptr,srcPt,text,color,fontface,generic_size)


getTextAutoSize

Get the size of the auto adjusted text for different screens

Arguments:
buffer ptr Pointer to a buffer
string text Text to write to buffer
number fontface Text font face
number generic_size Size of text (0-Small 1-Normal 2-Big)
Returns:
number[] size Size of text on screen

Example

size = buffer:.getTextAutoSize(ptr,text,fontface,generic_size)


loadImage

Draw an image from a file into a specific buffer from the instance

Arguments:
buffer ptr Pointer to a buffer
string filename Image filename to load
Returns:
bool state of loading the image

Example

state = buffer:.loadImage(ptr,filename)


saveImage

Save an image to a file

Arguments:
buffer ptr Pointer to a buffer
string filename Image filename to save

Example

buffer:.saveImage(ptr,filename)


brightness

Adjust image brightness

Arguments:
buffer ptr Pointer to a buffer
number delta Positive or negative value by which to alter brightness

Example

buffer:.brightness(ptr,delta)


grayscale

Convert image to grayscale

Arguments:
buffer ptr Pointer to a buffer
bool singleChannel Convert image to 1 or 3 channels

Example

buffer:.grayscale(ptr,singleChannel)


grayscaleCopy

Convert image to grayscale and return a new buffer

Arguments:
buffer ptr Pointer to a buffer
Returns:
buffer ptr New grayscale buffer (single channel)

Example

ptr = buffer:.grayscaleCopy(ptr)


fishToPano

Convert fisheye image to equirectangular panoramic

Arguments:
buffer ptr Pointer to a buffer
float xOffset X offset in source image
float yOffset Y offset in source image

Example

buffer:.fishToPano(ptr,xOffset,yOffset)


clahe

Execute Contrast Limited Adaptive Histogram Equalization (CLAHE) to equalize image.

Arguments:
buffer ptr Pointer to a buffer
int clipLimit This parameter sets the threshold for contrast limiting. Default can be 40.
int tileGridSizeX This sets the number of tiles in the row. Default can be 8.
int tileGridSizeY This sets the number of tiles in the column. Default can be 8.

Example

buffer:.clahe(ptr,clipLimit,tileGridSizeX,tileGridSizeY)


meanStdDev

Get the mean and standard deviation of the buffer

Arguments:
buffer ptr Pointer to a buffer
Returns:
table with mean and standard deviation of the buffer channels

Example

with = buffer:.meanStdDev(ptr)


blur

Blur the image

Arguments:
buffer ptr Pointer to a buffer
number x Rectangle X position (Relative)
number y Rectangle Y position (Relative)
number width Rectangle Width (Relative)
number height Rectangle Height (Relative)
number amount Blur amount

Example

buffer:.blur(ptr,x,y,width,height,amount)


pixelate

Pixelate the image

Arguments:
buffer ptr Pointer to a buffer
number x Rectangle X position (Relative)
number y Rectangle Y position (Relative)
number width Rectangle Width (Relative)
number height Rectangle Height (Relative)
number amount Pixelate amount

Example

buffer:.pixelate(ptr,x,y,width,height,amount)


drawBoundingBox

Draw a bounding box on the buffer

Arguments:
buffer ptr Pointer to a buffer
number x Rectangle X position (Relative)
number y Rectangle Y position (Relative)
number width Rectangle Width (Relative)
number height Rectangle Height (Relative)
string label Bounding box label
number[] color Bounding box color
number thickness Bounding box thickness

Example

buffer:.drawBoundingBox(ptr,x,y,width,height,label,color,thickness)


getTimestamp

gets timestamp

Arguments:
buffer ptr Pointer to a buffer
Returns:
number timestamp of the buffer frame (0 if not defined, usually in milliseconds - might be device dependent)

Example

timestamp = buffer:.getTimestamp(ptr)


getFrameId

gets frame id

Arguments:
buffer ptr Pointer to a buffer
Returns:
number current frame ID

Example

current = buffer:.getFrameId(ptr)


rotate90deg

Rotate the buffer multiples of 90 degrees

Arguments:
number times Number of times to rotate the buffer in 90 degrees CW

Example

buffer:.rotate90deg(times)


split

Splits the RGB buffer into separate buffers for each channel

Arguments:
buffer ptr Pointer to a buffer
Returns:
table with the split buffers

Example

with = buffer:.split(ptr)


toDataType

Convert buffer to a specific data type

Arguments:
buffer ptr Pointer to a buffer
number type Data type to convert to (0-UNKNOWN, 8-GRAY, 12-NV12, 13-YV12, 16-BGR, 24-BGRA)

Example

buffer:.toDataType(ptr,type)


toTransportUri

Convert buffer to a specific transport URI

Arguments:
buffer ptr Pointer to a buffer
string uri Transport URI to convert to (e.g., "cpu://", "cuda://", "opencl://")

Example

buffer:.toTransportUri(ptr,uri)


getTransportUri

Get the buffer's transport URI

Arguments:
buffer ptr Pointer to a buffer
Returns:
string uri Transport URI (e.g., "cpu://", "hailo://")

Example

uri = buffer:.getTransportUri(ptr)


copyToTransport

Get an independent deep copy on a specific transport

Arguments:
buffer ptr Pointer to a buffer
string uri Transport URI for the copy (e.g., "cpu://")
Returns:
buffer ptr New buffer with copied pixels, or nil when the copy fails

Example

ptr = buffer:.copyToTransport(ptr,uri)