使用色域转换接口前,用户需准备好被转换的图片对象,并转换到Tensor对象中。
关键步骤说明如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
//初始化 MxBase::MxInit(); { // 读取图片 std::string imgPath = "./test.jpg"; cv::Mat imgData = cv::imread(imgPath); size_t originalWidth = image.cols; size_t originalHeight = image.rows; // 构造输入Tensor const std::vector<uint32_t> shape = {originalHeight, originalWidth, 3}; MxBase::Tensor inputTensor((void*)imgData.data, shape, TensorDType::UINT8, -1); inputTensor.ToDevice(0); // 定义转换模式 auto mode = MxBase::CvtColorMode::COLOR_BGR2RGB; // 定义输出Tensor MxBase::Tensor outputTensor; // 执行色域转换 APP_ERROR ret = MxBase::CvtColor(inputTensor, outputTensor, mode, true); if (ret != APP_ERR_OK) { std::cout << "CvtColor failed." << std::endl; } } //去初始化 MxBase::MxDeInit(); |