CropAndPaste

Function Usage

Image cropping and pasting API of the ImageProcessor class. The procedure is as follows:

  1. Crops an image from inputImage.
  2. Resizes the image based on the size of the specified pasting area.
  3. Pastes the resized image to the area specified by pastedImage.
    • 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.
    • Supported input and output image formats: YUV_SP_420, YVU_SP_420, RGB_888, and BGR_888
    • The width and height of the cropped image cannot exceed that value of the original width and height of inputImage, and the width and height of the pasted image cannot exceed the value of original width and height of pastedImage.
    • The minimum size of the cropping and pasting ROI is 10 x 6, and the maximum size is 4096 x 4096.
    • 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.
    • For the Atlas 200/300/500 inference product, the width and height of the pasted image cannot exceed a multiple of [1/32, 16] of the width and height of the cropped image.
    • For the Atlas 200/300/500 inference product, it is recommended that the x value in the lower right corner of rect be a multiple of 16. For the Atlas inference products, the actual width of rect must be a multiple of 16. Otherwise, invalid data is padded.
    • 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.

    • Due to hardware interface restrictions, it is recommended that the four values of pasteRect be even numbers. If odd numbers are contained, 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. In addition, the x value of the coordinate of the upper left corner is automatically aligned to a multiple of 16.

      See the following example:

      • If pasteRect is set to {17, 17, 1287, 1287}, the actual width and height of the cropped image are ((1287 + 1) - (17 - 1))= 1272.
      • If pasteRect is set to {18, 18, 1287, 1287}, the actual width of the cropped image is ((1287 + 1) - 32) = 1256, and the actual height is ((1287 + 1) - 18) = 1270.

Prototype

APP_ERROR CropAndPaste(const Image& inputImage, const std::pair<Rect, Rect>& cropPasteRect,
                       Image& pastedImage);

Parameter Description

Parameter

Input/Output

Description

inputImage

Input

Image class before cropping and resizing.

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 original and aligned image widths and heights.

cropPasteRect

Input

Parameters for image cropping and resizing. The first Rect corresponds to the cropping parameter, and the second one corresponds to the pasting parameter.

pastedImage

Input/Output

Image class after cropping

Return Parameter Description

Data Structure

Description

APP_ERROR

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