Image Decoding
Function Description
Decodes the input image data and converts the local image or image data into the Image class for subsequent preprocessing and inference services. Currently, .jpeg and .png images are supported.
For details about the API, see Decode.
API Calling Process
Prepare a local image file or image data to be decoded, initialize the ImageProcessor class, construct an output Image object, and call the Decode API of the ImageProcessor class to decode the result.
The process of calling image decoding APIs is as follows:

Key steps are demonstrated as follows:
- Perform global initialization by calling MxInit().
- Construct and initialize ImageProcessor.
Construct an ImageProcessor object. After the object is constructed, call InitJpegDecodeChannel() to initialize the channel. If you skip this API, ImageProcessor automatically initializes the channel before decoding.
- Construct the output Image object.
Use the Image() constructor to store the image object to be decoded and output.
- Prepare data.
Load images from files or load image data from the memory based on service requirements.
- Decode the image by calling Decode().
Call the corresponding Decode API based on different input data types.
- 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 | // Initialization MxInit(); { // Construct the image processing class. ImageProcessor imageProcessor(deviceId); // (Optional) Initialize the decoding channel. imageProcessor.InitJpegDecodeChannel(); // Image decoding // Decoded image class Image decodedImage; // Perform decoding based on the image path. std::string imagePath = "image path"; APP_ERROR ret = imageProcessor.Decode(imagePath, decodedImage, ImageFormat::YUV_SP_420); if (ret != APP_ERR_OK) { std::cout << "Decode failed." << std::endl; } } // Deinitialization MxDeInit(); |