Help Center> Huawei HiLens> SDK Reference> Pre-processing> Converting the Image Color Format
Updated on 2023-06-15 GMT+08:00

Converting the Image Color Format

This section describes how to convert the color format of an image. The native OpenCV does not provide the option of converting RGB/BGR to NV12/NV21.

API Calling

HiLensEC hilens::CvtColor(const cv::Mat & src, cv::Mat & dst, CvtCode code)

Parameter Description

Table 1 Parameters

Parameter

Description

src

Source image (BGR888 or RGB888).

dst

Target image

code

Color conversion code, which specifies the conversion type. The options are RGB2YUV_NV12, RGB2YUV_NV21, BGR2YUV_NV12, and BGR2YUV_NV21.

enum hilens::CvtCode

For details about the enumerated values, see Table 2.

Table 2 Color conversion code

Enumerated Value

Description

BGR2YUV_NV12

Convert BGR to YUV_NV12.

RGB2YUV_NV12

Convert RGB to YUV_NV12.

BGR2YUV_NV21

Convert BGR to YUV_NV21.

RGB2YUV_NV21

Convert RGB to YUV_NV21.

Return Value

If the return value is 0, the operation is successful. Otherwise, the operation fails. Refer to Error Codes for details about the failure response parameters.