Crop

Function Usage

Cropping 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.

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 actual inputTensor resolution range is [10 x 6, 4096 x 4096]. If the input image is in YUV_400 format, the resolution range is [18 x 6, 4096 x 4096].
  • The cropped image cannot exceed the input image. The maximum resolution of the cropped image 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.
  • In the output outputTensorVec or outputTensor, if keepMargin is set to true, the width of the output image is a multiple of 16, ranging from 10 x 6 to 4096 x 4096. 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 cropped ROI.
  • 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.
  • Batch cropping supports only one input tensor. The length of cropRectVec cannot exceed 256. The number of output tensors cannot exceed 256, and equals to Number of input images x Length of cropRectVec.

Prototype

Prototype 1:

1
APP_ERROR Crop(const Tensor &inputTensor, const Rect &cropRect, Tensor &outputTensor, bool keepMargin = false, AscendStream& stream = AscendStream::DefaultStream());

Prototype 2:

1
APP_ERROR Crop(const Tensor &inputTensor, const std::vector<Rect> &cropRectVec, std::vector<Tensor> &outputTensorVec, 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 YUV_400 is contained, the width range is [18, 4096].

cropRect

Input

Cropped rectangle of the input tensor, which cannot exceed the width and height range of the input tensor.

cropRectVec

Input

List of coordinates tensor cropping (application scenario: image cropping in a batch).

outputTensor

Output

Tensor class after cropping.

outputTensorVec

Output

List of the tensor class after cropping (application scenario: image cropping in a batch).

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 cropped image.

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.