mxpi_imagecrop

Function

  • Allows you to crop the image based on the (x, y) coordinates and (width, height) of the detected object.
  • Allows you to specify the expanding ratio in four directions (up, down, left, and right) to crop the area of the object frame.
  • Allows you to specify the width and height of the cropped image.

Synchronous/Asynchronous (Status)

Synchronous

Constraints

  • Input port 0 is used to receive image data and the coordinate data of the cropped image.
  • Input port 1 is used to receive image data (such as the resized image data).
  • Minimum resolution of the input image: 32 x 32
  • Restrictions on the cutout range:
    • For Ascend: The height ranges from 6 to 4096 and the width ranges from 10 to 4096.
    • For OpenCV: The height ranges from 1 to 8192 and the width ranges from 1 to 8192.
  • Formats that support both 4K and 8K images:
    MXPI_PIXEL_FORMAT_YUV_SEMIPLANAR_420 = 1, // 1, YUV420SP NV12 8bit
    MXPI_PIXEL_FORMAT_YVU_SEMIPLANAR_420 = 2, // 2, YUV420SP NV21 8bit
  • Formats that support only 4K images:
    MXPI_PIXEL_FORMAT_YUV_400 = 0, // 0, YUV400 8bit
    MXPI_PIXEL_FORMAT_YUV_SEMIPLANAR_422 = 3, // 3, YUV422SP NV12 8bit
    MXPI_PIXEL_FORMAT_YVU_SEMIPLANAR_422 = 4, // 4, YUV422SP NV21 8bit
    MXPI_PIXEL_FORMAT_YUV_SEMIPLANAR_444 = 5, // 5, YUV444SP NV12 8bit
    MXPI_PIXEL_FORMAT_YVU_SEMIPLANAR_444 = 6, // 6, YUV444SP NV21 8bit
    MXPI_PIXEL_FORMAT_YUYV_PACKED_422 = 7, // 7, YUV422P YUYV 8bit
    MXPI_PIXEL_FORMAT_UYVY_PACKED_422 = 8, // 8, YUV422P UYVY 8bit
    MXPI_PIXEL_FORMAT_YVYU_PACKED_422 = 9, // 9, YUV422P YVYU 8bit
    MXPI_PIXEL_FORMAT_VYUY_PACKED_422 = 10, // 10, YUV422P VYUY 8bit
    MXPI_PIXEL_FORMAT_YUV_PACKED_444 = 11, // 11, YUV444P 8bit

Plugin Base Class (Factory)

mxpi_imagecrop

Input/Output

Input: buffer (data type: MxpiBuffer) and metadata (data type: MxpiObjectList)

Output: buffer (data type: MxpiBuffer) and metadata (data type: MxpiVisionList)

Port Format (Caps)

Static input: {"metadata/object"}; dynamic input: {"image/yuv","image/rgb"}

Static output: {"image/yuv","image/rgb"}

Property

For details, see Table 1.

Table 1 mxpi_imagecrop plugin properties

Property Name

Description

Mandatory or Not

Modifiable or Not

deviceId

Ascend device ID, which is specified by the deviceId property in the stream_config field. You do not need to set the ID.

No

Yes

parentName

Index of the input data (generally the name of the upstream element). The function is the same as that of dataSource. You are advised to use dataSource because it will be deleted in later versions.

Do not use it.

Yes

dataSource

Index of the input data (generally the name of the upstream element). The default value is the key value of the output port of the upstream plugin.

Recommended

Yes

dataSourceImage

Image data source for cropping. Generally, the data source is the name of an upstream element.

No

Yes

leftExpandRatio

Expanding ratio of in the left direction. The default value is 0, and the value range is [0, 1].

No

Yes

rightExpandRatio

Expanding ratio of in the right direction. The default value is 0, and the value range is [0, 1].

No

Yes

upExpandRatio

Expanding ratio of in the up direction. The default value is 0, and the value range is [0, 1].

No

Yes

downExpandRatio

Expanding ratio of in the down direction. The default value is 0, and the value range is [0, 1].

No

Yes

resizeHeight

Height of the resized image in Resizer_Stretch and Resizer_KeepAspectRatio_Fit resizing modes. The default value is the height of the cropped image, that is, the height without resizing.

No

Yes

resizeWidth

Width of the resized image in Resizer_Stretch and Resizer_KeepAspectRatio_Fit resizing modes. The default value is the width of the cropped image, that is, the width without resizing.

No

Yes

maxDimension

Maximum length of the resized image in Fast R-CNN resizing mode

No

Yes

minDimension

Minimum length of the resized image in Fast R-CNN resizing mode

No

Yes

resizeType

Resizing mode

  • Resizer_Stretch: stretch mode, which is the default resizing mode.
  • Resizer_KeepAspectRatio_FastRCNN: corresponds to the Fast R-CNN resizing mode.
  • Resizer_KeepAspectRatio_Fit: resizes the image proportionally to maximize the area of the specified width and height.

No

Yes

RGBValue

Padding color value. Enter the R, G, and B values in sequence. By default, the padding color is not set, and the default background color of DVPP is used.

No

Yes

paddingType

Padding mode. The options are as follows:

  • Padding_No (default)
  • Padding_RightDown
  • Padding_Around

No

Yes

cvProcessor

Processing mode. For details about the differences, see Before You Start.
  • Ascend (default)
  • OpenCV

No

Yes

autoDetectFrame

By default, the cropped coordinate box is set by the output of the upstream plugin (generally the inference plugin or block-dividing plugin). If you want to customize the cropped coordinate box, disable this attribute. The value can be 0 or 1 (default). When the value is 0, the coordinate box needs to be provided. The coordinate box consists of two coordinates: (x0, y0) and (x1, y1).

No

Yes

cropPointx0

x0 coordinate of the cropped image. It is of the string type and the range is [1,8192]. Multiple object frames are supported.

No

Yes

cropPointx1

x1 coordinate of the cropped image. It is of the string type and the range is [1,8192]. Multiple object frames are supported.

No

Yes

cropPointy0

y0 coordinate of the cropped image. It is of the string type and the range is [1,8192]. Multiple object frames are supported.

No

Yes

cropPointy1

y1 coordinate of the cropped image. It is of the string type and the range is [1,8192]. Multiple object frames are supported.

No

Yes

cropHeight

Height of the cropped image. The value range is [1,8192]. If the plugin does not receive the specified valid cropping range, the default value 0 is used, and an error is reported. (It is deprecated. Do not use it.)

No

Yes

cropWidth

Width of the cropped image. The value range is [1,8192]. If the plugin does not receive the specified valid cropping range, the default value 0 is used, and an error is reported. (It is deprecated. Do not use it.)

No

Yes

handleMethod

Reserved attribute. Use cvProcessor.

Processing method:

  • Ascend (default)
  • OpenCV

No

Yes

cropType

Reserved attribute. Use autoDetectFrame.

Cropping mode. The default value is cropCoordinate, indicating that the image is cropped based on the coordinates.

No

Yes

Custom cutout example:

  1. When a single coordinate box is input, set (x0, y0) to (1,1) and (x1, y1) to (100,100).
     "mxpi_imagecrop0": {
                "props" : {
                    "autoDetectFrame" : "0",
                    "cropPointx0" : "1",
                    "cropPointy0" : "1",
                    "cropPointx1" : "100",
                    "cropPointy1" : "100"
                },
                "factory": "mxpi_imagecrop",
                "next": "xxxxxxxx"
            },
  2. When multiple coordinate boxes are input, set the coordinates of the first object frame to (1,1) (100,100) and that of the second object frame to (100,100) (200,200).
     "mxpi_imagecrop0": {
                "props" : {
                    "autoDetectFrame" : "0",
                    "cropPointx0" : "1, 100",
                    "cropPointy0" : "1, 100",
                    "cropPointx1" : "100, 200",
                    "cropPointy1" : "100, 200"
                },
                "factory": "mxpi_imagecrop",
                "next": "xxxxxxxx"
            },