VisionWorks Toolkit Reference

December 18, 2015 | 1.2 Release

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
3. Output Validation Callback Function

This section illustrates the implementation of the output validation callback function.

An output validation callback function is needed to validate output parameter data objects of a custom user node. The callback is called automatically at graph verification time for each individual output parameter of any node that instantiates the user custom kernel. The output validation callback differs from the input validation callback because its purpose is to set a vx_meta_format object with the properties that are expected for the output parameter (metadata). From this vx_meta_format object, VisionWorks checks whether the node output parameter has the expected properties and raises an error otherwise. In most cases, the properties of outputs are deduced from input parameters.

2.1 Output validation callback prototype

Output validation callbacks have the same prototype for any kernel:

vx_status keypointArraySort_output_validate(vx_node node, vx_uint32 index, vx_meta_format meta)

2.2 Determine the expected output metadata

For an array, metadata are its capacity and the type of its elements. For an image, it would be its dimensions and format.

if (index == 1)
{
vx_array src = NULL;
vxQueryParameter(param0, VX_PARAMETER_ATTRIBUTE_REF, &src, sizeof(src));
vx_size src_capacity = 0;
vxQueryArray(src, VX_ARRAY_ATTRIBUTE_CAPACITY, &src_capacity, sizeof(src_capacity));
vx_enum src_item_type = 0;
vxQueryArray(src, VX_ARRAY_ATTRIBUTE_ITEMTYPE, &src_item_type, sizeof(src_item_type));
vxSetMetaFormatAttribute(meta, VX_ARRAY_ATTRIBUTE_ITEMTYPE, &src_item_type, sizeof(src_item_type));
vxSetMetaFormatAttribute(meta, VX_ARRAY_ATTRIBUTE_CAPACITY, &src_capacity, sizeof(src_capacity));
status = VX_SUCCESS;
}

Complete Code for the Node Output Validation

vx_status keypointArraySort_output_validate(vx_node node, vx_uint32 index, vx_meta_format meta)
{
if (index == 1)
{
vx_array src = NULL;
vxQueryParameter(param0, VX_PARAMETER_ATTRIBUTE_REF, &src, sizeof(src));
vx_size src_capacity = 0;
vxQueryArray(src, VX_ARRAY_ATTRIBUTE_CAPACITY, &src_capacity, sizeof(src_capacity));
vx_enum src_item_type = 0;
vxQueryArray(src, VX_ARRAY_ATTRIBUTE_ITEMTYPE, &src_item_type, sizeof(src_item_type));
vxSetMetaFormatAttribute(meta, VX_ARRAY_ATTRIBUTE_ITEMTYPE, &src_item_type, sizeof(src_item_type));
vxSetMetaFormatAttribute(meta, VX_ARRAY_ATTRIBUTE_CAPACITY, &src_capacity, sizeof(src_capacity));
status = VX_SUCCESS;
}
return status;
}