Image Cropping and Resizing
The system supports image cropping and resizing. The major steps are as follows:
- Call acl.media.dvpp_create_channel to create a channel for image data processing.
Before creating a channel, call acl.media.dvpp_create_channel_desc to create the channel description.
- Call acl.media.dvpp_create_roi_config and acl.media.dvpp_create_resize_config to create cropArea position configuration and resizing configuration, respectively.
- Before cropping and resizing, call acl.media.dvpp_malloc to allocate memory on the device for storing the input or output data.
- Perform cropping and resizing.
- About cropping:
- Call the asynchronous API acl.media.dvpp_vpc_resize_async to crop the image according to cropArea and loads the cropped image to the output memory for output.
Resize the cropped image again if the size is different from that of the canvas.
- The asynchronous API acl.media.dvpp_vpc_crop_and_paste_async is provided for cropping the source image based on the specified area, and pasting the cropped image to the specified area in the target image as the output image.
- Resize the image again if the size of the cropArea is inconsistent with that of the pasteArea.
- To paste the pasteArea on the canvas loaded to the output buffer, modify the code logic as follows: allocate the output buffer and then load a canvas to the allocated buffer.
- Call the asynchronous API acl.media.dvpp_vpc_resize_async to crop the image according to cropArea and loads the cropped image to the output memory for output.
- About resizing:
- Call the asynchronous API acl.media.dvpp_vpc_resize_async to resize the input image to the size of the output image.
- Calculate the buffer for storing the resized image based on the YUV420SP format as follows: widthStride x heightStride x 3/2.
- For asynchronous APIs, call acl.rt.synchronize_stream to block the application until all tasks in the specified stream are complete.
- About cropping:
- Call acl.media.dvpp_free to free the input and output memory.
- Call acl.media.dvpp_destroy_roi_config and acl.media.dvpp_destroy_resize_config to destroy cropArea position configuration and resizing configuration, respectively.
- Call acl.media.dvpp_destroy_channel to destroy the image data processing channel.
Call acl.media.dvpp_destroy_channel_desc to destroy the channel description after the channel is destroyed.