Performs CSC on the input image and outputs the image to the Tensor object.
For details about the API, see CvtColor.
Before calling the CSC APIs, prepare the image object to be converted and convert it to the Tensor object.
Key steps are demonstrated as follows:
Select the CvtColorMode format based on service requirements to construct the corresponding output tensor.
No stream is created. The input image and other parameters ara passed to the CvtColor method to obtain the image CSC result.
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 |
// Initialization MxBase::MxInit(); { // Image reading std::string imgPath = "./test.jpg"; cv::Mat imgData = cv::imread(imgPath); size_t originalWidth = image.cols; size_t originalHeight = image.rows; // Construct an input tensor. const std::vector<uint32_t> shape = {originalHeight, originalWidth, 3}; MxBase::Tensor inputTensor((void*)imgData.data, shape, TensorDType::UINT8, -1); inputTensor.ToDevice(0); // Define the conversion mode. auto mode = MxBase::CvtColorMode::COLOR_BGR2RGB; // Define the output tensor. MxBase::Tensor outputTensor; // Perform CSC. APP_ERROR ret = MxBase::CvtColor(inputTensor, outputTensor, mode, true); if (ret != APP_ERR_OK) { std::cout << "CvtColor failed." << std::endl; } } // Deinitialization MxBase::MxDeInit(); |