Resizes the input image and outputs it to the tensor object.
For details about the API, see Resize.
Before calling the resizing APIs, prepare the image to be resized and convert it to a tensor object.
Key steps are demonstrated as follows:
Construct the input Size and Tensor as well as the output Tensor based on service requirements.
No stream is created. The input image and other parameters are passed to the Resize method to obtain the image resizing result.
The following is a code example of key steps of functions and features, which is for reference only and cannot be directly copied for compilation or running.
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 29 30 31 32 33 34 |
// Initialization MxBase::MxInit(); { // Image reading std::string imgPath = "./test.jpg"; cv::Mat imgData = cv::imread(imgPath, cv::IMREAD_UNCHANGED); std::vector<uint32_t> shape{600, 600, 3}; // Construct an input tensor. MxBase::Tensor input(imgData.data, shape, MxBase::TensorDType::UINT8, -1); input.ToDvpp(0); // Set the resizing width and height. MxBase::Size resize(289, 289); // Construct an output tensor. std::vector<uint32_t> dstShape = {289, 304, 3}; MxBase::Tensor dst(dstShape, MxBase::TensorDType::UINT8, -1); dst.Malloc(); dst.ToDvpp(0); // Whether to reserve invalid boundaries of the input tensor for the output tensor bool keepMargin = true; // Perform resizing. APP_ERROR ret = MxBase::Resize(input, dst, resize, MxBase::Interpolation::BILINEAR_SIMILAR_OPENCV, keepMargin); if (ret != APP_ERR_OK) { std::cout << "Resize failed." << std::endl; } } // Deinitialization MxBase::MxDeInit(); |