WarpPerspective

Function Usage

Perspective transformation API. It projects a two-dimensional image to a three-dimensional view plane and then converts the image into two-dimensional coordinates. Asynchronous calling is supported.

Only Atlas inference product support this API.

The following conditions must be met:

  • The input and output tensors must be on the device or DVPP side, and the parameters (stream and data memory) must be on the same device.
  • For synchronization, the device where the data memory is located must be the same as the initialized device.
  • The output tensor width and height are calculated based on the input tensor and conversion matrix. Empty output tensors are supported. If an output tensor is empty, its output shape is the same as the shape of the input tensor by default.
  • When the data type of the input tensor is Float32 or Uint8 and the recommended size is 480p (640 x 480), the compute performance is better than that of cv::warpPerspective on the CPU.

Prototype

1
APP_ERROR WarpPerspective(const Tensor &src, Tensor &dst, const std::vector<std::vector<float>> transMatrix, const PaddingMode paddingMode, const float borderValue, const WarpPerspectiveMode warpPerspectiveMode, AscendStream &stream = AscendStream::DefaultStream());

Parameters

Parameter

Input/Output

Description

src

Input

Tensor class, input tensor that requires perspective transformation. The uint8, float16, and float32 types are supported. The dimension must be NHWC (four-dimensional). The range of N (number of tensors) is [1, 16], and that of C (number of channels) is [1, 4]. The tensor width range is [32, 2160], the tensor height range is [32, 3840], and the data memory must be on the device or DVPP. Empty tensor cannot be passed.

dst

Output

Tensor class, output tensor. If the value is not an empty tensor, call Tensor.Malloc() to allocate memory in advance. The dimension can be NHWC (four-dimensional). The range of N (number of tensors) is [1, 16], and that of C (number of channels) is [1, 4]. The tensor width and tensor height are calculated based on the input tensor and conversion matrix, the data memory must be on the device or DVPP. The data type, processor ID, number of tensors, and number of channels must be the same as those of the input tensor. Empty tensors can be passed. (When an empty tensor is passed, the output shape is the same as the shape of the input tensor by default.)

transMatrix

Input

Transformation matrix. The size must be in 3x3 format. The matrix determinant value is 0.

paddingMode

Input

Enumeration class, corresponding to the padding mode. Only constant values (PADDING_CONST) are supported. For details, see PaddingMode.

borderValue

Input

Padding value, with the range of [0, 255].

warpPerspectiveMode

Input

Enumeration class, corresponding to the interpolation mode. Only bilinear interpolation (INTER_LINEAR) is supported. For details, see WarpPerspectiveMode.

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.

If the "Synchronize stream execution failed" error occurs when the WarpPerspective API is executed, handle the issue by referring to Error "Synchronize stream execution failed" Occurs When WarpAffineHiper or WarpPerspective Is Running.