CSC
Function Description
Performs CSC on the input image and outputs the image to the Tensor object.
For details about the API, see CvtColor.
API Calling Process
Before calling the CSC APIs, prepare the image object to be converted and convert it to the Tensor object.
Figure 1 Process of calling APIs in tensor mode (CSC)
Key steps are demonstrated as follows:
- Perform global initialization by calling MxInit().
- Construct an output tensor object.
Select the CvtColorMode format based on service requirements to construct the corresponding output tensor.
- Select the synchronous or asynchronous CSC mode based on the service requirements.
- Synchronous execution
No stream is created. The input image and other parameters ara passed to the CvtColor method to obtain the image CSC result.
- Asynchronous execution
- Create a stream. For details, see Asynchronous Invocation.
- Transfer the input image, created stream, and other parameters to the CvtColor method to obtain the image CSC result.
- Synchronous execution
- Deinitialize the initialized global resources by calling MxDeInit().
Sample Code
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(); |
Parent topic: Image Processing Using Tensors (Tensor)