BackgroundReplace

Function Usage

This API is used to merge the input new background image with the existing image and replace the background with the new background in mask mode (dst = background x (1 - mask) + replace x mask). Asynchronous calling is supported.

When background and dst are the same tensor, inplace replacement can be implemented.

Only Atlas inference product support this API.

This API requires CANN 8.0.RC1 or a later version.

The following conditions must be met:

  • The data memory and stream of the input and output tensors must be located in the same device.
  • For synchronization, the device where the input and output tensor data memory is located must be the same as the initialized device.
  • The width and height of each input and output can be different. During compute, the minimum valid region is used for replacement. The valid region is the tensor itself. For example, if a reference rectangle is set for the tensor, the valid region is the reference rectangle.

Prototype

1
APP_ERROR BackgroundReplace(Tensor &background, const Tensor &replace, const Tensor &mask, Tensor &dst, AscendStream &stream = AscendStream::DefaultStream());

Parameters

Parameter

Input/Output

Description

background

Input

Tensor class, input tensor, target tensor to be replaced. The float16 and uint8 types are supported. The dimension can be HW (two-dimensional) or HWC (three-dimensional). C (number of channels) can be 1 or 3. The tensor width can be [1, 4096], and the tensor height can be [1, 4096]. The data memory must be on the device or DVPP.

replace

Input

Tensor class, input tensor, tensor replacement. The float16 and uint8 types are supported. The dimension can be HW (two-dimensional) or HWC (three-dimensional). C (number of channels) can be 1 or 3. The tensor width can be [1, 4096], and the tensor height can be [1, 4096]. The data memory must be on the device or DVPP. The data type and dimension (including C) must be the same as those in the background.

mask

Input

Tensor class, input tensor, mask tensor. The float16 data type is supported, and the dimension can be HW (two-dimensional) or HWC (three-dimensional). When C (number of channels) of background and replace is 1, C can be 1. When C of background and replace is 3, C can be 1 or 3. The tensor width and tensor height can be [1, 4096]. The data memory must be on the device or DVPP.

dst

Output

Tensor class, output tensor, result tensor to be replaced. The float16 and uint8 types are supported. The dimension can be HW (two-dimensional) or HWC (three-dimensional). C can be 1 or 3. The tensor width can be [1, 4096], and the tensor height can be [1, 4096]. The data memory must be on the device or DVPP. The data type and dimension (including C) must be the same as those in the background.

If the value is not empty, the Tensor.Malloc() API needs to be called to allocate memory in advance. Empty tensors can be passed. The data type and dimension of the output tensor are the same as those of background. The width is the minimum width of the valid regions of background, mask, and dst, and the height is the minimum height of the valid region of background, mask, and dst.

stream

Input

AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the API calling is a synchronous operation. In other cases, the API calling is an asynchronous operation.

Response Parameters

Data Structure

Description

APP_ERROR

For details about the returned error codes, see APP_ERROR Description.