Skip to main content
SDK Version: 2.3.3

DxPreprocess

DxPreprocess is an element that performs input preprocessing on raw video frames, converting them into a format suitable for AI models used by DxInfer. Each preprocessed input tensor is assigned an input ID specified by the preprocess-id property.

DxInfer must reference this ID in its own configuration to determine which tensor to use for inference.

Multiple DxPreprocess elements can co-exist in the same pipeline, enabling support for multi-input models or customized preprocessing steps for different video streams.

Key Features

Color Conversion

DxPreprocess converts the image color format to RGB or BGR based on the color-format property.

  • Default format: RGB.

Modes of Operation

  • Primary Mode applies preprocessing to the entire frame. If object detection is performed within the same pipeline, DxPreprocess will operate in this mode.
  • Secondary Mode applies preprocessing to individual object regions detected in this frame. This mode requires object metadata (e.g., from an upstream object detection element).

Region of Interest (ROI)
The Region of Interest (ROI) is defined using the roi property.

  • In Primary Mode, the specified ROI area is cropped and preprocessed as a whole.
  • In Secondary Mode, only objects that are fully contained within the ROI are selected for preprocessing.

Processing Interval
The processing interval is controlled by the interval property. It skips a specified number of frames before preprocessing the next frame or object. This is useful for reducing processing frequency in resource-constrained environments.

Object Filtering in Secondary Mode
Objects can be filtered based on the following criteria.

  • Class ID: Use the target-class-id property to process only objects that match the specified class. Non-matching objects are ignored.
  • Size : Use the min-object-width and min-object-height properties to exclude objects smaller than the defined size.

Resizing
DxPreprocess resizes full frames or object regions using the resize-width and resize-height property.
If keep-ratio is set to true, the aspect ratio is preserved by applying padding.
Padding color is set using the pad-value property.

Custom Preprocessing
User-defined preprocessing logic can be implemented by providing:

  • library-file-path : Path to the custom shared library (.so).
  • function-name : Name of the preprocessing function within the library.

The custom function signature has been updated to include GstBuffer access:

extern "C" bool PreProcess(GstBuffer *buf,
DXFrameMeta *frame_meta,
DXObjectMeta *object_meta,
void *output);

This allows implementation of customized data handling tailored to specific AI models with direct access to the GStreamer buffer.

QoS Handling
If the downstream sink element has sync=true, input buffers may be dropped based on their timestamps. This helps maintain real-time performance and avoids frame backlog under system load.

H/W Acceleration
If the Rockchip RGA (Raster Graphic Accelerator) module is available in the system environment, the input preprocessing step is offloaded from the CPU to the RGA, enabling hardware-accelerated processing. As a result, CPU usage is reduced and processing becomes more efficient.

Hierarchy

GObject
+----GInitiallyUnowned
+----GstObject
+----GstElement
+----GstBaseTransform
+----GstDxPreprocess

Properties

This table provides a complete reference to the properties of the DxPreprocess element.

NameDescriptionTypeDefault Value
nameSets the unique name of the DxPreprocess element.String"dxpreprocess0"
config-file-pathPath to the JSON config file containing the element's properties.Stringnull
preprocess-idAssigns an ID to the preprocessed input tensor.Unsigned Integer0
resize-widthSpecifies the width for resizing.Unsigned Integer0
resize-heightSpecifies the height for resizing.Unsigned Integer0
keep-ratioMaintains the original aspect ratio during resizing.Booleantrue
pad-valuePadding color value for R, G, B pixels duringUnsigned Integer0
color-formatSpecifies the color format for preprocessing. (0: RGB, 1: BGR)Unsigned Integer0 (RGB)
secondary-modeEnables Secondary Mode for processing object regions.Booleanfalse
target-class-idFilters objects in Secondary Mode by class ID. (-1 processes all objects).Integer-1
min-object-widthMinimum object width for preprocessing in Secondary Mode.Unsigned Integer0
min-object-heightMinimum object height for preprocessing in Secondary Mode.Unsigned Integer0
roiDefines the ROI (Region of Interest) for preprocessing as a comma-separated string "x1,y1,x2,y2".String"-1,-1,-1,-1"
intervalSpecifies the interval for preprocessing frames or objects.Unsigned Integer0
transposeEnables transposing of the output tensor axes.Booleanfalse
library-file-pathPath to the custom preprocess library, if used.Stringnull
function-nameName of the custom preprocessing function to use.Stringnull

Example JSON Configuration

{
"preprocess_id": 1,
"resize_width": 640,
"resize_height": 640,
"keep_ratio": true
}
NOTE
  • For implementing custom preprocess logic, refer to Chapter. Writing Your Own Application “Custom Pre-Process Library Documentation”.
  • All properties can also be configured using a JSON file for enhanced usability and flexibility.