TIOVX User Guide
vx_tutorial_graph_image_gradients.c File Reference
#include <stdio.h>
#include <VX/vx.h>
#include <TI/tivx.h>
#include <utility.h>

Go to the source code of this file.

Macros

#define IN_FILE_NAME   "${VX_TEST_DATA_PATH}/colors.bmp"
 Input file name.
 
#define PHASE_FILE_NAME   "${VX_TEST_DATA_PATH}/vx_tutorial_graph_image_gradients_phase_out.bmp"
 Phase file name.
 
#define MAGNITUDE_FILE_NAME   "${VX_TEST_DATA_PATH}/vx_tutorial_graph_image_gradients_magnitude_out.bmp"
 Magnitude file name.
 
#define GRAD_X_FILE_NAME   "${VX_TEST_DATA_PATH}/vx_tutorial_graph_image_gradients_grad_x_out.bmp"
 Gradient X file name.
 
#define GRAD_Y_FILE_NAME   "${VX_TEST_DATA_PATH}/vx_tutorial_graph_image_gradients_grad_y_out.bmp"
 Gradient Y file name.
 

Functions

void vx_tutorial_graph_image_gradients ()
 Tutorial Entry Point. More...
 

Detailed Description

Performs a Sobel filter followed by a magnitude node and phase node on the X and Y outputs of the Sobel filter.

In this tutorial we learn the below concepts,

  • How to create OpenVX context, OpenVX image data object and OpenVX virtual image data object
  • How to read a BMP file and load the pixel values into the image data object
  • How to query the image data object for attributes like width, height
  • How to create OpenVX node and associate it with previously created graph
  • How to choose a CPU core for an OpenVX to execute on
  • How to schedule OpenVX graph for execution then execute the graph
  • How to query the node data object for attributes like width, height
  • How to query the graph data object for attributes like number of nodes and parameters
  • How to read pixel values from an image data object and save it as a BMP file
  • How to cleanup all created resources and exit the OpenVX application

To include OpenVX interfaces include below file

#include <VX/vx.h>

Follow the comments in the function vx_tutorial_graph_image_gradients() to understand this tutorial

Definition in file vx_tutorial_graph_image_gradients.c.

Function Documentation

◆ vx_tutorial_graph_image_gradients()

void vx_tutorial_graph_image_gradients ( )

Tutorial Entry Point.
















































- Define objects that we wish to create in the OpenVX application.

A vx_context object is defined which is used as input parameter for all subesquent OpenVX object create APIs

/
vx_context context;
vx_image in_image = NULL;
vx_image grad_x = NULL;
vx_image grad_y = NULL;
vx_image magnitude = NULL;
vx_image phase = NULL;
vx_image magnitude_image = NULL;
vx_image grad_x_image = NULL;
vx_image grad_y_image = NULL;
vx_graph graph = NULL;
vx_scalar shift = NULL;
vx_node node[NUM_NODES] = {NULL};





























































































- Create OpenVX context.

This MUST be done first before any OpenVX API call. The context that is returned is used as input for subsequent OpenVX APIs

/
context = vxCreateContext();



























































































- Create image object.

Follow the comments in tivx_utils_create_vximage_from_bmpfile() to see how a vx_image object is created and filled with RGB data from BMP file IN_FILE_NAME

























































































- Show image attributes.

Follow the comments in show_image_attributes() to see how image attributes are queried and displayed.























































































- Create OpenVX image object.

Creates an OpenVX image object of 'width' x 'height' and having data format 'df'.

/
grad_x = vxCreateImage(context, width, height, (vx_df_image)VX_DF_IMAGE_S16);





















































































- Show image attributes.

Follow the comments in show_image_attributes() to see how image attributes are queried and displayed.



















































































- Create OpenVX image object.

Creates an OpenVX image object of 'width' x 'height' and having data format 'df'.

/
grad_y = vxCreateImage(context, width, height, (vx_df_image)VX_DF_IMAGE_S16);

















































































- Show image attributes.

Follow the comments in show_image_attributes() to see how image attributes are queried and displayed.















































































- Create OpenVX image object.

Creates an OpenVX image object of 'width' x 'height' and having data format 'df'.

/
magnitude = vxCreateImage(context, width, height, (vx_df_image)VX_DF_IMAGE_S16);













































































- Show image attributes.

Follow the comments in show_image_attributes() to see how image attributes are queried and displayed.

/











































































- Create OpenVX image object.

Creates an OpenVX image object of 'width' x 'height' and having data format 'df'.

/
magnitude_image = vxCreateImage(context, width, height, (vx_df_image)VX_DF_IMAGE_U8);









































































- Show image attributes.

Follow the comments in show_image_attributes() to see how image attributes are queried and displayed.

/
show_image_attributes(magnitude_image);







































































- Create OpenVX image object.

Creates an OpenVX image object of 'width' x 'height' and having data format 'df'.

/
grad_x_image = vxCreateImage(context, width, height, (vx_df_image)VX_DF_IMAGE_U8);





































































- Show image attributes.

Follow the comments in show_image_attributes() to see how image attributes are queried and displayed.

/
show_image_attributes(grad_x_image);



































































- Create OpenVX image object.

Creates an OpenVX image object of 'width' x 'height' and having data format 'df'.

/
grad_y_image = vxCreateImage(context, width, height, (vx_df_image)VX_DF_IMAGE_U8);

































































- Show image attributes.

Follow the comments in show_image_attributes() to see how image attributes are queried and displayed.

/
show_image_attributes(grad_y_image);































































- Create OpenVX image object.

Creates an OpenVX image object of 'width' x 'height' and having data format 'df'.

/
phase = vxCreateImage(context, width, height, (vx_df_image)VX_DF_IMAGE_U8);





























































- Show image attributes.

Follow the comments in show_image_attributes() to see how image attributes are queried and displayed.



























































- Create OpenVX graph.

/
graph = vxCreateGraph(context);

























































- Create OpenVX node object.

Creates an OpenVX Sobel 3x3 node with in_image input and grad_x and grad_y output.

/
node[i] = vxSobel3x3Node(graph, in_image, grad_x, grad_y);























































- Set node target CPU.

Sets target CPU for node[i] to DSP1





















































- Create OpenVX node object.

Creates an OpenVX Magnitude node with grad_x and grad_y input and magnitude output.

/
node[i] = vxMagnitudeNode(graph, grad_x, grad_y, magnitude);



















































- Set node target CPU.

Sets target CPU for node[i] to DSP1

















































- Create OpenVX node object.

Creates an OpenVX Phase node with grad_x and grad_y input and phase output.

/
node[i] = vxPhaseNode(graph, grad_x, grad_y, phase);















































- Set node target CPU.

Sets target CPU for node[i] to DSP2

/
{
}
else /* DSP2 is not present on some platforms, so changing target to DSP1 */
{
}













































- Create OpenVX node object.

Creates an OpenVX Convert Depth node with magnitude input and magnitude_image output. The conversion policy is Saturate and the shift value is shift.

/
node[i] = vxConvertDepthNode(graph,
magnitude, magnitude_image,
shift);











































- Set node target CPU.

Sets target CPU for node[i] to DSP1









































- Create OpenVX node object.

Creates an OpenVX Convert Depth node with grad_x input and grad_x_image output. The conversion policy is Saturate and the shift value is shift.

/
node[i] = vxConvertDepthNode(graph,
grad_x, grad_x_image,
shift);







































- Set node target CPU.

Sets target CPU for node[i] to DSP1





































- Create OpenVX node object.

Creates an OpenVX Convert Depth node with grad_y input and grad_y_image output. The conversion policy is Saturate and the shift value is shift.

/
node[i] = vxConvertDepthNode(graph,
grad_y, grad_y_image,
shift);
vxSetReferenceName((vx_reference)node[i], "GRAD_Y_IMAGE");
{
}
else /* DSP2 is not present on some platforms, so changing target to DSP1 */
{
}



































- Verify graph object.

Verifies that all parameters of graph object are valid.

/
status = vxVerifyGraph(graph);


export graph to dot file, which can be coverted to jpg using dot tool
/
tivxExportGraphToDot(graph, ".", "vx_tutorial_graph_image_gradients");































- Show graph attributes.

Follow the comments in show_graph_attributes() to see how graph attributes are queried and displayed.





























- Show node attributes.

Follow the comments in show_node_attributes() to see how node attributes are queried and displayed.



























- Schedule graph.

Schedules graph for future execution. vxVerifyGraph must return VX_SUCCESS before this function will pass.

/

























- Wait graph.

Waits for graph to complete.

/
vxWaitGraph(graph);























- Show graph attributes.

Follow the comments in show_graph_attributes() to see how graph attributes are queried and displayed.





















- Show node attributes.

Follow the comments in show_node_attributes() to see how node attributes are queried and displayed.



















- Save image object to bitmap file OUT_FILE_NAME.

Follow the comments in tivx_utils_save_vximage_to_bmpfile() to see how data in vx_image object is accessed to store pixel values from the image object to BMP file OUT_FILE_NAME

















- Save image object to bitmap file OUT_FILE_NAME.

Follow the comments in tivx_utils_save_vximage_to_bmpfile() to see how data in vx_image object is accessed to store pixel values from the image object to BMP file OUT_FILE_NAME















- Save image object to bitmap file OUT_FILE_NAME.

Follow the comments in tivx_utils_save_vximage_to_bmpfile() to see how data in vx_image object is accessed to store pixel values from the image object to BMP file OUT_FILE_NAME













- Save image object to bitmap file OUT_FILE_NAME.

Follow the comments in tivx_utils_save_vximage_to_bmpfile() to see how data in vx_image object is accessed to store pixel values from the image object to BMP file OUT_FILE_NAME











- Release image object.

Since we are done with using this image object, release it

/
vxReleaseImage(&in_image);
vxReleaseImage(&grad_x);
vxReleaseImage(&grad_y);
vxReleaseImage(&grad_x_image);
vxReleaseImage(&grad_y_image);
vxReleaseImage(&magnitude);
vxReleaseImage(&magnitude_image);









- Release scalar object.

Since we are done with using this scalar object, release it

/







- Release node object.

Since we are done with using this node object, release it

/
vxReleaseNode(&node[i]);





- Release graph object.

Since we are done with using this graph object, release it

/



- Release context object.

Since we are done using OpenVX context, release it. No further OpenVX API calls should be done, until a context is again created using vxCreateContext()

/
vxReleaseContext(&context);

Definition at line 118 of file vx_tutorial_graph_image_gradients.c.