TIOVX User Guide
vx_tutorial_graph_user_kernel.c
Go to the documentation of this file.
1 /*
2 *
3 * Copyright (c) 2017 Texas Instruments Incorporated
4 *
5 * All rights reserved not granted herein.
6 *
7 * Limited License.
8 *
9 * Texas Instruments Incorporated grants a world-wide, royalty-free, non-exclusive
10 * license under copyrights and patents it now or hereafter owns or controls to make,
11 * have made, use, import, offer to sell and sell ("Utilize") this software subject to the
12 * terms herein. With respect to the foregoing patent license, such license is granted
13 * solely to the extent that any such patent is necessary to Utilize the software alone.
14 * The patent license shall not apply to any combinations which include this software,
15 * other than combinations with devices manufactured by or for TI ("TI Devices").
16 * No hardware patent is licensed hereunder.
17 *
18 * Redistributions must preserve existing copyright notices and reproduce this license
19 * (including the above copyright notice and the disclaimer and (if applicable) source
20 * code license limitations below) in the documentation and/or other materials provided
21 * with the distribution
22 *
23 * Redistribution and use in binary form, without modification, are permitted provided
24 * that the following conditions are met:
25 *
26 * * No reverse engineering, decompilation, or disassembly of this software is
27 * permitted with respect to any software provided in binary form.
28 *
29 * * any redistribution and use are licensed by TI for use only with TI Devices.
30 *
31 * * Nothing shall obligate TI to provide you with source code for the software
32 * licensed and provided to you in object code.
33 *
34 * If software source code is provided to you, modification and redistribution of the
35 * source code are permitted provided that the following conditions are met:
36 *
37 * * any redistribution and use of the source code, including any resulting derivative
38 * works, are licensed by TI for use only with TI Devices.
39 *
40 * * any redistribution and use of any object code compiled from the source code
41 * and any resulting derivative works, are licensed by TI for use only with TI Devices.
42 *
43 * Neither the name of Texas Instruments Incorporated nor the names of its suppliers
44 *
45 * may be used to endorse or promote products derived from this software without
46 * specific prior written permission.
47 *
48 * DISCLAIMER.
49 *
50 * THIS SOFTWARE IS PROVIDED BY TI AND TI'S LICENSORS "AS IS" AND ANY EXPRESS
51 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
52 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
53 * IN NO EVENT SHALL TI AND TI'S LICENSORS BE LIABLE FOR ANY DIRECT, INDIRECT,
54 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
55 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
56 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
57 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
58 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
59 * OF THE POSSIBILITY OF SUCH DAMAGE.
60 *
61 */
62 
63 
130 #include <stdio.h>
131 #include <VX/vx.h>
132 #include <TI/tivx.h>
133 #include <utility.h>
135 
137 #define IN_FILE_NAME "${VX_TEST_DATA_PATH}/vx_tutorial_graph_image_gradients_phase_out.bmp"
138 
140 #define OUT_USER_KERNEL_FILE_NAME "${VX_TEST_DATA_PATH}/vx_tutorial_graph_user_kernel_out.bmp"
141 
143 #define OUT_TARGET_KERNEL_FILE_NAME "${VX_TEST_DATA_PATH}/vx_tutorial_graph_target_kernel_out.bmp"
144 
151 void vx_tutorial_graph_user_kernel(vx_bool add_as_target_kernel)
152 {
160  vx_context context;
161  vx_image in_image = NULL;
162  vx_image out_image = NULL;
163  vx_node node = NULL;
164  vx_graph graph = NULL;
166  vx_uint32 width, height;
167  vx_status status;
168 
177  char *out_file = OUT_USER_KERNEL_FILE_NAME;
178 
179  if(add_as_target_kernel)
180  {
181  out_file = OUT_TARGET_KERNEL_FILE_NAME;
182  }
185  printf(" vx_tutorial_graph_user_kernel: Tutorial Started !!! \n");
186 
192  context = vxCreateContext();
210  status = phase_rgb_user_kernel_add(context, add_as_target_kernel);
211  if(status!=(vx_status)VX_SUCCESS)
212  {
213  printf(" vx_tutorial_graph_user_kernel: ERROR: unable to add user kernel !!!\n");
214  }
217  if(status==(vx_status)VX_SUCCESS)
218  {
219  printf(" Loading file %s ...\n", IN_FILE_NAME);
220 
231  vxSetReferenceName((vx_reference)in_image, "INPUT");
232  show_image_attributes(in_image);
233 
234  vxQueryImage(in_image, (vx_enum)VX_IMAGE_WIDTH, &width, sizeof(vx_uint32));
235  vxQueryImage(in_image, (vx_enum)VX_IMAGE_HEIGHT, &height, sizeof(vx_uint32));
244  out_image = vxCreateImage(context, width, height, (vx_df_image)VX_DF_IMAGE_RGB);
245  vxSetReferenceName((vx_reference)out_image, "OUTPUT");
246  show_image_attributes(out_image);
254  graph = vxCreateGraph(context);
263  node = phase_rgb_user_kernel_node(graph, in_image, out_image);
270  status = vxVerifyGraph(graph);
271 
272  show_graph_attributes(graph);
273  show_node_attributes(node);
279  tivxExportGraphToDot(graph, ".", "vx_tutorial_graph_user_kernel");
288  if(status==(vx_status)VX_SUCCESS)
289  {
290  printf(" Executing graph ...\n");
291 
292  vxScheduleGraph(graph);
293  vxWaitGraph(graph);
294 
295  printf(" Executing graph ... Done !!!\n");
296 
297  show_graph_attributes(graph);
298  show_node_attributes(node);
299 
300  printf(" Saving to file %s ...\n", out_file);
301  tivx_utils_save_vximage_to_bmpfile(out_file, out_image);
302  }
310  vxReleaseImage(&in_image);
311  vxReleaseImage(&out_image);
312  vxReleaseNode(&node);
313  vxReleaseGraph(&graph);
324  }
330  vxReleaseContext(&context);
333  printf(" vx_tutorial_graph_user_kernel: Tutorial Done !!! \n");
334  printf(" \n");
335 }
336 
struct _vx_image * vx_image
vx_bool
vx_status VX_API_CALL vxQueryImage(vx_image image, vx_enum attribute, void *ptr, vx_size size)
Interface to TI extension APIs.
void show_node_attributes(vx_node node)
Show attributes of previously created node.
int32_t vx_enum
vx_status phase_rgb_user_kernel_remove(vx_context context)
Remove user/target kernel from context.
VX_SUCCESS
void show_graph_attributes(vx_graph graph)
Show attributes of previously created graph.
vx_true_e
#define IN_FILE_NAME
Input file name.
vx_status VX_API_CALL vxReleaseContext(vx_context *context)
vx_enum vx_status
struct _vx_context * vx_context
struct _vx_reference * vx_reference
#define OUT_USER_KERNEL_FILE_NAME
Output file name when tutorial is run with user kernel.
uint32_t vx_df_image
VX_DF_IMAGE_RGB
VX_IMAGE_WIDTH
#define OUT_TARGET_KERNEL_FILE_NAME
Output file name when tutorial is run with target kernel.
vx_image VX_API_CALL vxCreateImage(vx_context context, vx_uint32 width, vx_uint32 height, vx_df_image color)
vx_status VX_API_CALL vxWaitGraph(vx_graph graph)
vx_status VX_API_CALL vxReleaseGraph(vx_graph *graph)
void vx_tutorial_graph_user_kernel(vx_bool add_as_target_kernel)
Tutorial Entry Point.
vx_status VX_API_CALL vxSetReferenceName(vx_reference ref, const vx_char *name)
vx_status phase_rgb_user_kernel_add(vx_context context, vx_bool add_as_target_kernel)
Add user/target kernel to OpenVX context.
void show_image_attributes(vx_image image)
Show attributes of previously created image.
vx_image tivx_utils_create_vximage_from_bmpfile(vx_context context, const char *filename, vx_bool convert_to_gray_scale)
Create a image data object given BMP filename as input.
vx_node phase_rgb_user_kernel_node(vx_graph graph, vx_image in, vx_image out)
User/target kernel node create function.
uint32_t vx_uint32
vx_graph VX_API_CALL vxCreateGraph(vx_context context)
vx_status VX_API_CALL vxVerifyGraph(vx_graph graph)
vx_status VX_API_CALL vxScheduleGraph(vx_graph graph)
vx_context VX_API_CALL vxCreateContext()
struct _vx_graph * vx_graph
vx_status VX_API_CALL tivxExportGraphToDot(vx_graph graph, const char *output_file_path, const char *output_file_prefix)
Export graph representation as DOT graph file.
vx_status VX_API_CALL vxReleaseNode(vx_node *node)
vx_status tivx_utils_save_vximage_to_bmpfile(const char *filename, vx_image image)
Save data from image object to PNG file.
struct _vx_node * vx_node
vx_status VX_API_CALL vxReleaseImage(vx_image *image)
VX_IMAGE_HEIGHT