VisionWorks Toolkit Reference

April 8, 2016 | 1.4 Release

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Object Creation

This section demonstrates data object creation in NVX CUDA API.

The NVX CUDA API uses transparent data objects with memory allocation controlled by the application.

The image data object is represented by abstract base structure nvxcu_image_t and its inheritors. To create the image, data object application must use one of the specific image classes, for example, nvxcu_pitch_linear_image_t. The nvxcu_pitch_linear_image_t represents image data in pitch linear format in row-major order (like 2D memory allocated via cudaMallocPitch). To create nvxcu_pitch_linear_image_t, object application must provide CUDA device pointers with strides for all planes, as well as image format and dimensions.

nvxcu_pitch_linear_image_t createImageU8(uint32_t width, uint32_t height)
{
void *dev_ptr = NULL;
size_t pitch = 0;
cudaMallocPitch(&dev_ptr, &pitch, width * sizeof(uint8_t), height);
image.base.width = width;
image.base.height = height;
image.planes[0].dev_ptr = dev_ptr;
image.planes[0].pitch_in_bytes = pitch;
return image;
}

The array data object is represented by abstract base class nvxcu_array_t and its inheritors. To create array data object application must use one of the specific array classes, for example, nvxcu_plain_array_t. The nvxcu_plain_array_t represents array data in plain CUDA device memory. To create nvxcu_plain_array_t, application must provide CUDA device pointers to array's data and to array's number of items, as well as item type and the capacity of data buffer in the elements.

nvxcu_plain_array_t createArrayKeyPoint(uint32_t capacity)
{
void *dev_ptr = NULL;
cudaMalloc(&dev_ptr, capacity * sizeof(nvxcu_keypoint_t));
uint32_t *num_items_dev_ptr = NULL;
cudaMalloc((void **)&num_items_dev_ptr, sizeof(uint32_t));
arr.base.capacity = capacity;
arr.dev_ptr = dev_ptr;
arr.num_items_dev_ptr = num_items_dev_ptr;
return arr;
}

The pyramid data object is represented by abstract base class nvxcu_pyramid_t and its inheritors. To create the array, data object application must use one of the specific array classes, for example, nvxcu_pitch_linear_pyramid_t. nvxcu_pitch_linear_pyramid_t represents pyramid objects as plain C arrays of nvxcu_pitch_linear_image_t objects. Application must initialize all levels of the pyramid and must provide scale factor. It is application's responsibility to ensure size and format coherency between pyramid levels.

nvxcu_pitch_linear_pyramid_t createPyramidHalfScale(uint32_t width, uint32_t height, uint32_t num_levels)
{
pyr.base.num_levels = num_levels;
pyr.levels = calloc(num_levels, sizeof(nvxcu_pitch_linear_image_t));
uint32_t cur_width = width;
uint32_t cur_height = height;
float cur_scale = 1.0f;
for (uint32_t i = 0; i < num_levels; i++)
{
pyr.levels[i] = createImageU8(cur_width, cur_height);
// Next level dimensions
cur_scale *= pyr.base.scale;
cur_width = (uint32_t)ceilf((float)width * cur_scale);
cur_height = (uint32_t)ceilf((float)height * cur_scale);
}
return pyr;
}