TIOVX User Guide
vx_tutorial_image_color_convert.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 OUT_FILE_NAME   "${VX_TEST_DATA_PATH}/vx_tutorial_image_color_convert_out.bmp"
 Output file name.
 

Functions

void vx_tutorial_image_color_convert ()
 Tutorial Entry Point. More...
 
void show_graph_attributes (vx_graph graph)
 Show attributes of previously created graph. More...
 
void show_node_attributes (vx_node node)
 Show attributes of previously created node. More...
 

Detailed Description

Convert image from RGB format to NV12 format then extract luma channel

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 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_image_color_convert() to understand this tutorial

As part of this tutorial, we create few utility functions as listed below. These functions will be used in subsequent tutorials to display node and graph attributes.

Utility function Description
show_graph_attributes() Displays attributes of a previously created graph. NOTE: This function though listed in this tutorial is used in later tutorials
show_node_attributes() Displays attributes of a previously created node. NOTE: This function though listed in this tutorial is used in later tutorials

Definition in file vx_tutorial_image_color_convert.c.

Function Documentation

◆ vx_tutorial_image_color_convert()

void vx_tutorial_image_color_convert ( )

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 rgb_image = NULL;
vx_image nv12_image = NULL;
vx_image y_image = NULL;
vx_node node0 = NULL, node1 = NULL;
vx_graph graph = 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 OpenVX graph.

/
graph = vxCreateGraph(context);









































- 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 virtual image object.

Creates an OpenVX virtual image object of 'width' x 'height' and having data format 'df'. Virtual images are allowed to have a value of 0 for width and height.

/



































- 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'.

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































- Create OpenVX node object.

Creates an OpenVX Color Convert node with rgb_image input and nv12_image output.

/
node0 = vxColorConvertNode(graph, rgb_image, nv12_image);





























- Create OpenVX node object.

Creates an OpenVX Channel Combine node with nv12_image input and y_image output. It extracts the channel VX_CHANNEL_Y from input image.

/
node1 = vxChannelExtractNode(graph, nv12_image, (vx_enum)VX_CHANNEL_Y, y_image);



























- 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_image_color_convert");























- 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









- Release image object.

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

/
vxReleaseImage(&rgb_image);
vxReleaseImage(&nv12_image);
vxReleaseImage(&y_image);







- Release node object.

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

/
vxReleaseNode(&node0);
vxReleaseNode(&node1);





- 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 126 of file vx_tutorial_image_color_convert.c.

◆ show_graph_attributes()

void show_graph_attributes ( vx_graph  graph)

Show attributes of previously created graph.

This function queries the vx_graph graph for its number of nodes, number of parameters, state, performance, reference name and reference count then prints this information.

Parameters
graph[in] Previouly created graph object
  • Query graph attributes.

Queries graph for number of nodes, number of parameters, state and performance

/
vxQueryGraph(graph, (vx_enum)VX_GRAPH_NUMNODES, &num_nodes, sizeof(vx_uint32));
vxQueryGraph(graph, (vx_enum)VX_GRAPH_NUMPARAMETERS, &num_params, sizeof(vx_uint32));
vxQueryGraph(graph, (vx_enum)VX_GRAPH_STATE, &state, sizeof(vx_enum));

Definition at line 406 of file vx_tutorial_image_color_convert.c.

◆ show_node_attributes()

void show_node_attributes ( vx_node  node)

Show attributes of previously created node.

This function queries the vx_node node for its status, number of parameters, performance, reference name and reference count then prints this information.

Parameters
node[in] Previouly created graph object
  • Query node attributes.

Queries node for number of status, number of parameters and performance

/
vxQueryNode(node, (vx_enum)VX_NODE_STATUS, &status, sizeof(vx_status));
vxQueryNode(node, (vx_enum)VX_NODE_PARAMETERS, &num_params, sizeof(vx_uint32));

Definition at line 477 of file vx_tutorial_image_color_convert.c.