Media Data Processing V1 (Cropping and Pasting)

Sample Obtaining

Refer to smallResolution_cropandpaste to obtain the sample.

Description

This sample implements image cropping and pasting in the following three scenarios:

1. The crop ROI is less than 10 x 6.

2. The resizing ratio of the paste ROI to the crop ROI is within the range of [1/32, 16].

3. The input resolution meets the VPC requirements on resizing and pasting, as described in Restrictions.

Principles

The following table lists the key functions involved in this sample.

Initialization

  • aclInit: initializes AscendCL.
  • aclFinalize: deinitializes AscendCL.

Device Management

  • aclrtSetDevice: sets the compute device.
  • aclrtGetRunMode: obtains the run mode of the software stack. The internal processing varies depending on the run mode.
  • aclrtResetDevice: resets the compute device and cleans up all resources associated with the device.

Stream Management

  • aclrtCreateStream: creates a stream.
  • aclrtDestroyStream: destroys a stream.
  • aclrtSynchronizeStream: waits for stream tasks to complete.

Memory Management

  • aclrtMallocHost: allocates host memory.
  • aclrtFreeHost: frees host memory.
  • aclrtMalloc: allocates device memory.
  • aclrtFree: frees device memory.

In media data processing, if you need to allocate device memory to store the input or output data, call acldvppMalloc to allocate memory and call acldvppFree to free up memory.

Data Transfer

aclrtMemcpy:

  • Transfers decode source data from the host to the device.
  • Transfers the inference result from the device to the host.

Data transfer is not required if your app runs in the board environment.

Media Data Processing

Cropping and pasting:

acldvppVpcCropAndPasteAsync: crops a selected ROI from the input image according to cropArea and loads the cropped image to the output buffer.

Directory Structure

The sample directory is organized as follows:

├── data
│   ├── dvpp_vpc_1920x1080_nv12.yuv            //Test image. Obtain the test image according to the guide and save it to the data directory.

├── inc
│   ├── dvpp_process.h               //Header file that declares functions related to media data processing
│   ├── sample_process.h               //Header file that declares functions related to model processing
│   ├── utils.h                       //Header file that declares common functions (such as the file reading function)

├── src
│   ├── acl.json              //Configuration file for system initialization
│   ├── CMakeLists.txt         //Build script
│   ├── dvpp_process.cpp       //Implementation file of functions related to media data processing
│   ├── main.cpp               //Implementation file of the main function, for image cropping and pasting
│   ├── sample_process.cpp     //Implementation file of functions related to resource initialization and destruction
│   ├── utils.cpp              //Implementation file of common functions (such as the file reading function)

├── CMakeLists.txt    //Build script that calls the CMakeLists file in the src directory

App Build and Run (Ascend EP Mode)

Refer to smallResolution_cropandpaste to obtain the sample. View the README file in the sample.

App Build and Run (Ascend RC Mode)

Refer to smallResolution_cropandpaste to obtain the sample. View the README file in the sample.