static vx_convolution vxCreateGaussian5x5Convolution(vx_context context) { vx_convolution conv = vxCreateConvolution(context, 5, 5); vx_status status = vxWriteConvolutionCoefficients(conv, (vx_int16 *)gaussian5x5); if (status != VX_SUCCESS) { vxReleaseConvolution(&conv); return NULL; } status = vxSetConvolutionAttribute(conv, VX_CONVOLUTION_ATTRIBUTE_SCALE, (void *)&gaussian5x5scale, sizeof(vx_uint32)); if (status != VX_SUCCESS) { vxReleaseConvolution(&conv); return NULL; } return conv; }
vx_status example_conv(vx_context context) { //! [assign] // A horizontal Scharr gradient operator with different scale. vx_int16 gx[3][3] = { { 3, 0, -3}, { 10, 0,-10}, { 3, 0, -3}, }; vx_uint32 scale = 9; vx_convolution scharr_x = vxCreateConvolution(context, 3, 3); vxAccessConvolutionCoefficients(scharr_x, NULL); vxCommitConvolutionCoefficients(scharr_x, (vx_int16*)gx); vxSetConvolutionAttribute(scharr_x, VX_CONVOLUTION_ATTRIBUTE_SCALE, &scale, sizeof(scale)); //! [assign] vxReleaseConvolution(&scharr_x); return VX_SUCCESS; }
static vx_status VX_CALLBACK vxHalfscaleGaussianInitializer(vx_node node, const vx_reference *parameters, vx_uint32 num) { vx_status status = VX_ERROR_INVALID_PARAMETERS; if (num == 3) { vx_image input = (vx_image)parameters[0]; vx_image output = (vx_image)parameters[1]; vx_int32 kernel_size = 3; vx_convolution convolution = 0; vx_context context = vxGetContext((vx_reference)node); vx_graph graph = vxCreateGraph(context); if (vxGetStatus((vx_reference)graph) == VX_SUCCESS) { vx_uint32 i; /* We have a child-graph; we want to make sure the parent graph is recognized as a valid scope for sake of virtual image parameters. */ graph->parentGraph = node->graph; vxReadScalarValue((vx_scalar)parameters[2], &kernel_size); if (kernel_size == 3 || kernel_size == 5) { if (kernel_size == 5) { convolution = vxCreateGaussian5x5Convolution(context); } if (kernel_size == 3 || convolution) { vx_image virt = vxCreateVirtualImage(graph, 0, 0, VX_DF_IMAGE_U8); vx_node nodes[] = { kernel_size == 3 ? vxGaussian3x3Node(graph, input, virt) : vxConvolveNode(graph, input, convolution, virt), vxScaleImageNode(graph, virt, output, VX_INTERPOLATION_TYPE_NEAREST_NEIGHBOR), }; vx_border_mode_t borders; vxQueryNode(node, VX_NODE_ATTRIBUTE_BORDER_MODE, &borders, sizeof(borders)); for (i = 0; i < dimof(nodes); i++) { vxSetNodeAttribute(nodes[i], VX_NODE_ATTRIBUTE_BORDER_MODE, &borders, sizeof(borders)); } status = VX_SUCCESS; status |= vxAddParameterToGraphByIndex(graph, nodes[0], 0); /* input image */ status |= vxAddParameterToGraphByIndex(graph, nodes[1], 1); /* output image */ status |= vxAddParameterToGraphByIndex(graph, node, 2); /* gradient size - refer to self to quiet sub-graph validator */ status |= vxVerifyGraph(graph); /* release our references, the graph will hold it's own */ for (i = 0; i < dimof(nodes); i++) { vxReleaseNode(&nodes[i]); } if (convolution) vxReleaseConvolution(&convolution); vxReleaseImage(&virt); status |= vxSetChildGraphOfNode(node, graph); } } vxReleaseGraph(&graph); } } return status; }