TIOVX User Guide
vx_tutorial_image_crop_roi.c File Reference
#include <stdio.h>
#include <VX/vx.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_crop_roi.bmp"
 Output file name.
 

Functions

vx_image load_image_from_handle_from_file (vx_context context, char *filename, vx_bool convert_to_gray_scale, tivx_utils_bmp_image_params_t *imgParams)
 Load image from handle from file. More...
 
void vx_tutorial_image_crop_roi ()
 Tutorial Entry Point. More...
 

Detailed Description

Crop a rectangular region from an image

In this tutorial we learn the below concepts,

  • How to create OpenVX context and OpenVX image data object
  • How to read a BMP from handle from 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 an image from a rectangular region of another image
  • 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>

To include utility APIs to read and write BMP file include below file

#include <bmp_rd_wr.h>

Follow the comments in the function vx_tutorial_image_crop_roi() 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 load and save images.

Utility function Description
load_image_from_handle_from_file() Loads an image data object from handle from file

Definition in file vx_tutorial_image_crop_roi.c.

Function Documentation

◆ load_image_from_handle_from_file()

vx_image load_image_from_handle_from_file ( vx_context  context,
char *  filename,
vx_bool  convert_to_gray_scale,
tivx_utils_bmp_image_params_t *  imgParams 
)

Load image from handle from file.

Parameters
context[in] Context
filename[in] BMP filename, MUST have extension of .bmp
convert_to_gray_scale[in] vx_true_e: Converts RGB values in BMP file to 8b grayscale value and copies them to image object
vx_false_e: Retains RGB values from BMP file and copies them to image object
bmp_file_context[in] BMP file context
Returns
Image data object from file.


- Create image from handle.

Creates a reference to image object that was externally allocated

/
image = vxCreateImageFromHandle(context, df, image_addr, ptrs, (vx_enum)VX_MEMORY_TYPE_HOST);

Definition at line 253 of file vx_tutorial_image_crop_roi.c.

◆ vx_tutorial_image_crop_roi()

void vx_tutorial_image_crop_roi ( )

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 image, roi_image;
vx_uint32 width, height;
tivx_utils_bmp_image_params_t imgParams;













- 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();











- Show image attributes.

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









- Create image from region of interest.

Creates an image from another image given a rectangle

/
roi_image = vxCreateImageFromROI(image, &rect);
vxSetReferenceName((vx_reference)roi_image, "CROP_ROI");







- 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(&roi_image);



- 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 124 of file vx_tutorial_image_crop_roi.c.