Crops and resizes the input image, and outputs the image to the Image object.
For details about the API, see CropResize.
Before calling the image cropping and resizing APIs, prepare the image object to be cropped and resized.
Key steps are demonstrated as follows:
Construct an ImageProcessor object and initialize the channel by calling InitVpcChannel(). If you skip this API, ImageProcessor automatically initializes the channel before cropping and resizing.
Decode the image based on services to generate an Image object that can be cropped and resized. Subsequently, the image can be processed by using the image processing APIs to generate a final Image object to be cropped and resized.
Based on the service requirements, select different modes to construct the corresponding input Rect, Size, and output Image: single-input multi-cropping single-resizing, single-input multi-cropping multi-resizing, or multi-input multi-cropping multi-resizing
No stream is created. The input image and other parameters are passed to the API to obtain the image cropping and 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 35 36 37 38 |
// 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 cropping and resizing. // Image class after cropping and resizing. std::vector<Image> cropResizedImageVec(1); // Image cropping size Rect rect(0, 0, 240, 240); std::vector<Rect> cropConfigVec = {rect}; // Resizing size Size size(416, 416); // Image cropping and resizing ret = imageProcessor.CropResize(decodedImage, cropConfigVec, size, cropResizedImageVec); if (ret != APP_ERR_OK) { std::cout << "CropResize failed." << std::endl; } } // Deinitialization MxDeInit(); |