Resizing
Function Description
Resizes the input image and outputs it to the Image object.
For details about the API, see Resize.
API Calling Process
Before calling the resizing API, prepare the image object to be resized.
Key steps are demonstrated as follows:
- Perform global initialization by calling MxInit().
- Initialize ImageProcessor.
Construct an ImageProcessor object and initialize the channel by calling InitVpcChannel(). If you skip this API, ImageProcessor automatically initializes the channel before resizing.
- Call the image decoding API to decode the input image.
Decode the image based on services to generate an Image object that can be resized. Subsequently, the image can be processed by using the image processing APIs to generate a final Image object to be resized.
- Construct the resizing parameters and the output Image.
Construct the corresponding input Size and output Image based on service requirements.
- Select the synchronous or asynchronous resizing mode based on the service requirements.
- Synchronous execution
No stream is created. The input image and other parameters are passed to the Resize() API to obtain the image resizing result.
- Asynchronous execution
- Create a stream. For details, see Asynchronous Invocation.
- Transfer the input image, created stream, and other parameters to the Resize() API to obtain the image resizing result.
- Synchronous execution
- Deinitialize the initialized global resources by calling MxDeInit().
Sample Code
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 MxInit(); { // Construct the image processing class. ImageProcessor imageProcessor(deviceId); // Decode the image for Image generation. // Decoded image class Image decodedImage; // Perform decoding based on the image path. APP_ERROR ret = imageProcessor.Decode(imagePath, decodedImage); if (ret != APP_ERR_OK) { std::cout << "Decode failed." << std::endl; } // (Optional) Initialize the image processing channel. imageProcessor.InitVpcChannel(); // Perform resizing. // Image class after resizing Image resizedImage; // Resizing size Size size(416, 416); // Resizing ret = imageProcessor.Resize(decodedImage, size, resizedImage, Interpolation::HUAWEI_HIGH_ORDER_FILTER); if (ret != APP_ERR_OK) { std::cout << "Resize failed." << std::endl; } } // Deinitialization MxDeInit(); |