CropResize

Function Usage

Cropping and resizing API of the tensor class. It supports asynchronous execution. The tensor memory allocated by calling this API does not need to be managed by the users. It is released by the internal management module.

For details, see Cropping and Resizing.

Only Atlas inference product support this API.

  • The input and output tensors support the YUV_400 and RGB_888 image formats, with input resolution of 4096 x 4096 or smaller.
  • The width and height of the inputTensor image range from 10 x 6 to 4096 x 4096. If the input or output tensor format is YUV_400, the width range is [18, 4096].
  • The width and height of the cropped ROI cannot exceed the actual width and height of the input image. The maximum resolution of the cropped ROI is 4096 x 4096.
    • If the input image is in RGB_888 format, the minimum resolution of the cropped image is 10 x 6.
    • If the input image is in YUV_400 format, the minimum resolution of the cropped image is 18 x 6.
  • The resizing range is from 10 x 6 to 4096 x 4096. If the input image format is YUV_400, the minimum resolution is 18 x 6, and the resizing range is a multiple of [1/32, 16] of the cropped ROI.
  • The number of cropped ROIs cannot be greater than 256. The numbers of cropped ROIs, resizing ranges, and output tensors must be the same.
  • In the output outputTensorVec, if keepMargin is set to true, the width of the output tensor is automatically aligned to a multiple of 16. The default value of the keepMargin parameter is false, indicating that the invalid boundary in the tensor is not reserved. The width and height of the output tensor are the same as those of the resizing width and height.
  • An empty vector can be passed, but the vector cannot have an empty tensor. If a valid region is set for the input tensor, the cropped ROI must be within the valid region. Otherwise, image cropping fails.

Prototype

1
APP_ERROR CropResize(const Tensor &inputTensor, const std::vector<Rect> &cropRectVec, const std::vector<Size> &sizeVec, std::vector<Tensor> &outputTensorVec, const Interpolation interpolation = Interpolation::BILINEAR_SIMILAR_OPENCV, bool keepMargin = false, AscendStream& stream = AscendStream::DefaultStream());

Parameters

Parameter

Input/Output

Description

inputTensor

Input

Tensor of type UINT8. The value cannot be empty. Memory needs to be allocated on the device or DVPP side.

The input tensor width range is [10, 4096], and the height range is [6, 4096]. If the format YUV400 is contained, the width range is [18, 4096].

cropRectVec

Input

List of cropping parameters (Rect class). The number must be the same as that of elements in the output tensor list.

sizeVec

Input

List of resizing parameters (Size class). The number must be the same as that of elements in the output tensor list.

outputTensorVec

Output

List of tensor classes after cropping and resizing.

interpolation

Input

Resizing mode of an input tensor:

1
2
3
HUAWEI_HIGH_ORDER_FILTER = 0
BILINEAR_SIMILAR_OPENCV = 1
NEAREST_NEIGHBOR_OPENCV = 2
The Atlas inference product support the following algorithms (defaulted to 1):
  • 0 and 1: conventional bilinear algorithm, whose compute process is similar to that of OpenCV. When the input and output images are both in RGB format and the resizing range is [1/32, 512], the maximum value difference of a single pixel from OpenCV is ±1.
  • 2: conventional nearest neighbor algorithm, whose compute process is close to that of OpenCV.

keepMargin

Input

Specifies whether to retain the invalid boundary in the tensor in the outputTensor.

The default value is false, indicating that the invalid boundary in the tensor is not reserved. The width and height of the output tensor are the same as those of the resizing width and height.

stream

Input

Stream used for asynchronous execution. The default value is AscendStream::DefaultStream(), indicating that a default stream is created (for synchronous execution).

Response Parameters

Data Structure

Description

APP_ERROR

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