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 bounding box.
  • 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 cropping range:
    • For Ascend: The height range is [6, 4096] and the width range is [10, 4096].
    • For OpenCV: The height range [1, 8192] and the width range is [1, 8192].
  • Formats that support both 4K and 8K images:
    1
    2
    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:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    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), metadata (data type: MxpiObjectList)
  • Output: buffer (data type: MxpiBuffer), 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 this property 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: indicates the stretching 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 image area within the specified width and height.

No

Yes

RGBValue

Value for color padding. Enter the R, G, and B values in sequence. By default, the value is empty and color padding is not performed. The default background color of DVPP is used.

No

Yes

paddingType

Padding mode:

  • Padding_No (default)
  • Padding_RightDown
  • Padding_Around

No

Yes

cvProcessor

Processing method:
  • ascend (default): Ascend DVPP interfaces are called for processing.
  • opencv: OpenCV interfaces are called for processing.

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 for cropping. It is of the string type and the range is [1, 8192]. Multiple bounding boxes are supported.

No

Yes

cropPointx1

x1 coordinate for cropping. It is of the string type and the range is [1, 8192]. Multiple bounding boxes are supported.

No

Yes

cropPointy0

y0 coordinate for cropping. It is of the string type and the range is [1, 8192]. Multiple bounding boxes are supported.

No

Yes

cropPointy1

y1 coordinate for cropping. It is of the string type and the range is [1, 8192]. Multiple bounding boxes are supported.

No

Yes

handleMethod

Reserved property. Use cvProcessor.

Processing method:

  • ascend (default)
  • opencv

No

Yes

cropType

Reserved property. Use autoDetectFrame.

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

No

Yes

Example for customizing image cropping:

  1. For a single coordinate box is input, set (x0, y0) to (1, 1) and (x1, y1) to (100, 100).
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
     "mxpi_imagecrop0": {
                "props" : {
                    "autoDetectFrame" : "0",
                    "cropPointx0" : "1",
                    "cropPointy0" : "1",
                    "cropPointx1" : "100",
                    "cropPointy1" : "100"
                },
                "factory": "mxpi_imagecrop",
                "next": "xxxxxxxx"
            },
    
  2. For more than one coordinate box, set the coordinates of the first bounding box to (1, 1) (100, 100) and that of the second bounding box to (100, 100) (200, 200).
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
     "mxpi_imagecrop0": {
                "props" : {
                    "autoDetectFrame" : "0",
                    "cropPointx0" : "1, 100",
                    "cropPointy0" : "1, 100",
                    "cropPointx1" : "100, 200",
                    "cropPointy1" : "100, 200"
                },
                "factory": "mxpi_imagecrop",
                "next": "xxxxxxxx"
            },