Region of Interest

This chapter describes the use of a Region of Interest in TwinCAT Vision.

What is a Region of Interest?

A Region of Interest (ROI) is a rectangular image region to which an image is temporarily restricted. The image itself is not changed, but the section to be processed merely reduced in size. An ROI can be reset to the entire image at any time.

What is a Region of Interest needed for?

An existing image is frequently larger than the area to be processed. In this case an ROI should be set in order to obtain the following advantages:

  1. Better performance: The image processing time is shorter if the image region to be processed is smaller.
  2. Less interference: Interfering image objects that are outside the ROI are excluded from processing and therefore do not affect the result.

It is equally possible through the use of ROIs to process several image areas separately by setting the ROI at various points in the image, one after the other.

Notice

ROI configuration in the camera

If you use a camera as an image source, it is best to implement an ROI there in order to reduce the data quantity to be transmitted and to keep it as low as possible. Depending on the setting and sensor, the possible frame rate may also increase as a result of this. See camera configuration examples: Region of Interest (ROI)

How is a Region of Interest technically displayed?

The information about a set ROI is stored in TwinCAT Vision directly in the respective image object. The setting of an ROI merely consists of the setting of a rectangle description. The image data outside of this area still exist, but they are ignored when calling functions.

The rectangle description consists of the position (nX and nY) of the top left corner and the size (nWidth and nHeight) of the rectangle. Make sure that the rectangle does not extend beyond the edge of the picture (nWidth ≤ ImageWidth - nX and nHeight ≤ ImageHeight - nY).

Region of Interest 1:

To set an ROI, these parameters are transferred directly or as a structure of the type TcVnRectangle_UDINT, depending on the function:

The function F_VN_GetRoi is available for checking whether and which ROI is set on an image. An ROI can also be set on an image that already has an ROI. The function F_VN_ResetRoi can be used if the ROI is to be enlarged or reset to the entire image size.