Crop

Function Usage

Image cropping API of the ImageProcessor class. Atlas inference product and Atlas 800I A2 inference product support asynchronous execution. The Image memory allocated using this API does not need to be managed by the user and is released internally. For details about the cropping effect, see Figure 1.

For details, see Cropping.

  • Supported input/output formats of the Image class:
    • Atlas 200/300/500 inference product supports YUV_SP_420 and YVU_SP_420 (nv12 and nv21).
    • Atlas 200I/500 A2 inference product supports YUV_SP_420 and YVU_SP_420 (nv12 and nv21).
    • Atlas inference product and Atlas 800I A2 inference product support YUV_SP_420, YVU_SP_420, RGB_888 and BGR_888 (nv12, nv21, rgb, and bgr). The resolution of the RGB (BGR) image format cannot exceed 4096 x 4096.
  • The actual inputImage resolution range is [18 x 6, 4096 x 4096]. The resolution range of a YUV_SP_420 or YVU_SP_420 image is [18 x 6, 8192 x 8192].
  • The cropped ROI cannot exceed the input image region. It is recommended that the four coordinates of the cropRect be even numbers. If odd numbers are included (excluding RGB and BGR formats), the coordinate of the upper left corner is automatically rounded down to an even number, and the coordinate of the lower right corner is automatically rounded up to an even number.
  • The maximum resolution of the cropped ROI is 4096 x 4096, and the minimum resolution is 18 x 6. For example, if cropRect is set to {1, 1, 1287, 1287}, the actual width and height of the cropped image are ((1287 + 1) - (1 - 1)) = 1288, and the resolution is 1288 x 1288.
  • In the outputImageVec, the width of each image is a multiple of 16, and the height is a multiple of 2. The value range is [32 × 6, 4096 × 4096].
  • In the scenario where images are input in a batch, the number of input images cannot exceed 12, the length of cropRectVec cannot exceed 256, the number of output images cannot exceed 256, and equals Number of input images x Length of cropRectVec.
Figure 1 Cropping

Prototype

Prototype 1:

1
APP_ERROR ImageProcessor::Crop(const Image& inputImage, const Rect& cropRect, Image& outputImage, AscendStream& stream = AscendStream::DefaultStream());

Prototype 2:

1
APP_ERROR ImageProcessor::Crop(const Image& inputImage, const std::vector<Rect>& cropRectVec, std::vector<Image>& outputImageVec, AscendStream& stream = AscendStream::DefaultStream());

Prototype 3:

1
APP_ERROR ImageProcessor::Crop(const std::vector<Image>& inputImageVec, const std::vector<Rect>& cropRectVec, std::vector<Image>& outputImageVec, AscendStream& stream = AscendStream::DefaultStream());

Parameters

Parameter

Input/Output

Description

inputImage

Input

Image class before cropping.

The Image class obtained by the Decode API and other VPC APIs can be directly used as inputs. If the user-defined Image class is used, set the image width and height.

inputImageVec

Input

List of the Image class before cropping (application scenario: image cropping in a batch).

cropRect

Input

Coordinates for image cropping

cropRectVec

Input

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

outputImage

Output

Image class after cropping.

outputImageVec

Output

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

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.