Crop

Function Usage

Image cropping API of the ImageProcessor class. The memory allocated by this API does not need to be managed or destroyed by users.

  • For details about the input and output image formats of the Image class, see ImageFormat.
  • The original width and height of the input Image class range from 18 x 6 to 4096 x 4096. For images in YUV_SP_420 and YVU_SP_420 formats, the width and height can be 8192 x 8192.
  • The width of the output image automatically becomes a multiple of 16, and the height becomes a multiple of 2. Therefore, the width and height range from 32 x 6 to 4096 x 4096.
  • The maximum resolution of the output Image class (cropRect) is 4096 x 4096, and the minimum resolution is 18 x 6.
  • The crop ROI cannot be larger than the input image.
  • Due to hardware interface restrictions, it is recommended that the four values of cropRect be even numbers. If odd numbers are included, 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.

    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.

Prototype

APP_ERROR Crop(const Image& inputImage, const Rect& cropRect, Image& outputImage);
APP_ERROR Crop(const Image& inputImage, const std::vector<Rect>& cropRectVec,
               std::vector<Image>& outputImageVec);

Parameter Description

Parameter

Input/Output

Description

inputImage

Input

Image class before cropping.

The Image classes 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.

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

Return Parameter Description

Data Structure

Description

APP_ERROR

Error code returned during program execution. For details, see the MxBase/ErrorCode/ErrorCode.h file.