Skip to main content
Version: 0.11.x

Function: restrictToBox()

restrictToBox(src, dst, box): Tensor

Defined in: extensions/cv/ops/box.ts:212

Masks the source image tensor by keeping only the elements inside the specified bounding box, writing the result to a pre-allocated destination image tensor.

Note: This operation does not change the image tensor dimensions (it does not crop the shape). Instead, it copies the elements within the box coordinates from src to dst, and sets all elements outside the box to 0.

Parameters​

src​

Tensor

The source image tensor in HWC layout. Expected shape [H, W, C] (channels-last). Supports any numeric data type.

dst​

Tensor

The pre-allocated destination image tensor to write masked values to. Expected shape [H, W, C] in HWC layout and the same data type as src.

box​

The bounding box defining the region of interest to copy.

object & Readonly<{ xmax: number; xmin: number; ymax: number; ymin: number; }> | object & Readonly<{ h: number; w: number; xmin: number; ymin: number; }> | object & Readonly<{ cx: number; cy: number; h: number; w: number; }>

Returns​

Tensor

The destination image tensor containing the masked output of shape [H, W, C] and matching data type.

Throws​

With code INVALID_ARGUMENT if tensor shapes, layouts, or data types are invalid, RESOURCE_BUSY if a tensor is in use, or RESOURCE_DISPOSED if either tensor was disposed.