Customizing Pre-processing and Visual Overlays
DeGirumJS provides a rich set of user-facing properties that allow you to precisely control how input data is handled before inference (pre-processing) and how inference results are visually presented (overlays). This flexibility enables you to tailor the SDK's behavior to your specific application needs and aesthetic preferences.
The following examples show the parameters set as options when you load a model using zoo.loadModel().
You can always set the parameters by simply invoking the corresponding setter methods on a model instance after it has been loaded.
Input Handling (Pre-processing)
The SDK automatically resizes and prepares your input images to match the dimensions required by the AI model. You can customize this process using the following parameters:
-
inputPadMethod: This parameter determines how the input image is scaled and positioned within the model's input frame. Determines how your input image is sent to the model.-
'letterbox'(Default): The image is resized to fit within the model's input dimensions while preserving its original aspect ratio. Any empty space (padding) around the image is filled with the color specified byinputLetterboxFillColor. This method prevents distortion and is generally recommended for most vision models. -
'stretch': The image is stretched or shrunk to exactly match the model's input dimensions, regardless of its original aspect ratio. This can lead to image distortion but ensures the entire image fills the input frame. -
'crop-first': The image is first cropped to match the aspect ratio of the model's input, and then resized. TheinputCropPercentagedetermines how much of the original image is retained. -
'crop-last': The image is resized first, and then cropped to fit the model's input dimensions.
-
-
inputLetterboxFillColor: WheninputPadMethodis'letterbox', this parameter sets the RGB color of the padded areas.- Type:
Array<number>(e.g.,[R, G, B], where each component is 0-255) - Default:
[0, 0, 0](black)
- Type:
-
inputCropPercentage: This parameter is used in conjunction with'crop-first'and'crop-last'inputPadMethodvalues. It specifies the percentage of the image (after initial scaling for'crop-last') that should be retained after cropping.- Type:
number(between 0 and 1) - Default:
1.0
- Type:
Overlay Customization
The model.displayResultToCanvas() method draws visual overlays (like bounding boxes, labels, and keypoints) on a canvas. You can customize the appearance of these overlays using the following parameters:
-
overlayAlpha: Controls the transparency of the drawn overlays. A value of1.0means fully opaque, while0.0means fully transparent.- Type:
number(between 0 and 1) - Default:
0.75
- Type:
-
overlayColor: Sets the color(s) for drawing overlays. You can provide a single RGB triplet for a uniform color or an array of RGB triplets to cycle through different colors for different detected objects/classes. -
overlayFontScale: Adjusts the size of text labels (e.g., class names, probabilities) drawn on the overlay. A value of1.0is the default size.- Type:
number(positive number) - Default:
1.0
- Type:
-
overlayLineWidth: Sets the width of lines used in overlays, such as bounding box borders and connections in pose detection.- Type:
number(positive number) - Default:
2
- Type:
-
overlayShowLabels: A boolean flag to control the visibility of text labels (e.g., "person", "car") on the overlay.- Type:
boolean - Default:
true
- Type:
-
overlayShowProbabilities: A boolean flag to control the visibility of confidence scores (probabilities) alongside labels on the overlay.- Type:
boolean - Default:
false
- Type:
-
autoScaleDrawing: When set totrue, the SDK automatically scales the drawn overlays (bounding boxes, labels, keypoints) to appear consistent regardless of the input image's original dimensions or the canvas size. It usestargetDisplayWidthandtargetDisplayHeightas reference.- Type:
boolean - Default:
false
- Type:
-
targetDisplayWidth/targetDisplayHeight: These optional parameters are used in conjunction withautoScaleDrawing. They define a reference canvas size (e.g.,1920x1080) against which the overlay elements are scaled. If your target canvas size is different from the default, you can adjust these values to ensure optimal visual presentation.- Type:
number - Defaults:
1920for width,1080for height
- Type:
Label Filtering
You can control which detected objects or classification results are included in the final output by filtering them based on their labels. This is particularly useful when you are only interested in a subset of the classes a model can detect.
-
labelBlacklist: An array of strings. Any result whoselabelmatches an entry in this list will be excluded from the final output.- Type:
Array<string> - Default:
null(no labels are blacklisted by default)
- Type:
-
labelWhitelist: An array of strings. If this list is provided, only results whoselabelmatches an entry in this list will be included in the final output. All other labels will be filtered out.- Type:
Array<string> - Default:
null(no labels are whitelisted by default, all are included unless blacklisted)
- Type:
Note on Whitelist and Blacklist: If both labelWhitelist and labelBlacklist are provided, the labelWhitelist takes precedence. Only items present in the whitelist will be considered, and then any of those items also present in the blacklist will be removed. It's generally recommended to use one or the other for clarity.