cvt_color

Function Usage

Converts the image color gamut type of a tensor to the specified type. Conversions between the following types are supported:

If keepMargin is set to true, the output width is automatically aligned with 16. The default value is false, indicating that the invalid boundary in the tensor is not reserved. Table 1 lists the CSC types supported by each product. The meanings of the symbols are as follows:

  • √: supported
  • x: not supported
    Table 1 CSC types

    CSC Type

    Atlas 200I/500 A2 inference product

    Atlas inference product

    Atlas 800I A2 inference product

    YUVSP420 (nv12) to YUV400 (GRAY)

    YVUSP420 (nv21) to YUV400 (GRAY)

    x

    YUVSP420 (nv12) to RGB

    x

    YUVSP420 (nv12) to BGR

    x

    YVUSP420 (nv21) to RGB

    x

    YVUSP420 (nv21) to BGR

    x

    RGB to YUVSP420 (nv12)

    x

    RGB to YVUSP420 (nv21)

    x

    BGR to YUVSP420 (nv12)

    x

    BGR to YVUSP420 (nv21)

    x

    RGB to YUV400 (GRAY)

    x

    BGR to YUV400 (GRAY)

    x

    BGR to RGB

    x

    RGB to BGR

    x

    RGB to RGBA

    x

    RGBA to YUV400 (GRAY)

    x

    RGBA to RGB

    x

    GRAY to RGB

    x

    x

    RGB to mRGBA

    x

    x

    The conversion from RGBA to mRGBA requires CANN 8.0.RC1 or later.

Prototype

cvt_color(inputTensor: Tensor, cvtColorMode: cvt_color_mode, keepMargin = False)

Parameters

Parameter

Input/Output

Description

inputTensor

Input

Tensor of type dtype.uint8. The value cannot be empty. Memory needs to be allocated on the device side.

  • Tensor in the shape of {height, width, number of channels}. The number of channels must match input format. RGBA-to-mRGBA conversion supports only 4 channels.
    NOTE:

    If the CSC type of inputTensor is base.yuv_400 or base.nv12, set the height 1.5 times the displayed image height when configuring the input tensor shape. The height of the tensor must be a multiple of 3, the width must be a multiple of 16, and the channel must be 1.

  • The input tensor width range is [10, 4096], and the height range is [6, 4096]. If the format YUV400, YUVSP420, YVUSP420, or GRAY is contained, the width range is [18, 4096].
  • For a grayscale image, tensors in the {height x width} shape are supported.

cvtColorMode

Input

Enumeration class, referring to the original type and target type of CSC.

If the cvtColorMode CSC type is base.color_bgr2yuvsp420, base.color_rgb2yuvsp420, base.color_rgb2yvusp420, or base.color_bgr2yvusp420:

  • It is recommended that the width and height of the input RGB tensor be even numbers. Otherwise, abnormal data may exist on the borders of the output image.
  • The height of the output tensor is 1.5 times the height of the input tensor. For example, if the input height is 4096, the output height is 6144, which exceeds the restrictions of some DVPP APIs. Check whether the subsequent service requirements are met.

keepMargin

Input

Whether to retain the invalid boundary in the tensor in the output tensor. The default value is False, indicating that the invalid boundary is not retained. If keepMargin is set to true, the output width is automatically aligned with 16 and the invalid region is reserved.

This parameter is invalid when cvtColorMode is set to base.color_gray2rgb or base.color_rgba2mrgba.

Response Parameters

Converted tensor data