Media Data Processing
Class Description
The Image data class serves as the data structure for the input and output of image processing, including image encoding and decoding. By default, you construct input data on the host side, and the ImageProcessor class manages data transfer between devices. Therefore, you do not need to perform memory data transfer operations. The ImageProcessor class performs image validation.
The Image class applies for device-side resources, which conflicts with the scope of MxDeInit. Therefore, its scope cannot be greater than or equal to the scope of MxDeInit.
ConvertToTensor
Converts the Image class on the DVPP side to the Tensor class on the device side, or the Image on the host side to the Tensor on the host side. The data type of the converted Tensor class object is uint8.
- If the conversion fails, an empty Tensor instance is returned.
- If the Tensor class fails to be constructed due to exceptional scenarios such as insufficient memory or failure to identify the chip, an exception is thrown.
- When the
withStrideparameter istrue, the Tensor object retains the padding information of the Image object. To reduce memory copies and improve running efficiency, the returned Tensor object shares data memory with the Image object. In this scenario, the data memory of the Image object and that of the Tensor object affect each other. For example, after the Image object is released, the data in the corresponding Tensor object becomes invalid memory data. - When ConvertToTensor is called without parameters, the returned Tensor object retains the padding information of the Image object and has a batch dimension, that is, NHWC, where the batch dimension N = 1.
Tensor Image::ConvertToTensor(bool withStride, bool formatNHWC);
Tensor Image::ConvertToTensor();
| Parameter | Input/Output | Description |
|---|---|---|
| withStride | Input | bool type, specifying whether to retain padding information. If set to true, the padding information is retained and the data memory is shared with the Image object. If set to false, the padding information is not retained and the data memory is not shared with the Image object. |
| formatNHWC | Input | bool type, specifying whether the converted Tensor has a batch dimension. If set to true, the returned Tensor has a batch dimension. If set to false, the returned Tensor does not have a batch dimension. |
| Data Structure | Description |
|---|---|
| Tensor | Tensor class. For details, see Tensor. |
DumpBuffer
Writes the image memory data to a binary file. You need to specify the file name and the specific path.
APP_ERROR Image::DumpBuffer(const std::string& filePath, bool forceOverwrite = false);
| Parameter | Input/Output | Description |
|---|---|---|
| filePath | Input | Path of the data file to be written (including the file name). Symbolic links are not supported. |
| forceOverwrite | Input | Whether to forcibly overwrite an existing file when saving. The default value is false, indicating that the file is not overwritten. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
GetData
Obtains the memory data pointer of the Image object.
std::shared_ptr<uint8_t> Image::GetData() const;
| Data Structure | Description |
|---|---|
| std::shared_ptr<uint8_t> | Smart pointer to the memory data. |
GetDataSize
Obtains the memory data size of the Image object.
uint32_t Image::GetDataSize() const;
| Data Structure | Description |
|---|---|
| uint32_t | Memory data size. |
GetDeviceId
Obtains the deviceId of the Image object.
int32_t Image::GetDeviceId() const;
| Data Structure | Description |
|---|---|
| int32_t | Device ID of the Image. |
GetFormat
Obtains the image format of the Image object.
ImageFormat Image::GetFormat() const;
| Data Structure | Description |
|---|---|
| ImageFormat | Image format. For details, see ImageFormat. |
GetOriginalData
Used to obtain the valid image memory data.
The following image formats are currently supported.
YUV_400 = 0,
RGB_888 = 12,
BGR_888 = 13,
ARGB_8888 = 14,
ABGR_8888 = 15,
RGBA_8888 = 16,
BGRA_8888 = 17,
std::shared_ptr<uint8_t> Image::GetOriginalData() const;
| Data Structure | Description |
|---|---|
| std::shared_ptr<uint8_t> | Memory address returned (smart pointer). |
GetOriginalSize
Obtains the original image width and height of the Image object.
Size Image::GetOriginalSize() const;
| Data Structure | Description |
|---|---|
| Size | Original image width and height. |
GetSize
Obtains the aligned image width and height of the Image object, that is, the width and height of the actual memory size.
Size Image::GetSize() const;
| Data Structure | Description |
|---|---|
| Size | Aligned image width and height, that is, the width and height of the actual memory size. |
Image
Constructor of the Image class. You can create an Image object in the following ways. If the construction fails due to insufficient memory or failure to identify the chip, an exception is thrown.
- Creates an empty Image object.
- Creates an image with customized memory data. The default image format is ImageFormat::YUV_SP_420, and the default device ID is the host side (
deviceId= -1). - Creates an image with aligned width and height, valid width and height, and customized memory data. The following conditions must be met.
deviceIdmust be a valid value in the range [-1, number of recognized devices - 1]. Otherwise, the interface call fails."format" supports the following image formats.
YUV_400 = 0, RGB_888 = 12, BGR_888 = 13, ARGB_8888 = 14, ABGR_8888 = 15, RGBA_8888 = 16, BGRA_8888 = 17,dataSizemust be consistent with the valid width and height or the aligned width and height. For the calculation formula, seedataSize= width × height × number of channels.
After you apply for host memory, if you need to construct an Image object on the device side, perform the following operations.
- Construct an Image object on the host side with
deviceIdset to "-1" (consistent with theimageDatamemory location, set to the host side). - Use the ToDevice(
deviceId) method to migrate the memory of the constructed Image object to the device side.
Image::Image();Image::Image(const std::shared_ptr<uint8_t> imageData, const uint32_t dataSize, const int32_t deviceId = -1, const Size imageSize = DEFAULT_IMAGE_SIZE, const ImageFormat format = ImageFormat::YUV_SP_420);Image::Image(const std::shared_ptr<uint8_t> imageData, const uint32_t dataSize, const int32_t deviceId, const std::pair<Size, Size> imageSizeInfo, const ImageFormat format);
| Parameter | Input/Output | Description |
|---|---|---|
| imageData | Input | Input memory constructed by you. You are responsible for applying for and releasing this memory. It cannot be a null pointer (nullptr). |
| dataSize | Input | Size of the input memory. It must be consistent with the actual memory data size. |
| imageSize | Input | Image width and height. The default value is (0, 0). If you apply for device-side memory, set the image width and height corresponding to the actual memory data. |
| imageSizeInfo | Input | Combination of the image valid width and height and aligned width and height. The valid width and height must not exceed the aligned width and height. For the input method, see the following.std::pair<Size, Size> imageSizeInfo(valid width and height, aligned width and height)The valid width and height range is [6, 8192]. The aligned width and height range is [16, 8192], where the width must be a multiple of 16 and the height must be a multiple of 2. |
| format | Input | Image format. |
| deviceId | Input | Device ID of the input memory. If you apply for device-side memory, enter the corresponding deviceId. Value range: [-1, number of recognized devices - 1]. This value must be on the same side as imageData (host side: -1, device side: a specific device ID). Otherwise, subsequent services may face risks and exceptions. |
~Image
Default destructor of the Image class.
Image::~Image();operator =
The Image class overloads the assignment operator, which performs a deep copy of member variables, a shallow copy of memory data, and increments the reference count by one.
Image &operator = (const Image &img);
| Parameter | Input/Output | Description |
|---|---|---|
| img | Input | Input Image class. |
Serialize
Serializes the image memory data and metadata, and saves them to a file.
APP_ERROR Image::Serialize(const std::string& filePath, bool forceOverwrite = false);
| Parameter | Input/Output | Description |
|---|---|---|
| filePath | Input | Path for saving the serialized data file (including the file name). Symbolic links are not supported. |
| forceOverwrite | Input | Whether to forcibly overwrite an existing file when saving. The default value is false, indicating that the file is not overwritten. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
SetImageAlignedSize
Sets the aligned image width and height.
Set the value based on the actual input image data of Image. The image data cannot be empty.
The following image formats are currently supported.
YUV_400 = 0, RGB_888 = 12, BGR_888 = 13, ARGB_8888 = 14, ABGR_8888 = 15, RGBA_8888 = 16, BGRA_8888 = 17,
APP_ERROR Image::SetImageAlignedSize(const Size whSize);
| Parameter | Input/Output | Description |
|---|---|---|
| whSize | Input | Aligned image width and height, in pixels. The aligned width and height range is [16, 8192] and must be greater than or equal to the valid width and height. The width must be a multiple of 16, and the height must be a multiple of 2. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
SetImageOriginalSize
Sets the valid image data width and height.
Set the value based on the actual input image data of Image. The image data cannot be empty.
APP_ERROR Image::SetImageOriginalSize(const Size whSize);
| Parameter | Input/Output | Description |
|---|---|---|
| whSize | Input | Valid width and height, in pixels. The valid width and height range is [6, 8192] and must not exceed the aligned width and height. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
TensorToImage
Converts the Tensor class on the host side to the Image class on the host side, or the Tensor class on the device side to the Image class on the DVPP side.
During conversion, the width of the Image is aligned up to a multiple of 16, and the height is aligned up to a multiple of 2. The converted Image class object has a padding area.
For the converted Image class, call the member function GetSize to obtain the Size class object to view the padded width and height, and call the member function GetOriginalSize to obtain the Size class object to view the original image width and height.
For example:
- When the width and height of the image corresponding to the Tensor class object are 500 and 499, the converted Image class object has a width and height of 500 and 499 obtained through GetOriginalSize after padding, and a width and height of 512 and 500 obtained through GetSize.
- When the width and height of the image corresponding to the Tensor class object are 512 and 500, the converted Image class object does not need padding. That is, the width and height of the converted Image class object remain 512 and 500.
static APP_ERROR Image::`TensorToImage`(const Tensor& inputTensor, Image& Image, const ImageFormat& imageFormat);
| Parameter | Input/Output | Description |
|---|---|---|
| inputTensor | Input | Tensor class, the input tensor. The input must meet the following requirements. |
| Image | Output | Image class, the output image. Its memory is allocated on the DVPP side. |
| imageFormat | Input | ImageFormat class, specifying the image format, which must match the image format corresponding to the inputTensor data. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
ToDevice
Transfers the image memory data stored in the Image class to the device side.
APP_ERROR Image::ToDevice(const int32_t devId);
| Parameter | Input/Output | Description |
|---|---|---|
| devId | Input | Device ID to which the data is transferred. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
ToHost
Transfers the image memory data stored in the Image class to the host side.
APP_ERROR Image::ToHost();
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Unserialize
Loads the data file saved to the drive by Serialize into the memory. You need to specify the file name and the specific path.
APP_ERROR Image::Unserialize(const std::string& filePath);
| Parameter | Input/Output | Description |
|---|---|---|
| filePath | Input | Path of the data file saved to the drive. The supported input file size range is (0, 4GB]. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Class Description
The ImageProcessor class is an image processing class that mainly provides interfaces such as image encoding and decoding, scaling, and cropping.
ImageProcessor objects do not support concurrent use in multiple threads. If multiple threads need to use the same ImageProcessor object, you must ensure locking and mutual exclusion by yourself.
The ImageProcessor class involves applying for device-side resources, which conflicts with the scope of MxDeInit. Therefore, its scope cannot be greater than or equal to the scope of MxDeInit.
About the Real Image Width and Height and the Aligned Image Width and Height
As shown in Figure 1, due to hardware limitations, the ImageProcessor has some limitations during use. To speed up reading and writing, the image length and width need to be aligned to a specified size. This does not affect the valid area. The invalid data is filled rightward and downward to align to the specified size.
When operations such as scaling are performed on an image, the ImageProcessor processes the image based on its original width and height.
Figure 1 Aligned width and height and real width and height

ConvertFormat
Color space conversion interface of the ImageProcessor class. The Image memory applied for by using this interface does not need to be managed by you. It is released internally. Currently, this interface can be called only in the
For the related usage process, see Color Space Conversion.
APP_ERROR ImageProcessor::`ConvertFormat`(const Image& inputImage, const ImageFormat outputFormat, Image& outputImage);
| Parameter | Input/Output | Description |
|---|---|---|
| inputImage | Input | Image class before conversion. The Image class obtained from the Decode interface and other VPC interfaces can be directly used as input. |
| outputFormat | Input | Target format of the color space conversion, supporting YUV_SP_420, YVU_SP_420, RGB_888, and BGR_888. |
| outputImage | Output | Image output after conversion. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Crop
Image cropping interface of the ImageProcessor class.
For the related usage process, see Cropping.
For the image formats supported by the input and output Image classes, see the following.
Atlas 200I/500 A2 inference products support YUV_SP_420 and YVU_SP_420 (nv12 and nv21).Atlas inference products andAtlas 800I A2 inference products support YUV_SP_420, YVU_SP_420, RGB_888, and BGR_888 (nv12, nv21, rgb, and bgr), where the resolution of the RGB (BGR) image format must not exceed (4096 × 4096).
The real image resolution range of
inputImage: 18 × 6 to 4096 × 4096, where the resolution of the YUV_SP_420 and YVU_SP_420 formats is 18 × 6 to 8192 × 8192.The cropping area must not exceed the input image area. It is recommended that the four values of the input cropping coordinate frame
cropRectbe even. Except for RGB and BGR, if odd values are included, the top-left coordinates are automatically rounded down to even numbers, and the bottom-right coordinates are automatically rounded up to even numbers.The maximum resolution of the cropping area is 4096 × 4096, and the minimum resolution is 18 × 6. For example, for
cropRect{1, 1, 1287, 1287}, the actual cropped width and height are ((1287 + 1) - (1 - 1)) = 1288, and the corresponding resolution is 1288 × 1288.In the output
outputImageVec, the width of each image is automatically aligned to 16, and the height is aligned to 2. The range is [32 × 6, 4096 × 4096].In the batch cropping scenario, the number of input images must not exceed 12, the length of the cropping configuration parameter
cropRectVecmust not exceed 256, and the number of output images must not exceed 256 and must satisfy number of output images = number of input images × length of the cropping configuration parametercropRectVec.
Prototype 1:
APP_ERROR ImageProcessor::Crop(const Image& inputImage, const Rect& cropRect, Image& outputImage, AscendStream& stream = AscendStream::DefaultStream());Prototype 2:
APP_ERROR ImageProcessor::Crop(const Image& inputImage, const std::vector<Rect>& cropRectVec, std::vector<Image>& outputImageVec, AscendStream& stream = AscendStream::DefaultStream());Prototype 3:
APP_ERROR ImageProcessor::Crop(const std::vector<Image>& inputImageVec, const std::vector<Rect>& cropRectVec, std::vector<Image>& outputImageVec, AscendStream& stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| inputImage | Input | Image class before cropping. The Image class obtained from the Decode interface and other VPC interfaces can be directly used as input. If the Image class is constructed by you, you need to set the image width and height. |
| inputImageVec | Input | List of Image classes before cropping (for the batch cropping scenario). |
| cropRect | Input | Cropping coordinate frame of the input image. |
| cropRectVec | Input | List of cropping coordinate frames of the input image (for the batch cropping scenario). |
| outputImage | Output | Image class after cropping. |
| outputImageVec | Output | List of Image classes after cropping (for the batch cropping scenario). |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
CropAndPaste
Image cropping and pasting interface of the ImageProcessor class.
For the related usage process, see Cropping and Pasting.
For the image formats supported by the input and output Image classes, see the following.
Atlas 200I/500 A2 inference products support YUV_SP_420 and YVU_SP_420 (nv12 and nv21).Atlas inference products andAtlas 800I A2 inference products support YUV_SP_420, YVU_SP_420, RGB_888, and BGR_888 (nv12, nv21, rgb, and bgr), where the resolution of the RGB (BGR) image format must not exceed (4096 × 4096).
Crop an image from
inputImage.- The real image width and height range of the input Image class: 18 × 6 to 4096 × 4096, where the width and height of the YUV_SP_420 and YVU_SP_420 formats can reach 8192 × 8192.
- The cropped width and height must not exceed the real image width and height of
inputImage. The minimum range of the cropping area is 10 × 6. - It is recommended that the four values of the input cropping parameters be even. Except for RGB and BGR, if odd values are included, the top-left coordinates are automatically rounded down to even numbers, and the bottom-right coordinates are automatically rounded up to even numbers. For example, for
cropRect{1, 1, 1287, 1287}, the actual cropped width and height are ((1287 + 1) - (1 - 1)) = 1288.
Scale the cropped image to the size of the specified pasting area.
Paste the scaled image to the specified pasting area of
pastedImage.The pasted width and height must not exceed the real image width and height of
pastedImage. The minimum range of the pasting area is 10 × 6, and the maximum range is 4096 × 4096.It is recommended that the four values of the input pasting parameters be even. Except for RGB and BGR, if odd values are included, the top-left coordinates are automatically rounded down to even numbers, and the bottom-right coordinates are automatically rounded up to even numbers.
The x of the top-left coordinates in the pasting parameters is automatically aligned to a multiple of 16. For example:
- For
pasteRect{17, 17, 1287, 1287}, the actual pasted width and height are ((1287 + 1) - (17 - 1)) = 1272, and the corresponding resolution is 1272 × 1272. - For
pasteRect{18, 18, 1287, 1287}, the actual pasted width is ((1287 + 1) - 32) = 1256, and the height is ((1287 + 1) - 18) = 1270. The corresponding resolution is 1256 × 1270.
- For
In the
Atlas 200I/500 A2 inference products environment, the pasted width and height must not exceed the [1/32, 16] multiple range of the cropped width and height.In the
Atlas inference products andAtlas 800I A2 inference products environments, the actual width of the pastingrectmust be aligned to "16". Otherwise, invalid data is used for padding. In theAtlas 200I/500 A2 inference products environment, it is recommended that thexvalue of the bottom-right corner of the pastingrectbe aligned to "16".
The width of the output
pastedImageis automatically aligned to 16, and the height is aligned to 2. Therefore, the width and height range is 32 × 6 to 4096 × 4096.
Figure 1 Cropping, scaling, and pasting

APP_ERROR ImageProcessor::CropAndPaste(const Image& inputImage, const std::pair<Rect, Rect>& cropPasteRect, Image& pastedImage, AscendStream& stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| inputImage | Input | Image class before cropping and scaling. The Image class obtained from the Decode interface and other VPC interfaces can be directly used as input. If the Image class is constructed by you, you need to set the image width and height and the aligned image width and height. |
| cropPasteRect | Input | Cropping, scaling, and pasting parameters of the input image. The first Rect corresponds to the cropping parameters, and the second Rect corresponds to the scaling and pasting parameters. |
| pastedImage | Input/Output | Image class after cropping. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
CropResize
Image cropping and scaling interface of the ImageProcessor class.
For the related usage process, see Cropping and Scaling.
For the image formats supported by the input and output Image classes, see the following.
Atlas 200I/500 A2 inference products support YUV_SP_420 and YVU_SP_420 (nv12 and nv21).Atlas inference products andAtlas 800I A2 inference products support YUV_SP_420, YVU_SP_420, RGB_888, and BGR_888 (nv12, nv21, rgb, and bgr), where the resolution of the RGB (BGR) image format must not exceed (4096 × 4096).
The real image width and height range of
inputImage: 18 × 6 to 4096 × 4096, where the width and height of the YUV_SP_420 and YVU_SP_420 formats can reach 8192 × 8192.The minimum cropping area is 10 × 6. The cropping area must not exceed the real image width and height of the input image. It is recommended that the four values of the input
cropRectbe even. Except for RGB and BGR, if odd values are included, the top-left coordinates are automatically rounded down to even numbers, and the bottom-right coordinates are automatically rounded up to even numbers.The maximum resolution of the output Image class is 4096 × 4096, and the minimum resolution is 18 × 6. For example, for
cropRect{1, 1, 1287, 1287}, the actual cropped width and height are ((1287 + 1) - (1 - 1)) = 1288, and the corresponding resolution is 1288 × 1288.The scaling range is 18 × 6 to 4096 × 4096 and must not exceed the [1/32, 16] multiple range of the cropping area.
In the output
outputImageVec, the width of each image is automatically aligned to 16, and the height is aligned to 2. The range is [32 × 6, 4096 × 4096].
Prototype 1:
APP_ERROR ImageProcessor::CropResize(const Image& inputImage, const std::vector<Rect>& cropRectVec, const Size& resize, std::vector<Image>& outputImageVec, AscendStream& stream = AscendStream::DefaultStream());Prototype 2:
APP_ERROR ImageProcessor::CropResize(const Image& inputImage, const std::vector<std::pair<Rect, Size>>& cropResizeVec, std::vector<Image>& outputImageVec, AscendStream& stream = AscendStream::DefaultStream());Prototype 3:
APP_ERROR ImageProcessor::CropResize(const std::vector<Image>& inputImageVec, const std::vector<std::pair<Rect, Size>>& cropResizeVec, std::vector<Image>& outputImageVec, AscendStream& stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| inputImage | Input | Image class before cropping and scaling. The Image class obtained from the Decode interface and other VPC interfaces can be directly used as input. If the Image class is constructed by you, you need to set the image width and height and the aligned image width and height. |
| inputImageVec | Input | List of Image classes before cropping and scaling (for the batch cropping and scaling scenario). The Image class obtained from the Decode interface and other VPC interfaces can be directly used as input. If the Image class is constructed by you, you need to set the image width and height and the aligned image width and height. |
| cropRectVec | Input | List of input cropping parameters. It must have the same number of elements as the output image list. |
| resize | Input | Uniform scaling width and height for input. |
| cropResizeVec | Input | List of cropping and scaling parameters of the input image. Rect is the cropping coordinate frame, and Size is the scaling width and height (for the batch cropping and scaling scenario). |
| outputImageVec | Output | List of Image classes after cropping (for the batch cropping and scaling scenario). |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Decode
Image decoding interface of the ImageProcessor class. The Image memory applied for by using this interface does not need to be managed by you. It is released internally. Only memory applied for on the host side can be used as the input of the decoding interface. The data type of the input image memory currently supports JPEG and PNG formats. For the related usage process, see Image Decoding.
JPG/JPEG format:
Maximum resolution of JPG/JPEG input images: 8192 × 8192, where the RGB_888 and BGR_888 formats support only up to 4096 × 4096.
Minimum resolution of JPG/JPEG input images: 32 × 32.
The data type of the decoded image and
outputImagecurrently supports only YUV_SP_420 and YVU_SP_420 image formats.Atlas inference products andAtlas 800I A2 inference products additionally support decoding in the RGB_888 and BGR_888 formats.Width of the output image.
Atlas 200I/500 A2 inference products align the width to 128 (that is, the width is a multiple of 128). Before the alignment, the interface first rounds the width down to a multiple of 2. For example, if the original image width is 1023, after decoding through theDecodeinterface, the value obtained through GetSize is 1024, and the value obtained through GetOriginalSize is 1022.Atlas inference products andAtlas 800I A2 inference products align the width to 64 (that is, the width is a multiple of 64). The RGB_888 and BGR_888 formats are aligned to 16. The decoding interface aligns automatically.
Height of the output image: aligned to 16 (that is, the height is a multiple of 16). The decoding interface aligns automatically.
For
Atlas 200I/500 A2 inference products , before alignment, the interface first rounds the height down to a multiple of 2. For example, if the original image height is 683, after decoding through theDecodeinterface, the value obtained through GetSize is 688, and the value obtained through GetOriginalSize is 682.Constraints on JPG/JPEG input image formats:
- Only Huffman encoding is supported. The subsample of the bitstream must be 444/422/420/400/440.
- Arithmetic coding is not supported.
- Progressive JPEG format is not supported.
- JPEG2000 format is not supported.
PNG format:
- Maximum resolution of PNG input images: 4096 × 4096.
- Minimum resolution of PNG input images: 32 × 32.
- Width of the output image: aligned to 128 (that is, the width is a multiple of 128). The decoding interface aligns automatically.
- Height of the output image: aligned to 16 (that is, the height is a multiple of 16). The decoding interface aligns automatically.
APP_ERROR ImageProcessor::Decode(const std::shared_ptr<uint8_t> `dataPtr`, const uint32_t dataSize, Image& outputImage, const ImageFormat `decodeFormat` = ImageFormat::YUV_SP_420);APP_ERROR ImageProcessor::Decode(const std::string inputPath, Image& outputImage, const ImageFormat `decodeFormat` = ImageFormat::YUV_SP_420);
| Parameter | Input/Output | Description |
|---|---|---|
| dataPtr | Input | Memory address of the input image data to be decoded. You need to manage the image data memory address before decoding. |
| dataSize | Input | Memory size of the input image data to be decoded. It must be consistent with the actual memory size of dataPtr.dataSize provided by you is insufficient to fully read the image file header information, an exception is returned.dataSize provided by you is greater than the file header information and smaller than the actual memory size, partial decoding is performed based on dataSize.dataSize provided by you is greater than the actual memory size, the image file end-of-file marker prevails. |
| decodeFormat | Input | Format of the decoded image.decodeFormat is YUV_SP_420, and you can set this parameter by yourself.decodeFormat takes effect only when BGR_888 is configured and the input image channels are in RGB or GRAY format. In other cases, this parameter is invalid and decoding is performed in the PNG source format. For example:
|
| inputPath | Input | Path of the input image to be decoded. |
| outputImage | Output | Image class after decoding. The image width and height and the aligned width and height are automatically included in outputImage. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Encode
Image encoding interface of the ImageProcessor class. The Image memory applied for by using this interface does not need to be managed by you. It is released internally. See Image Encoding.
For the related usage process, see the following.
Maximum resolution of input images: 8192 × 8192.
Minimum resolution of input images: 32 × 32.
The real width and height of the input image must be even numbers. If they are odd numbers, they are automatically rounded up to even numbers, and the encoded image is automatically padded by 1 pixel.
Width of the input image: for YUV420SP or RGB data, align the width to 16.
Height of the input image: the same value as the input image height, or the value of the input image height aligned up to 16 (minimum 32).
Input image format:
Atlas 200I/500 A2 inference products support YUV_SP_420 and YVU_SP_420 (nv12 and nv21).Atlas inference products andAtlas 800I A2 inference products support YUV_SP_420, YVU_SP_420, RGB_888, and BGR_888 (nv12, nv21, rgb, and bgr), where the resolution of the RGB (BGR) image format must not exceed (4096 × 4096).
Output image format: JPEG-compressed image file, for example, *.jpg.
APP_ERROR ImageProcessor::Encode(const Image& inputImage, const std::string savePath, const uint32_t encodeLevel = 100);APP_ERROR ImageProcessor::Encode(const Image& inputImage, std::shared_ptr<uint8_t>& outDataPtr, uint32_t& outDataSize, const uint32_t encodeLevel = 100);
| Parameter | Input/Output | Description |
|---|---|---|
| inputImage | Input | Image class before encoding. The Image class obtained from the Decode interface and other VPC interfaces can be directly used as input. If the Image class is constructed by you, you need to set the image width and height. |
| encodeLevel | Input | The default value is 100. For |
| savePath | Input | Path for saving the encoded image. The file name suffix is limited to jpg. |
| outDataPtr | Output | Memory data address of the encoded image. |
| outDataSize | Output | Memory data size of the encoded image. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
ImageProcessor
Constructor of the ImageProcessor class.
If the construction fails due to insufficient memory or failure to identify the chip, a std::runtime_error exception is thrown.
The memory data contained in the input Image class of image processing interfaces (except decoding) must be on the device side. The memory data of the Image object obtained by using the interfaces in the ImageProcessor class is already on the device side and does not need to be released by you.
ImageProcessor::ImageProcessor(const int32_t deviceId = 0);
| Parameter | Input/Output | Description |
|---|---|---|
| deviceId | Input | Chip on which the image processing class is deployed. The default value is chip 0. Value range: [0, the number of recognized chips - 1]. |
~ImageProcessor
Default destructor of the ImageProcessor class.
ImageProcessor::~ImageProcessor()InitJpegDecodeChannel
Initializes the JPEGD image channel for JPEG decoding.
Not supported on
APP_ERROR ImageProcessor::InitJpegDecodeChannel(const JpegDecodeChnConfig& config = JPEG_DECODE_CHN_CONFIG);
| Parameter | Input/Output | Description |
|---|---|---|
| config | Input | Channel configuration parameter. The default value is JPEG_DECODE_CHN_CONFIG. For the corresponding data structure, see the following (currently reserved). struct JpegDecodeChnConfig {}; |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
InitJpegEncodeChannel
Initializes the JPEGE image channel for JPEG encoding.
Not supported on
APP_ERROR ImageProcessor::InitJpegEncodeChannel(const JpegEncodeChnConfig& config = JPEG_ENCODE_CHN_CONFIG);
| Parameter | Input/Output | Description |
|---|---|---|
| config | Input | Channel configuration parameter. The value range is [32, 8192]. The default value is JPEG_ENCODE_CHN_CONFIG, that is, the maximum image width and height is 8192 × 8192. This parameter takes effect only on |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
InitPngDecodeChannel
Initializes the PNGD image channel for PNG image decoding.
Not supported on
APP_ERROR ImageProcessor::InitPngDecodeChannel(const PngDecodeChnConfig& config = PNG_DECODE_CHN_CONFIG);
| Parameter | Input/Output | Description |
|---|---|---|
| config | Input | Channel configuration parameter. The default value is PNG_DECODE_CHN_CONFIG. For the corresponding data structure, see the following (currently reserved). struct PngDecodeChnConfig {}; |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
InitVpcChannel
Initializes the VPC image channel for image processing functions (cropping, scaling, padding, cropping and scaling, cropping and pasting, and color space conversion).
This interface does not need to be explicitly called on
APP_ERROR ImageProcessor::InitVpcChannel(const VpcChnConfig& config = VPC_CHN_CONFIG);
| Parameter | Input/Output | Description |
|---|---|---|
| config | Input | Channel configuration parameter. The default value is VPC_CHN_CONFIG. For the corresponding data structure, see the following (currently reserved). struct VpcChnConfig {}; |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Padding
Image padding interface of the ImageProcessor class. The Image memory applied for by using this interface does not need to be managed by you. It is released internally.
For the related usage process, see Padding.
- The image formats supported by the input and output Image classes are YUV_SP_420, YVU_SP_420, RGB_888, and BGR_888 (nv12, nv21, rgb, and bgr), where the resolution of the RGB (BGR) image format must not exceed (4096 × 4096).
- The real image resolution range of
inputImage: 18 × 6 to 4096 × 4096. - Currently, this interface supports only the "BORDER_CONSTANT" padding mode. Other padding modes are reserved interfaces. For the YUV_SP_420 and YVU_SP_420 formats, it is recommended that the padding size be an even number. When the padding size is an odd number, it is automatically aligned up. For example, if you enter a padding size of (1, 1, 1, 1), it is automatically aligned to (2, 2, 2, 2), and 2 pixels are padded on the top, bottom, left, and right. When the input image resolution is 4095 × 4095 and the padding size is (1, 0, 1, 0), the automatically aligned padding size is 4097 × 4097, which exceeds the range. Therefore, the padding fails.
- The resolution of
outputImageis 18 × 6 to 4096 × 4096. The width is automatically aligned to 16, and the height is aligned to 2. The range is [32 × 6, 4096 × 4096].
APP_ERROR ImageProcessor::Padding(const Image& inputImage, Dim &padDim, const Color& color, const BorderType borderType, Image& outputImage);
| Parameter | Input/Output | Description |
|---|---|---|
| inputImage | Input | Image class before padding. The Image class obtained from the Decode interface and other VPC interfaces can be directly used as input. If the Image class is constructed by you, you need to set the image width and height and the aligned image width and height. |
| padDim | Input | Padding size of the input image. |
| color | Input | Three-channel color value for padding. It takes effect only when borderType is set to BORDER_CONSTANT. |
| borderType | Input | Padding mode. For details, see BorderType. |
| outputImage | Output | Image class after padding. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Resize
Image scaling interface of the ImageProcessor class.
For the related usage process, see Scaling.
For the image formats supported by the input and output Image classes, see the following.
Atlas 200I/500 A2 inference products support YUV_SP_420 and YVU_SP_420 (nv12 and nv21).Atlas inference products andAtlas 800I A2 inference products support YUV_SP_420, YVU_SP_420, RGB_888, and BGR_888 (nv12, nv21, rgb, and bgr), where the resolution of the RGB (BGR) image format must not exceed (4096 × 4096).
The real image resolution range of
inputImageis [18 × 6, 4096 × 4096], where the width and height of the YUV_SP_420 and YVU_SP_420 formats can reach 8192 × 8192.Maximum resolution of the
resizeparameter: 4096 × 4096. Minimum resolution: 32 × 6.The width of
outputImageis automatically aligned to 16, and the height is aligned to 2. Therefore, the width and height range is 32 × 6 to 4096 × 4096.The width and height of the scaled image must not exceed the [1/32, 16] multiple range of the real image.
APP_ERROR ImageProcessor::Resize(const Image& inputImage, const Size& resize, Image& outputImage, const Interpolation interpolation, AscendStream& stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| inputImage | Input | Image class before scaling. The Image class obtained from the Decode interface and other VPC interfaces can be directly used as input. If the Image class is constructed by you, you need to set the image width and height and the aligned image width and height. |
| resize | Input | Width and height of the scaled input image. |
| interpolation | Input | Scaling mode of the input image. For the optional parameters, see the following. HUAWEI_HIGH_ORDER_FILTER = 0BILINEAR_SIMILAR_OPENCV = 1NEAREST_NEIGHBOR_OPENCV = 2BILINEAR_SIMILAR_TENSORFLOW = 3NEAREST_NEIGHBOR_TENSORFLOW = 4 |
| outputImage | Output | Image class after scaling. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Class Description
The Tensor data class serves as the data structure for the input and output of model inference.
The Tensor class involves applying for device-side resources, which conflicts with the scope of MxDeInit. Therefore, its scope cannot be greater than or equal to the scope of MxDeInit.
The hardware support of the interfaces is shown in Table 1. The meanings of the symbols are as follows:
- √: Supported
- x: Not supported
Table 1 Hardware support of interfaces
| Interface | |||
|---|---|---|---|
| BatchConcat | √ | √ | √ |
| Clone | √ | √ | √ |
| GetByteSize | √ | √ | √ |
| GetData | √ | √ | √ |
| GetDataType | √ | √ | √ |
| GetDeviceId | √ | √ | √ |
| GetMemoryType | √ | √ | √ |
| GetReferRect | √ | √ | √ |
| GetShape | √ | √ | √ |
| GetValidRoi | √ | √ | √ |
| IsEmpty | √ | √ | √ |
| IsWithMargin | √ | √ | √ |
| Malloc | √ | √ | √ |
| operator = | √ | √ | √ |
| operator == | √ | √ | √ |
| SetShape | √ | √ | √ |
| Tensor | √ | √ | √ |
| ~Tensor | √ | √ | √ |
| TensorFree | √ | √ | √ |
| TensorMalloc | √ | √ | √ |
| ToDevice | √ | √ | √ |
| ToDvpp | √ | √ | √ |
| ToHost | √ | √ | √ |
| SetReferRect | x | √ | x |
| SetTensorValue | √ | √ | √ |
| SetValidRoi | √ | √ | √ |
| Transpose | √ | √ | √ |
BatchConcat
Combines multiple Tensors into a batch along the batch dimension. By default, the first dimension of each input Tensor is the batch dimension, and the memory is contiguous.
friend APP_ERROR Tensor::BatchConcat(const std::vector<Tensor> &inputs, Tensor &output);
| Parameter | Input/Output | Description |
|---|---|---|
| inputs | Input | List of Tensors to be combined into a batch. |
| output | Output | Tensor assembled into a batch. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Clone
Prototype 1:
Performs a deep copy of the Tensor and returns the copied Tensor.
- If the Tensor is on the host side, the copy process is always a synchronous operation.
- If the Tensor is on the DVPP or device side, whether the operation is synchronous or asynchronous depends on the
streamparameter. The device where the Tensor resides must be the same as the device where the stream resides.
Prototype 2:
Performs a deep copy of the specified area of the Tensor, copying the content of the src area to the area of the assigned tensor. The following requirements must be met:
- Neither
srcnor the assigned Tensor can be empty. The length and width of the assigned Tensor must be [64, 4096]. The maximum height ofsrcmust not exceed "1048576", and the total size (N × H × W × C) ofsrcmust not exceed "67108864". srcand the assigned Tensor must contain reference areas (ReferRect) with the same width and height, and neither can be 0. The width of the ReferRect must not exceed "1920".- The data types of
srcand the assigned Tensor support uint8 and float16, and the types must be the same. srcand the assigned Tensor support only Tensors in NHWC, HWC, and HW shapes (the number of channels is 1 or 3, and N is 1). The dimensions and number of channels of both must be equal.srcand the assigned Tensor must be on the DVPP or device side.- The device where
srcand the assigned Tensor reside must be the same as the device where the stream resides.
// Prototype 1
Tensor Tensor::Clone(AscendStream &stream=AscendStream::DefaultStream()) const;
// Prototype 2 (applicable only to Atlas inference products)
APP_ERROR Tensor::Clone(const Tensor &src, AscendStream &stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src | Input | Assigns the specified reference area of src to the reference area of the tensor that executes this method. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
Prototype 1:
| Data Structure | Description |
|---|---|
| Tensor | Tensor class. See Tensor. |
Prototype 2:
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
GetByteSize
Obtains the number of bytes occupied by the Tensor data memory.
size_t Tensor::GetByteSize() const;
| Data Structure | Description |
|---|---|
| size_t | Number of bytes occupied by the Tensor data memory. |
GetData
Obtains the memory data of the Tensor.
void* Tensor::GetData() const;
| Data Structure | Description |
|---|---|
| void* | Raw pointer to the Tensor data. |
GetDataType
Obtains the data type of the Tensor.
MxBase::TensorDType Tensor::GetDataType() const;
| Data Structure | Description |
|---|---|
| MxBase::TensorDType | Data type of the Tensor. See TensorDType. |
GetDeviceId
Obtains the number of the chip where the Tensor data resides.
int32_t Tensor::GetDeviceId() const;
| Data Structure | Description |
|---|---|
| int32_t | Number of the chip where the Tensor data resides (-1 indicates the host side). |
GetMemoryType
Obtains the memory type of the Tensor.
MemoryData::MemoryType Tensor::GetMemoryType() const;
| Data Structure | Description |
|---|---|
| MemoryData::MemoryType | Data type of MemoryType. See MemoryData. |
GetReferRect
Supports querying the reference area of the Tensor.
Rect Tensor::GetReferRect() const;
| Data Structure | Description |
|---|---|
| MxBase::Rect | Data type of Rect. See Rect. |
GetShape
Obtains the shape data of the Tensor.
std::vector<uint32_t> Tensor::GetShape() const;
| Data Structure | Description |
|---|---|
| std::vector<uint32_t> | Shape data of the Tensor. |
GetValidRoi
Supports querying the valid area of the Tensor.
Rect Tensor::GetValidRoi() const;
| Data Structure | Description |
|---|---|
| MxBase::Rect | Data type of Rect. See Rect. |
IsEmpty
Checks whether the Tensor is empty.
bool Tensor::IsEmpty() const;
| Data Structure | Description |
|---|---|
| bool | Boolean result indicating whether the Tensor is empty. |
IsWithMargin
Queries whether the Tensor has padding.
bool Tensor::IsWithMargin() const;
| Data Structure | Description |
|---|---|
| bool | Boolean result indicating whether the Tensor has padding. |
Malloc
Memory allocation interface of the Tensor. The Tensor memory allocated by using this interface does not need to be managed by you. It is released internally.
APP_ERROR Tensor::Malloc();
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
operator =
The Tensor class overloads the assignment operator, which performs a deep copy of member variables, a shallow copy of memory data, and increments the reference count by one.
Tensor &operator=(const Tensor &other);
| Parameter | Input/Output | Description |
|---|---|---|
| other | Input | Input Tensor class. |
operator ==
The Tensor class overloads the equality operator to check whether the contents of two Tensors are equal.
bool operator==(const Tensor &other);
| Parameter | Input/Output | Description |
|---|---|---|
| other | Input | Input Tensor class. |
SetShape
Sets the shape of the Tensor.
APP_ERROR Tensor::SetShape(std::vector<uint32_t> shape);
| Parameter | Input/Output | Description |
|---|---|---|
| shape | Input | Shape of the Tensor. The number of elements represented by shape must be the same as the number of elements represented by the original shape of the Tensor. Each dimension in the shape vector must be a positive integer, and a single value or the product of all values must be smaller than 536,870,912 (512 × 1024 × 1024). Otherwise, the function throws an exception. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Tensor
Constructor of the Tensor class.
Tensor::Tensor(); // Default constructor. If construction fails, a std::runtime_error exception is thrownTensor::Tensor(const Tensor &other); // Copy construction is supportedTensor::Tensor(const std::vector<uint32_t> &shape, const MxBase::TensorDType &dataType, const int32_t &deviceId = -1);
// If memory is not passed in, memory can be allocated by using the Malloc interface. The allocated memory does not need to be released by you. If construction fails, a std::runtime_error exception is thrownTensor::Tensor(void* usrData,const std::vector<uint32_t> &shape, const MxBase::TensorDType &dataType, const int32_t &deviceId = -1);
// The memory data constructed by the user is passed in, and the user is responsible for managing this memory (ensuring the lifecycle of the memory data). If construction fails, a std::runtime_error exception is thrownTensor::Tensor(const std::vector<uint32_t> &shape, const MxBase::TensorDType &dataType, const int32_t &deviceId, bool `isDvpp`);Tensor::Tensor(void *usrData, const std::vector<uint32_t> &shape, const MxBase::TensorDType &dataType,const int32_t &deviceId, const bool `isDvpp`, const bool isBorrowed);Tensor::Tensor(const Tensor &tensor, const Rect &rect); // Copy constructor with a reference area, which can be used to construct an ROI area (applicable only to Atlas inference products)
| Parameter | Input/Output | Description |
|---|---|---|
| other | Input | Another initialized Tensor. |
| usrData | Input | Input memory constructed by the user. The user is responsible for applying for and releasing this memory. |
| shape | Input | Shape attribute of the Tensor. |
| dataType | Input | Data type of the Tensor. For details, see TensorDType. |
| deviceId | Input | Device ID where the Tensor resides. The default value is -1, indicating the host side.usrData is passed in, this value must be on the same side as deviceId (host side: -1, device side: a specific device ID). Otherwise, subsequent services may face risks and exceptions. |
| isDvpp | Input | Sets whether to allocate DVPP memory. If deviceId is -1, host-side memory is allocated, and this parameter is invalid.If the user pointer usrData is passed in and isDvpp is set to true, ensure that the memory pointed to by usrData is on the device side. Otherwise, subsequent services may face risks and exceptions. |
| isBorrowed | Input | Sets whether the memory pointed to by usrData is released by the Tensor. If isBorrowed is set to false, the Tensor releases the memory pointed to by usrData, and you do not need to release it. If isBorrowed is set to true, you need to manage the memory pointed to by usrData by yourself.If the memory is delegated to the Tensor for management, only memory that needs to be manually released is supported. Otherwise, the memory may be released repeatedly. |
| rect | Input | Coordinates of the reference area of the image (x0, y0, x1, y1), with left-closed and right-open intervals. If constructed by using Tensor(const Tensor &tensor, const Rect &rect), the following requirements must be met: tensor cannot be empty. Only Tensors in NHWC, HWC, and HW formats are supported. The number of channels is 1/3/4. The batch dimension is 1. x0 and y0 of the rect area must be smaller than x1 and y1, respectively. x0, y0, x1, and y1 must be within the width and height range of the tensor. |
| tensor | Input | Another initialized Tensor. |
~Tensor
Default destructor of the Tensor class.
Tensor::~Tensor();TensorFree
Releases Tensor data.
static APP_ERROR Tensor::TensorFree(Tensor &tensor);
| Parameter | Input/Output | Description |
|---|---|---|
| tensor | Input | Tensor class data to be released. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
TensorMalloc
Memory allocation interface of the Tensor. The Tensor memory allocated by using this interface does not need to be managed by you. It is released internally.
This interface is expected to be officially discontinued in December 2025. You are advised to use Malloc.
static APP_ERROR Tensor::TensorMalloc(Tensor &tensor);
| Parameter | Input/Output | Description |
|---|---|---|
| tensor | Output | Tensor for which memory is to be allocated. It is constructed by using the constructor that does not pass in memory. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
ToDevice
Transfers Tensor data to the device side.
- If the original memory is passed in through the constructor by the user, the user is responsible for releasing the original memory.
- If the memory is allocated through TensorMalloc or Malloc, the data is transferred to the device side, and the original memory is automatically released.
APP_ERROR Tensor::ToDevice(int32_t deviceId);
| Parameter | Input/Output | Description |
|---|---|---|
| deviceId | Input | Transfers the Tensor to the device corresponding to deviceId. deviceId must be a valid device ID. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
ToDvpp
Transfers Tensor data to the DVPP side.
- If the original memory is passed in through the constructor by the user, the user is responsible for releasing the memory.
- If the memory is allocated through TensorMalloc or Malloc, the original memory is automatically released without user management.
- When you use media data processing functions and allocate DVPP-side memory, certain constraints apply. For details, see the CANN Application Development Guide (C&C++).
APP_ERROR Tensor::ToDvpp(int32_t deviceId);
| Parameter | Input/Output | Description |
|---|---|---|
| deviceId | Input | Transfers the Tensor to the device corresponding to deviceId. deviceId must be a valid device ID. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
ToHost
Transfers Tensor data to the host side.
- If the original memory is passed in through the constructor by the user, the user is responsible for releasing the memory.
- If the memory is allocated through TensorMalloc or Malloc, the data is transferred to the host side, and the original memory is automatically released without user management.
APP_ERROR Tensor::ToHost();
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
SetReferRect
Supports setting the reference area of the Tensor. NHWC (N=1), HWC, and HW dimensions are supported. The number of channels can be 1, 3, or 4. The width and height of the reference area must not exceed the original image.
Currently supported only on
APP_ERROR Tensor::SetReferRect(Rect rect);
| Parameter | Input/Output | Description |
|---|---|---|
| rect | Input | Coordinate frame of the input image, where x0 < x1 and y0 < y1. For the data type, see Rect. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
SetTensorValue
Sets the value of the Tensor. int32_t, uint8_t, float16, and float32 types are supported.
The Tensor object must be on the device side, and the data type must match the SetTensorValue method called.
The device where the Tensor resides must be the same as the device where the stream resides.
APP_ERROR Tensor::SetTensorValue(uint8_t value, AscendStream& stream = AscendStream::DefaultStream());APP_ERROR Tensor::SetTensorValue(float value, bool IsFloat16 = false, AscendStream& stream = AscendStream::DefaultStream());APP_ERROR Tensor::SetTensorValue(int32_t value, AscendStream& stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| value | Input | int32_t, uint8_t, or float type, specifying the value to be set for the Tensor. |
| isFloat16 | Input | bool type. The default value is false. If set to true, the Tensor elements are set to the float16 type. If set to false, the Tensor elements are set to the float32 type. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
SetValidRoi
Supports setting the valid area of the Tensor. NHWC (N=1), HWC, and HW dimensions are supported. The width and height of the valid area must not exceed the original image.
APP_ERROR Tensor::SetValidRoi(Rect rect);
| Parameter | Input/Output | Description |
|---|---|---|
| rect | Input | Coordinate frame of the input image. For the data type, see Rect. The start coordinate (x0, y0) can only be (0, 0). |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Transpose
Transposes the input Tensor data according to a specified set of axis dimensions (axes). If no specific axis dimension is specified, the Tensor data is transposed in reverse order by default.
This function supports memory reuse for output data. You can pass in output data through pre-allocated memory (the memory size must be the same as the input).
This function supports operations only on the host side. To process Tensor data on the device side, first use the ToHost interface to transfer the device-side data to the host side, and then perform transposition.
friend APP_ERROR Tensor::Transpose(const Tensor &input, Tensor &output, std::vector<uint32_t> axes = {});
| Parameter | Input/Output | Description |
|---|---|---|
| input | Input | Tensor class to be transposed. Dimensions of 2, 3, and 4 are supported. The data types float32, float16, and uint8 are supported. |
| output | Output | Tensor class after transposition. |
| axes | Input | Transposition option. The default value is empty. If no specific axes are specified, a reverse-order axes list is generated by default to transpose the data in input in reverse order. For example, for a three-dimensional tensor, the default reverse-order axes is {2, 1, 0}. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
General Description
The underlying operators called by some interfaces in this section enable fusion rules by default to improve computing efficiency. All fusion rules used by the operators are recorded in the "fusion_result.json" file in the directory where the interfaces are executed. For the detailed field description and the configuration of the fusion rule switch, see --fusion_switch_file in CANN ATC Offline Model Compilation Tool User Guide.
For the related usage process, see Tensor Operations.
- When you use interfaces that support operator preloading in a multi-thread scenario, preload the related operator interfaces through MxInitFromConfig to ensure correct resource lifecycles. For details, see Example of Initializing the Operator Preload File.
The hardware support of the interfaces is shown in Table 1. The meanings of the symbols are as follows:
- √: Supported
- x: Not supported
Table 1 Hardware support of interfaces
| Interface | |||
|---|---|---|---|
| Abs | √ | √ | × |
| AbsDiff | √ | √ | × |
| AbsSum | × | √ | × |
| Add | √ | √ | × |
| AddWeighted | √ | √ | × |
| BackgroundReplace | × | √ | × |
| BatchSplit | √ | √ | × |
| BitwiseAnd | √ | √ | × |
| BitwiseNot | √ | √ | × |
| BitwiseOr | √ | √ | × |
| BitwiseXor | √ | √ | × |
| BlendImageCaption | × | √ | × |
| BlendImages | × | √ | × |
| Clip | √ | √ | × |
| Compare | √ | √ | × |
| ConvertTo | √ | √ | × |
| Crop | x | √ | x |
| CropResize | x | √ | x |
| CvtColor | √ | √ | √ |
| Divide | √ | √ | × |
| Erode | × | √ | × |
| Exp | √ | √ | × |
| Hstack | √ | √ | × |
| Log | √ | √ | × |
| Max | √ | √ | × |
| Merge | √ | √ | × |
| Min | √ | √ | × |
| MinMax | × | √ | × |
| MinMaxLoc | × | √ | × |
| Multiply | √ | √ | × |
| Pow | √ | √ | × |
| Reduce | √ | √ | × |
| Rescale | √ | √ | × |
| Resize | × | √ | √ |
| ResizePaste | × | √ | × |
| Rotate | × | √ | √ |
| ScaleAdd | √ | √ | × |
| Sort | √ | √ | × |
| SortIdx | √ | √ | × |
| Split | √ | √ | × |
| Sqr | √ | √ | × |
| SqrSum | × | √ | × |
| Sqrt | √ | √ | × |
| Subtract | √ | √ | × |
| Sum | × | √ | × |
| Threshold | √ | √ | × |
| ThresholdBinary | √ | √ | × |
| Tile | × | √ | × |
| Transpose | √ | √ | × |
| Vstack | √ | √ | × |
| WarpAffineHiper | × | √ | × |
| WarpPerspective | × | √ | × |
Abs
Tensor absolute value operation of the Tensor class. float16, float32, and uint8 are supported. Asynchronous calls are supported. Inplace operations are not supported.
Currently supported on
On
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- The shapes of the Tensors corresponding to the input and output parameters must be equal, the types must be consistent, and the dimensions must not exceed 4.
- On
Atlas inference products , when the input Tensor data type is Float32 or Float16 and the size is larger than 480P (640 × 480), or the input Tensor data type is uint8 and the size is larger than 1080P (1920 × 1080), the Abs computing performance is better than that of cv::abs on the CPU. - On
Atlas 200I/500 A2 inference products , when the input size is 720P (720 × 1280), the computing performance is better than that of cv::abs on the CPU.
APP_ERROR Abs(const Tensor &src, Tensor &dst, AscendStream& stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src | Input | Tensor class, the input tensor. float16, float32, and uint8 inputs are supported. The data memory must be on the device or DVPP side. |
| dst | Output | Tensor class, the output tensor. The types float16, float32, and uint8 are supported. An empty Tensor can be passed in. If dst is not empty, its shape must be the same as that of src, memory must be allocated in advance by calling the Tensor.Malloc() interface, and the data memory must be on the device side (the same device as src) or the DVPP side. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
AbsDiff
Image processing algorithm. AbsDiff calculates the absolute difference of tensors. float16, float32, and uint8 are supported. Asynchronous calls and preloading are supported. Inplace operations are not supported.
Currently supported on
On
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- Pay attention to data out-of-bounds issues.
- The shapes of the Tensors corresponding to the input and output parameters must be equal, the types must be consistent, and the dimensions must not exceed 4.
- On
Atlas inference products , when the input Tensor data type is float32 or float16 and the size is larger than 480P (640 × 480), or the input Tensor data type is uint8 and the size is larger than 1080P (1920 × 1080), theAbsDiffcomputing performance is better than that of cv::absdiff on the CPU. - On
Atlas 200I/500 A2 inference products , when the input size is 720P (720 × 1280), the computing performance is better than that of cv::absdiff on the CPU.
APP_ERROR AbsDiff(const Tensor &src1, const Tensor &src2, Tensor &dst, AscendStream& stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src1 | Input | Tensor class, the input tensor. float16, float32, and uint8 inputs are supported. The data memory must be on the device or DVPP side. |
| src2 | Input | Tensor class, the input tensor. float16, float32, and uint8 inputs are supported. The data memory must be on the device or DVPP side. |
| dst | Output | Tensor class, the output tensor. The types float16, float32, and uint8 are supported. An empty Tensor can be passed in. If dst is not empty, its shape must be the same as that of src1/src2, memory must be allocated in advance by calling the Tensor.Malloc() interface, and the data memory must be on the device side (the same device as src) or the DVPP side. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
AbsSum
Image processing algorithm. AbsSum calculates the sum of absolute values of a tensor. float32 and uint8 are supported. Asynchronous calls are supported.
Currently supported only on
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- Pay attention to data type out-of-bounds issues.
- The number of channels of the Tensors corresponding to the input and output parameters must be consistent. The input Tensor supports only HWC, and the number of channels can be 1 or 3. The data type of the output Tensor is always float32.
APP_ERROR AbsSum(const Tensor &src, Tensor &dst, AscendStream &stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src | Input | Tensor class, the input tensor. float32 and uint8 inputs are supported. |
| dst | Output | Tensor class, the output tensor. Only float32 output is supported. An empty Tensor can be passed in. If dst is not an empty Tensor, memory must be allocated in advance by calling the Tensor.Malloc() interface. If the input Tensor shape is HWC, the output shape is C. For example, if the input Tensor is [16,16,3], the output Tensor shape is [3]. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Add
Image processing algorithm. Add performs tensor addition. float16, float32, and uint8 are supported. Asynchronous calls are supported.
Currently supported on
On
The following conditions must be met:
The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
Pay attention to data type out-of-bounds issues.
The shapes of the Tensors corresponding to the input and output parameters must be equal, the types must be consistent, and the dimensions must not exceed 4.
On
Atlas inference products , when the input size is larger than 1080P (1920 × 1080), the computing performance is better than that of cv::add on the CPU.On
Atlas 200I/500 A2 inference products , when the input size is 720P (720 × 1280), the computing performance is better than that of cv::add on the CPU.On
Atlas inference products , inplace operations are supported. When inplace operations are supported, the input and output Tensors support HW/HWC/NHWC, and the input and output Tensors can have different HW, but the shapes of the ROIs involved in the operation must be the same.Only interfaces that support inplace operations can reuse ROIs with each other. For specifying the ROI area, see Tensor.
APP_ERROR Add(const Tensor &src1, const Tensor &src2, Tensor &dst, AscendStream &stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src1 | Input | Tensor class, the addend and input tensor. float16, float32, and uint8 inputs are supported. |
| src2 | Input | Tensor class, the addend and input tensor. float16, float32, and uint8 inputs are supported. |
| dst | Output | Tensor class, the output tensor. float16, float32, and uint8 outputs are supported. An empty Tensor can be passed in. If dst is not an empty Tensor, memory must be allocated in advance by calling the Tensor.Malloc() interface. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
AddWeighted
Image processing. Tensor weighted blending interface of the Tensor class (that is, dst = alpha × src1 + beta × src2 + gamma). float16, float32, and uint8 are supported. Asynchronous calls are supported. Inplace operations are not supported.
Currently supported on
On
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- Pay attention to data out-of-bounds issues.
- The shapes of the Tensors corresponding to the input and output parameters must be equal, the types must be consistent, and the dimensions must not exceed 4.
APP_ERROR AddWeighted(const Tensor &src1, float alpha, const Tensor &src2, float beta, float gamma, Tensor &dst, AscendStream &stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src1 | Input | Tensor class, the input tensor. float16, float32, and uint8 inputs are supported. The data memory must be on the device or DVPP side. |
| alpha | Input | float type, coefficient of tensor src1. |
| src2 | Input | Tensor class, the input tensor. float16, float32, and uint8 inputs are supported. The data memory must be on the device or DVPP side. |
| beta | Input | float type, coefficient of tensor src2. |
| gamma | Input | float type, the value added to dst at the end of the calculation. |
| dst | Output | Tensor class, the output tensor. The types float16, float32, and uint8 are supported. An empty Tensor can be passed in. If dst is not empty, its shape must be the same as that of src1/src2, memory must be allocated in advance by calling the Tensor.Malloc() interface, and the data memory must be on the device side (the same device as src) or the DVPP side. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
BackgroundReplace
Background replacement interface. Blends the input new background image with the existing image, replacing the background with the new one through a mask (that is, dst = background × (1-mask) + replace × mask). Asynchronous calls are supported.
When background and dst are the same Tensor, inplace replacement can be implemented.
Currently supported only on
This interface depends on CANN 8.0.RC1 or a later version.
The following conditions must be met:
- The data memory and stream of the input and output Tensors of the interface must reside on the same device.
- In the synchronous scenario, the device where the data memory of the input and output Tensors resides must be the same as the initialized device.
- The width and height of the inputs and outputs can be inconsistent. During calculation, the smallest valid area is used for replacement. The valid area is the tensor itself. If a reference area is set for the tensor, the valid area is the reference area.
APP_ERROR BackgroundReplace(Tensor &background, const Tensor &replace, const Tensor &mask, Tensor &dst, AscendStream &stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| background | Input | Tensor class, the input tensor and the target tensor to be replaced. float16 and uint8 types are supported. HW (two-dimensional) and HWC (three-dimensional) dimensions are supported, where "C" (number of channels) is 1 or 3. The tensor width supports [1,4096], and the tensor height supports [1,4096]. The data memory must be on the device side or the DVPP side. |
| replace | Input | Tensor class, the input tensor and the replacement tensor. float16 and uint8 types are supported. HW (two-dimensional) and HWC (three-dimensional) dimensions are supported, where "C" (number of channels) is 1 or 3. The tensor width supports [1,4096], and the tensor height supports [1,4096]. The data memory must be on the device side or the DVPP side. The data type and dimensions (including C) must be the same as those of background. |
| mask | Input | Tensor class, the input tensor and the mask tensor. float16 is supported. HW (two-dimensional) and HWC (three-dimensional) dimensions are supported. When the C of background and replace is 1, C supports 1. When the C of background and replace is 3, C supports 1 and 3. The tensor width supports [1,4096], and the tensor height supports [1,4096]. The data memory must be on the device side or the DVPP side. |
| dst | Output | Tensor class, the output tensor and the replacement result tensor. float16 and uint8 types are supported. HW (two-dimensional) and HWC (three-dimensional) dimensions are supported, where "C" (number of channels) is 1 or 3. The tensor width supports [1,4096], and the tensor height supports [1,4096]. The data memory must be on the device side or the DVPP side. The data type and dimensions (including C) must be the same as those of background. If dst is not empty, memory must be allocated in advance by calling the Tensor.Malloc() interface. An empty tensor can be passed in. The data type and dimensions of the output tensor are the same as those of background. The width is the minimum valid area width of background, mask, and dst, and the height is the minimum valid area height of background, mask, and dst. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
BatchSplit
Image processing algorithm. Tensors support batch splitting. float16, float32, and uint8 are supported. Asynchronous calls and input/output memory reuse are supported.
Currently supported on
The following conditions must be met:
- All parameters of the interface (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- The types of the Tensors corresponding to the input and output parameters must be consistent. The input Tensor shape must be three-dimensional or four-dimensional, such as NWHC/NCHW/NHW.
- When the output is not empty, the size of the output vector must be equal to the Batch size of the input Tensor, and each Tensor in the output vector is the result of removing the batch dimension from the input Tensor, that is, NWHC/NCHW/NHW is split into N WHC/CHW/HW.
APP_ERROR BatchSplit(const Tensor &src, std::vector<Tensor> &dst, bool isReplace, AscendStream &stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src | Input | Tensor class, the input tensor. The Tensor supports float16, float32, and uint8 types. Three-dimensional or four-dimensional dimensions are supported. |
| dst | Output | std::vector<Tensor> class, the output. float16, float32, and uint8 are supported (must be consistent with src). An empty vector can be passed in. If the vector is not empty, memory must be allocated in advance for the Tensors in the vector by calling the Tensor.Malloc() interface. |
| isReplace | Input | bool type. When set to true, the output dst reuses the memory of the input src, and the lifecycles of the two are consistent. Therefore, you need to ensure this by yourself. When set to false, the output dst and the input src do not affect each other (the memory release of each is determined by its own lifecycle). |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value or isReplace is true, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
BitwiseAnd
Image processing algorithm. BitwiseAnd performs bitwise AND. uint8 is supported. Asynchronous calls are supported. Inplace operations are not supported.
Currently supported on
On
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- The shapes of the Tensors corresponding to the input and output parameters must be equal, the types must be consistent, and the dimensions must not exceed 4.
APP_ERROR BitwiseAnd(const Tensor &src1, const Tensor &src2, Tensor &dst, AscendStream& stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src1 | Input | Tensor class, the input tensor. uint8 input is supported. |
| src2 | Input | Tensor class, the input tensor. uint8 input is supported. |
| dst | Output | Tensor class, the output tensor. uint8 output is supported. An empty Tensor can be passed in. If dst is not an empty Tensor, memory must be allocated in advance by calling the Tensor.Malloc() interface. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
BitwiseNot
Image processing algorithm. BitwiseNot performs bitwise NOT. uint8 is supported. Asynchronous calls are supported. Inplace operations are not supported.
Currently supported on
On BitwiseXor. For the example, see Example of Initializing the Operator Preload File).
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- Pay attention to data out-of-bounds issues.
- The shapes of the Tensors corresponding to the input and output parameters must be equal, the types must be consistent, and the dimensions must not exceed 4.
APP_ERROR BitwiseNot(const Tensor &src, Tensor &dst, AscendStream& stream=AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src | Input | Tensor class, the input tensor. uint8 input is supported. The data memory must be on the device or DVPP side. |
| dst | Output | Tensor class, the output tensor. uint8 is supported. An empty Tensor can be passed in. If dst is not empty, its shape must be the same as that of src, memory must be allocated in advance by calling the Tensor.Malloc() interface, and the data memory must be on the device side (the same device as src) or the DVPP side. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
BitwiseOr
Image processing algorithm. BitwiseOr performs bitwise OR. uint8 is supported. Asynchronous calls are supported. Inplace operations are not supported.
Currently supported on
On
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- The shapes of the Tensors corresponding to the input and output parameters must be equal, the types must be consistent, and the dimensions must not exceed 4.
APP_ERROR BitwiseOr(const Tensor &src1, const Tensor &src2, Tensor &dst, AscendStream& stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src1 | Input | Tensor class, the input tensor. uint8 input is supported. |
| src2 | Input | Tensor class, the input tensor. uint8 input is supported. |
| dst | Output | Tensor class, the output tensor. uint8 output is supported. An empty Tensor can be passed in. If dst is not an empty Tensor, memory must be allocated in advance by calling the Tensor.Malloc() interface. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
BitwiseXor
Image processing algorithm. BitwiseXor performs bitwise XOR. uint8 is supported. Asynchronous calls are supported. Inplace operations are not supported.
Currently supported on
On
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- The shapes of the Tensors corresponding to the input and output parameters must be equal, the types must be consistent, and the dimensions must not exceed 4.
APP_ERROR BitwiseXor(const Tensor &src1, const Tensor &src2, Tensor &dst, AscendStream& stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src1 | Input | Tensor class, the input tensor. uint8 input is supported. |
| src2 | Input | Tensor class, the input tensor. uint8 input is supported. |
| dst | Output | Tensor class, the output tensor. uint8 output is supported. An empty Tensor can be passed in. If dst is not an empty Tensor, memory must be allocated in advance by calling the Tensor.Malloc() interface. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
BlendImageCaption
Pastes the caption and background board onto the image frame according to the caption opacity and background board opacity (that is, caption × alpha/255 + (1-alpha/255) × (1-Opacity) × frame + captionBg × Opacity × (1-alpha/255)). Asynchronous calls are supported.
Currently supported only on
The following conditions must be met:
- The data memory and stream of the input and output Tensors of the interface must reside on the same device.
- In the synchronous scenario, the device where the data memory of the input and output Tensors resides must be the same as the initialized device.
- The calculation area of pasting is determined by the caption tensor. By default, it is its reference area. If no reference area is set, the entire caption tensor is used as the calculation area. The other tensors need to have reference areas with the same width and height. If no reference area is set, the entire tensor is used as the calculation area. The calculation areas of all input and output tensors must have the same width and height. The maximum calculation width is 1920.
APP_ERROR `BlendImageCaption`(Tensor &frame, const Tensor &caption, const Tensor &captionAlpha, const Tensor &`captionBg`, float captionBgOpacity, AscendStream &stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| frame | Input and Output | Tensor class, the input and output tensor and the background frame tensor. The width and height ranges are both [64, 4096]. Only the UINT8 type is supported. NHWC (N is 1), HWC, and HW are supported, where the number of channels must be the same as that of caption. The data memory must be on the device or DVPP side. An empty tensor cannot be passed in. |
| caption | Input | Tensor class, the input tensor and the caption tensor. The width and height ranges are both [64, 4096]. Only the UINT8 type is supported. NHWC (N is 1), HWC, and HW are supported, and the number of channels is 1 or 3. The data memory must be on the device or DVPP side. An empty tensor cannot be passed in. |
| captionAlpha | Input | Tensor class, the input tensor and the mask tensor of the caption image. The width and height ranges are both [64, 4096]. Only the UINT8 type is supported. NHWC (N is 1), HWC, and HW are supported, and the number of channels is 1. The data memory must be on the device or DVPP side. An empty tensor cannot be passed in. |
| captionBg | Input | Tensor class, the input tensor and the caption background image tensor. The width and height ranges are both [64, 4096]. Only the UINT8 type is supported. NHWC (N is 1), HWC, and HW are supported, where the number of channels must be the same as that of caption. The data memory must be on the device or DVPP side. An empty tensor cannot be passed in. |
| captionBgOpacity | Input | Opacity of the background board. The value range is [0,1]. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
BlendImages
Opacity pasting interface. Pastes the material frame onto the background frame according to its opacity (that is, materialrgb × (materialalpha/255) + (1-materialalpha/255) × frame). Asynchronous calls are supported.
Currently supported only on
This interface depends on CANN 8.0.RC1 or a later version.
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- The width and height of the inputs and outputs can be inconsistent. During calculation, the smallest valid area is used for replacement.
APP_ERROR BlendImages(const Tensor &material, Tensor &frame, AscendStream& stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| material | Input | Tensor class, the input tensor and the material frame tensor. uint8 is supported. HWC (three-dimensional) dimension is supported, where "C" (number of channels) is "4" (that is, the RGBA format). The tensor width supports [1,4096], and the tensor height supports [1,4096]. The data memory must be on the device side or the DVPP side. An empty Tensor cannot be passed in. |
| frame | Input and Output | Tensor class, the input and output tensor and the background frame tensor. uint8 is supported. HWC (three-dimensional) dimension is supported, where "C" (number of channels) is 3 (that is, the RGB format). The tensor width supports [1,4096], and the tensor height supports [1,4096]. The data memory must be on the device side or the DVPP side. An empty Tensor cannot be passed in. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Clip
Image processing. Tensor clipping interface of the Tensor class, used to limit the elements in the tensor to a given minimum value and maximum value (elements smaller than the minimum value are replaced with the minimum value, and elements greater than the maximum value are replaced with the maximum value). Asynchronous calls are supported. Inplace operations are not supported.
Currently supported on
On
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- The types of the Tensors corresponding to the input and output parameters must be consistent, the shapes must be equal, and the dimensions must not exceed 4.
APP_ERROR Clip(const Tensor &src, Tensor &dst, float minVal, float maxVal, AscendStream &stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src | Input | Tensor class. float16, float32, and uint8 inputs are supported. |
| dst | Output | Tensor class. float16, float32, and uint8 outputs are supported. An empty Tensor can be passed in. If dst is not an empty Tensor, memory must be allocated in advance by calling the Tensor.Malloc() interface. |
| minVal | Input | float type, the minimum value after clipping in the tensor. Elements smaller than the minimum value are replaced with the minimum value. minVal must be smaller than or equal to maxVal. |
| maxVal | Input | float type, the maximum value after clipping in the tensor. Elements greater than the maximum value are replaced with the maximum value. maxVal must be greater than or equal to minVal. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Compare
Image processing algorithm. Compare is a tensor comparison algorithm. The input and output tensors support float16, float32, and uint8. Asynchronous calls are supported. Inplace operations are not supported.
Currently supported on
On
The following conditions must be met:
The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
The types and shapes of the Tensors corresponding to the input and output parameters must be the same, and the dimensions must not exceed 4.
On
Atlas inference products , when the input Tensor data type is float32 and the size is larger than 480P (640 × 480), the data type is uint8 and the size is larger than 1080P (1920 × 1080), or the data type is float16 and the size is larger than 960 × 540, the Compare computing performance is better than that of cv::compare on the CPU.On
Atlas 200I/500 A2 inference products , when the input size is 720P (720 × 1280), the computing performance is better than that of cv::compare on the CPU.
APP_ERROR Compare(const Tensor &src1, const Tensor &src2, Tensor &dst, const CmpOp cmpOp = CmpOp::CMP_EQ, AscendStream& stream = AscendStream::DefaultStream());
Parameters
| Parameter | Input/Output | Description |
|---|---|---|
| src1 | Input | Tensor class, the input tensor. float16, float32, and uint8 inputs are supported. The data memory must be on the device or DVPP side. |
| src2 | Input | Tensor class, the input tensor. float16, float32, and uint8 inputs are supported. The data memory must be on the device or DVPP side. |
| dst | Output | Tensor class, the output tensor. When the comparison result is met, the tensor result is 255. Otherwise, it is 0. float16, float32, and uint8 outputs are supported. An empty Tensor can be passed in. If dst is not an empty Tensor, memory must be allocated in advance by calling the Tensor.Malloc() interface. |
| cmpOp | Input | Enumeration value, corresponding to the tensor comparison type. Only equal to, not equal to, less than, greater than, less than or equal to, and greater than or equal to are supported. For details, see CmpOp. enum class CmpOp { CMP_EQ = 0, CMP_NE, CMP_LT, CMP_GT, CMP_LE, CMP_GE }; |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
ConvertTo
Converts the values of the Tensor to the specified type. Conversions among float32, float16, int8, int32, uint8, int16, uint16, uint32, int64, uint64, double64, and bool types are supported. Asynchronous calls are supported.
Currently supported on
On
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- On
Atlas inference products ,srcsupports inplace operations. Whensrcsupports inplace operations, the input and output Tensors support HW/HWC/NHWC. Conversions between u8 and fp16/fp32 types are supported. The output Tensor is not allowed to set ROI, and the Shape width and height of the output Tensor must be consistent with the ROI width and height ofsrc.
APP_ERROR ConvertTo(const Tensor &src, Tensor &dst, const MxBase::TensorDType &dataType, AscendStream& stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src | Input | Tensor class, the input tensor. In inplace operations, the ROI of src and the shape of dst are consistent. In non-inplace operations, the shapes of src and dst are consistent. |
| dst | Output | Tensor class, the output tensor. An empty Tensor can be passed in. If dst is not an empty Tensor, memory must be allocated in advance by calling the Tensor.Malloc() interface. |
| dataType | Input | TensorDType class, specifying the type to convert to. It must be the same as the TensorDType attribute of dst. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Crop
Cropping interface of the Tensor class. Asynchronous execution is supported. The Tensor memory applied for by using this interface does not need to be managed by you. It is released internally.
For the related usage process, see Cropping.
Currently supported only on
The image formats supported by the input and output Tensor classes are YUV_400 and RGB_888, and the input resolution must not exceed (4096 × 4096).
The real image resolution range of
inputTensor: 10 × 6 to 4096 × 4096. When the input image format is YUV_400, the range is 18 × 6 to 4096 × 4096.The cropping area must not exceed the input image area. The maximum resolution of the cropping area is 4096 × 4096.
- When the input image format is "RGB_888", the minimum resolution of the cropping area is 10 × 6.
- When the input image format is "YUV_400", the minimum resolution of the cropping area is 18 × 6.
In the output
outputTensorVecoroutputTensor, ifkeepMarginis set totrue, the width of the output image is automatically aligned to 16, and the range is 10 × 6 to 4096 × 4096. The default value of thekeepMarginparameter isfalse, which means the invalid boundary area in the Tensor is not retained, and the width and height of the output Tensor are the same as the cropped width and height.An empty vector can be passed in, but the vector cannot contain empty Tensors. If a valid area is set for the input Tensor, the cropping area must be within the valid area. Otherwise, cropping fails.
In the batch cropping scenario, only one input Tensor is supported. The length of the cropping configuration parameter
cropRectVecmust not exceed 256, and the number of output Tensors must not exceed 256 and must satisfy number of output Tensors = number of input images × length of the cropping configuration parametercropRectVec.
Prototype 1:
APP_ERROR Crop(const Tensor &inputTensor, const Rect &cropRect, Tensor &outputTensor, bool keepMargin = false, AscendStream& stream = AscendStream::DefaultStream());Prototype 2:
APP_ERROR Crop(const Tensor &inputTensor, const std::vector<Rect> &cropRectVec, std::vector<Tensor> &`outputTensorVec`, bool keepMargin = false, AscendStream& stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| inputTensor | Input | Tensor class, the input tensor. It cannot be empty. Memory must be allocated on the device/DVPP side, and the data type is UINT8. The input tensor width range is [10, 4096], and the height range is [6, 4096]. If the input or output tensor format contains YUV400, the width range is [18, 4096]. |
| cropRect | Input | Cropping coordinate frame of the input Tensor. It must not exceed the width and height range of the input tensor. |
| cropRectVec | Input | List of cropping coordinate frames of the input Tensor (for the batch cropping scenario). |
| outputTensor | Output | Tensor class after cropping. |
| outputTensorVec | Output | List of Tensor classes after cropping (for the batch cropping scenario). |
| keepMargin | Input | Whether to retain the invalid boundary area in the Tensor in the output outputTensor. The default value is false, which means the invalid boundary area in the Tensor is not retained, that is, the width and height of the output Tensor are the same as the cropped width and height. |
| stream | Input | Stream used for asynchronous execution. The default value is AscendStream::DefaultStream(), which creates a default stream (that is, synchronous execution). |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
CropResize
Cropping and scaling interface of the Tensor class. Asynchronous execution is supported. The Tensor memory applied for by using this interface does not need to be managed by you. It is released internally.
For the related usage process, see Cropping and Scaling.
Currently supported only on
The image formats supported by the input and output Tensor classes are YUV_400 and RGB_888, where the input resolution must not exceed (4096 × 4096).
The real image width and height range of
inputTensor: 10 × 6 to 4096 × 4096. If the input or output tensor format is YUV_400, the width range is [18, 4096].The cropping area must not exceed the real image width and height of the input image. The maximum resolution of the cropping area is 4096 × 4096.
- When the input image format is "RGB_888", the minimum resolution of the cropping area is 10 × 6.
- When the input image format is "YUV_400", the minimum resolution of the cropping area is 18 × 6.
The scaling range is 10 × 6 to 4096 × 4096. When the input image format is YUV_400, the minimum resolution is 18 × 6. The scaling range must not exceed the [1/32, 16] multiple range of the cropping area.
The number of cropping areas must not be greater than 256. The number of cropping areas, the number of scaling ranges, and the number of output tensors must be equal.
In the output
outputTensorVec, if thekeepMarginparameter is set totrue, the width of the output Tensor is automatically aligned to 16. The default value of thekeepMarginparameter isfalse, which means the invalid boundary area in the Tensor is not retained, that is, the width and height of the output Tensor are the same as the scaling parameters.An empty vector can be passed in, but the vector cannot contain empty Tensors. If a valid area is set for the input Tensor, the cropping area must be within the valid area. Otherwise, cropping fails.
APP_ERROR CropResize(const Tensor &inputTensor, const std::vector<Rect> &cropRectVec, const std::vector<Size> &sizeVec, std::vector<Tensor> &`outputTensorVec`, const Interpolation interpolation = Interpolation::BILINEAR_SIMILAR_OPENCV, bool keepMargin = false, AscendStream& stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| inputTensor | Input | Tensor class, the input tensor. It cannot be empty. Memory must be allocated on the device/DVPP side, and the data type is UINT8. The input tensor width range is [10, 4096], and the height range is [6, 4096]. If the input or output tensor format contains YUV400, the width range is [18, 4096]. |
| cropRectVec | Input | List of input cropping parameters (Rect class). It must have the same number of elements as the output Tensor list. |
| sizeVec | Input | List of input scaling parameters (Size class). It must have the same number of elements as the output Tensor list. |
| outputTensorVec | Output | List of Tensor classes after cropping and scaling. |
| interpolation | Input | Scaling mode of the input Tensor. For the optional parameters, see the following. HUAWEI_HIGH_ORDER_FILTER = 0BILINEAR_SIMILAR_OPENCV = 1NEAREST_NEIGHBOR_OPENCV = 2 |
| keepMargin | Input | Whether to retain the invalid boundary area in the Tensor in the output outputTensor. The default value is false, which means the invalid boundary area in the Tensor is not retained, that is, the width and height of the output Tensor are the same as the scaling parameter width and height. |
| stream | Input | Stream used for asynchronous execution. The default value is AscendStream::DefaultStream(), which creates a default stream (that is, synchronous execution). |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
CvtColor
Converts the image color space type of the Tensor to the specified color space type. Conversions among the following types are supported.
If keepMargin of outputTensor is set to true, the output width is automatically aligned to 16. The default value is false, which means the invalid boundary area in the Tensor is not retained.
For the related usage process, see Color Space Conversion.
The color space conversion types supported by each product are shown in Table 1. The meanings of the symbols are as follows:
- √: Supported
- x: Not supported
Table 1 Color space conversion types
| Color Space Conversion Type | |||
|---|---|---|---|
| YUVSP420 (nv12) to YUV400 (GRAY) | √ | √ | √ |
| YVUSP420 (nv21) to YUV400 (GRAY) | x | √ | √ |
| YUVSP420 (nv12) to RGB | x | √ | √ |
| YUVSP420 (nv12) to BGR | x | √ | √ |
| YVUSP420 (nv21) to RGB | x | √ | √ |
| YVUSP420 (nv21) to BGR | x | √ | √ |
| RGB to YUVSP420 (nv12) | x | √ | √ |
| RGB to YVUSP420 (nv21) | x | √ | √ |
| BGR to YUVSP420 (nv12) | x | √ | √ |
| BGR to YVUSP420 (nv21) | x | √ | √ |
| RGB to YUV400 (GRAY) | x | √ | √ |
| BGR to YUV400 (GRAY) | x | √ | √ |
| BGR to RGB | x | √ | √ |
| RGB to BGR | x | √ | √ |
| RGB to RGBA | x | √ | √ |
| RGBA to YUV400 (GRAY) | x | √ | √ |
| RGBA to RGB | x | √ | √ |
| GRAY to RGB | x | √ | x |
| RGBA to mRGBA | x | √ | x |
RGBA to mRGBA requires CANN 8.0.RC1 or a later version.
APP_ERROR CvtColor(const Tensor &inputTensor, Tensor &outputTensor, const CvtColorMode &mode, bool keepMargin = false, AscendStream &stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| inputTensor | Input | Tensor class, the input tensor. It cannot be empty. Memory must be allocated on the device/DVPP side, and the data type is UINT8. The tensor shape is {height, width, number of channels}, and the number of channels must be consistent with the input format. For RGBA to mRGBA, only 4 channels are supported. If the inputTensor color space type is YUVSP420 or YVUSP420, when setting the input tensor shape, the height is 1.5 times the display height of the image. The tensor height must be a multiple of 3, the width must be a multiple of 16, and the number of channels is 1. When inputTensor uses the SetValidRoi interface to set the valid area, its y1 (corresponding to the valid height of the tensor) must be a multiple of 3, and the valid height of the corresponding actual image is y1/3 × 2. The input tensor width range is [10, 4096], and the height range is [6, 4096]. If the input or output tensor format contains YUV400, YUVSP420, YVUSP420, or GRAY, the width range is [18, 4096]. For grayscale images, a tensor with the shape {height × width} is supported. |
| outputTensor | Output | Tensor class, the output tensor. If it is not empty, memory must be allocated on the device/DVPP side, and the data type is UINT8. For RGBA to mRGBA or GRAY to RGB, the tensor type is the same as the input Tensor. |
| mode | Input | Enumeration value, corresponding to the original type and target type of the color space conversion. For details, see CvtColorMode. If the mode color space type is COLOR_BGR2YUVSP420, COLOR_RGB2YUVSP420, COLOR_RGB2YVUSP420, or COLOR_BGR2YVUSP420, you are advised to set the RGB Tensor width and height to even numbers. Otherwise, abnormal data may exist on the edge of the output image. The height of the output tensor is 1.5 times the height of the input tensor. For example, if the input height is 4096, the output height is 6144, which exceeds the limit of the DVPP interface. Pay attention to whether the subsequent service requirements can be met. |
| keepMargin | Input | Whether to retain the invalid boundary area in the Tensor in the output outputTensor. The default value is false, which means the invalid boundary area in the Tensor is not retained. If keepMargin is set to true, the output width is automatically aligned to 16, and the invalid area is retained. When mode=COLOR_GRAY2RGB or mode=COLOR_RGBA2mRGBA, this parameter is invalid. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Divide
Image processing algorithm. Divide performs tensor division. float16, float32, and uint8 are supported. Asynchronous calls are supported, and some function prototypes support preloading. Inplace operations are not supported.
Currently supported on
On
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- Pay attention to data type out-of-bounds issues.
- On
Atlas inference products , this interface performs saturation calculation. When the data value exceeds the data type range, no wraparound occurs. OnAtlas 200I/500 A2 inference products , this interface is a non-saturation interface. - The shapes of the Tensors corresponding to the input and output parameters must be equal, and the dimensions must not exceed 4.
src1andsrc2can be of different data types, and the data type ofdstis determined by the higher precision data type ofsrc1andsrc2. - On
Atlas inference products , when the input size is larger than 240P (320 × 240), the computing performance is better than that of cv::divide on the CPU. - On
Atlas 200I/500 A2 inference products , when the input size is 720P (720 × 1280), the computing performance is better than that of cv::divide on the CPU.
Prototype 1
APP_ERROR Divide(const Tensor &src1, const Tensor &src2, Tensor &dst, AscendStream &stream = AscendStream::DefaultStream());Prototype 2 (not applicable to
APP_ERROR Divide(const Tensor &src1, const Tensor &src2, Tensor &dst, float scale, AscendStream& stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src1 | Input | Tensor class, the dividend and input tensor. float16, float32, and uint8 inputs are supported. |
| src2 | Input | Tensor class, the divisor and input tensor. float16, float32, and uint8 inputs are supported. The elements in src2 cannot be 0. |
| dst | Output | Tensor class, the output tensor. float16, float32, and uint8 outputs are supported. An empty Tensor can be passed in. If dst is not an empty Tensor, memory must be allocated in advance by calling the Tensor.Malloc() interface. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| scale | Input | float type, the input scalar. The result of multiplying the input Tensor src1 by the scalar is then divided by src2. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Erode
Image processing algorithm. Erode performs image erosion. Erosion is a morphological processing algorithm commonly used in graphics processing. Erosion can remove noise and some boundary values. float16, float32, and uint8 are supported. Asynchronous calls are supported, but preloading is not supported. Inplace operations are not supported.
Currently supported on
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- The shapes of the Tensors corresponding to the input and output parameters must be equal. HW and HWC are supported.
- When the input size is larger than 240P (320 × 240), the computing performance is better than that of cv::erode on the CPU.
APP_ERROR Erode(const Tensor& src, Tensor& dst, const BlurConfig& blurconfig, AscendStream& stream=AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src | Input | Tensor class, the input tensor and the tensor to be eroded. uint8, fp16, and fp32 data types are supported. The HWC dimension is required (c=1, 3, 4). The tensor width supports [64,4096], and the tensor height supports [64,4096]. |
| dst | Output | Tensor class, the output tensor. The data type and shape are the same as those of src. An empty Tensor can be passed in. If dst is not an empty Tensor, memory must be allocated in advance by calling the Tensor.Malloc() interface. |
| blurConfig | Input | Configuration of the erosion algorithm parameters. For details, see BlurConfig. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Exp
Image processing algorithm. Exp calculates the natural exponent of a tensor. float16 and float32 are supported. Asynchronous calls are supported. Preloading is supported (see Example of Initializing the Operator Preload File). Inplace operations are not supported.
Currently supported on
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- The shapes of the Tensors corresponding to the input and output parameters must be equal, the types must be consistent, and the dimensions must not exceed 4.
- On
Atlas inference products , when the Tensor size is larger than 480P (640 × 480), the Exp computing performance is better than that of cv::exp on the CPU. - On
Atlas 200I/500 A2 inference products , when the input size is 720P (720 × 1280), the computing performance is better than that of cv::exp on the CPU.
APP_ERROR Exp(const Tensor &src, Tensor &dst, AscendStream &stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src | Input | Tensor class, the input tensor. float16 and float32 inputs are supported. |
| dst | Output | Tensor class, the output tensor. float16 and float32 outputs are supported. An empty Tensor can be passed in. If dst is not an empty Tensor, memory must be allocated in advance by calling the Tensor.Malloc() interface. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Hstack
Image processing algorithm. Horizontal stacking operation of tensors. float16, float32, and uint8 are supported. Asynchronous calls are supported, and preloading is supported (see Example of Initializing the Operator Preload File).
Currently supported on
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- Pay attention to data type out-of-bounds issues.
- The shapes of the Tensors corresponding to the input and output parameters must be equal (except the "W" dimension), the types must be consistent, and the dimensions must not exceed 4.
- The total width of the input Tensors must be smaller than or equal to the maximum width of the Tensor type (the maximum value of the uint32 type).
- When the output Tensor is not empty, the output Tensor width must be equal to the total width of the input Tensors.
APP_ERROR Hstack(const std::vector <Tensor> &tv, Tensor &dst, AscendStream &stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| tv | Input | std::vector<Tensor> class, used to store the Tensors waiting to be concatenated. The Tensor supports float16, float32, and uint8 types. The data memory must be on the device side or the DVPP side. HW (2-dimensional), HWC (3-dimensional), and NHWC (4-dimensional) dimensions are supported, and the length of the tv tensor must be greater than 1 (at least 2 Tensors must be passed in). The length of tv is subject to the successful construction of the vector. The sum of the widths of the Tensors in tv must not exceed the maximum width of the Tensor class (the maximum value of uint32). |
| dst | Output | Tensor class, the output tensor and the concatenated Tensor. float16, float32, and uint8 are supported (must be consistent with tv). An empty Tensor can be passed in. If dst is not empty, its shape must be the same as that of tv, the "W" dimension (width) must be equal to the sum of the "W" of all Tensors in tv, memory must be allocated in advance by calling the Tensor.Malloc() interface, and the data memory must be on the device side (the same device as tv) or the DVPP side. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Log
Image processing algorithm. Log calculates the natural logarithm of a tensor. float16 and float32 are supported. Asynchronous calls are supported. Preloading is supported (see Example of Initializing the Operator Preload File). Inplace operations are not supported.
Currently supported on
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- The shapes of the Tensors corresponding to the input and output parameters must be equal, the types must be consistent, and the dimensions must not exceed 4.
- On
Atlas inference products , when the Tensor size is larger than 480P (640 × 480), the Log computing performance is better than that of cv::log on the CPU. - On
Atlas 200I/500 A2 inference products , when the input size is 720P (720 × 1280), the computing performance is better than that of cv::log on the CPU.
APP_ERROR Log(const Tensor &src, Tensor &dst, AscendStream &stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src | Input | Tensor class, the input tensor. float16 and float32 inputs are supported. When the element value of the input tensor is 0, the corresponding output tensor element value is -inf. |
| dst | Output | Tensor class, the output tensor. float16 and float32 outputs are supported. An empty Tensor can be passed in. If dst is not an empty Tensor, memory must be allocated in advance by calling the Tensor.Malloc() interface. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Max
Image processing algorithm. Max takes the larger value of two input Tensors by comparing them element by element. float16, float32, and uint8 are supported. Asynchronous calls are supported. Inplace operations are not supported.
Currently supported on
On
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- The shapes of the Tensors corresponding to the input and output parameters must be equal, the types must be consistent, and the dimensions must not exceed 4.
- On
Atlas inference products , when the input Tensor data type is float32 or float16 and the size is larger than 480P (640 × 480), or the input Tensor data type is uint8 and the size is larger than 1080P (1920 × 1080), the Max computing performance is better than that of cv::max on the CPU. - On
Atlas 200I/500 A2 inference products , when the input size is 720P (720 × 1280), the computing performance is better than that of cv::max on the CPU.
APP_ERROR Max(const Tensor &src1, const Tensor &src2, Tensor &dst, AscendStream& stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src1 | Input | Tensor class, the input tensor. float16, float32, and uint8 inputs are supported. The data memory must be on the device or DVPP side. |
| src2 | Input | Tensor class, the input tensor. float16, float32, and uint8 inputs are supported. The data memory must be on the device or DVPP side. |
| dst | Output | Tensor class, the output tensor. The types float16, float32, and uint8 are supported. An empty Tensor can be passed in. If dst is not empty, its shape must be the same as that of src1/src2, memory must be allocated in advance by calling the Tensor.Malloc() interface, and the data memory must be on the device side (the same device as src) or the DVPP side. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Merge
Image processing. Image channel merging interface of the Tensor class, used to merge multiple images into one multi-channel image. Asynchronous calls are supported.
Currently supported on
On
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- The shapes of the Tensors corresponding to the input and output parameters must be equal (except the last dimension), and the types must be consistent.
APP_ERROR Merge(const std::vector <Tensor> &tv, Tensor &dst, AscendStream& stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| tv | Input | std::vector <Tensor> class, used to store the Tensors waiting to be merged. The Tensor supports float16, float32, and uint8 types. HWC (three-dimensional) and NHWC (four-dimensional) dimensions are supported, and the length of the tv vector must be greater than 1 (at least 2 Tensors must be passed in). |
| dst | Output | Tensor class, the merged multi-channel Tensor. float16, float32, and uint8 types are supported. An empty Tensor can be passed in. If dst is not an empty Tensor, memory must be allocated in advance by calling the Tensor.Malloc() interface. The C (number of channels) in dst is 3 or 4, equal to the total number of C in tv. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Min
Image processing algorithm. Min takes the smaller value of two input Tensors by comparing them element by element. float16, float32, and uint8 are supported. Asynchronous calls are supported. Inplace operations are not supported.
Currently supported on
On
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- The shapes of the Tensors corresponding to the input and output parameters must be equal, the types must be consistent, and the dimensions must not exceed 4.
- On
Atlas inference products , when the input Tensor data type is float32 or float16 and the size is larger than 480P (640 × 480), or the input Tensor data type is uint8 and the size is larger than 1080P (1920 × 1080), the Min computing performance is better than that of cv::min on the CPU. - On
Atlas 200I/500 A2 inference products , when the input size is 720P (720 × 1280), the computing performance is better than that of cv::min on the CPU.
APP_ERROR Min(const Tensor &src1, const Tensor &src2, Tensor &dst, AscendStream& stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src1 | Input | Tensor class, the input tensor. float16, float32, and uint8 inputs are supported. The data memory must be on the device or DVPP side. |
| src2 | Input | Tensor class, the input tensor. float16, float32, and uint8 inputs are supported. The data memory must be on the device or DVPP side. |
| dst | Output | Tensor class, the output tensor. The types float16, float32, and uint8 are supported. An empty Tensor can be passed in. If dst is not empty, its shape must be the same as that of src1/src2, memory must be allocated in advance by calling the Tensor.Malloc() interface, and the data memory must be on the device side (the same device as src) or the DVPP side. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
MinMax
Image processing algorithm. Obtains the minimum value and maximum value of the input tensor. float16, float32, and uint8 are supported.
Currently supported only on
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- The input Tensor must be two-dimensional or three-dimensional (with one channel). The output Tensor is the extremum of all elements of the input Tensor (the output Tensor is one-dimensional, with one element).
APP_ERROR MinMax(const Tensor &src, Tensor &minVal, Tensor &maxVal, AscendStream &stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src | Input | Tensor class, the input tensor. float16, float32, and uint8 inputs are supported. |
| minVal | Output | Tensor class, the minimum value and output tensor. The data type is the same as that of src. An empty Tensor can be passed in. If minVal is not an empty Tensor, memory must be allocated in advance by calling the Tensor.Malloc() interface. |
| maxVal | Output | Tensor class, the maximum value and output tensor. The data type is the same as that of src. An empty Tensor can be passed in. If maxVal is not an empty Tensor, memory must be allocated in advance by calling the Tensor.Malloc() interface. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
MinMaxLoc
Image processing algorithm. MinMaxLoc finds the maximum and minimum element values of a tensor and their position indexes. float16, float32, and uint8 are supported. Asynchronous calls are supported.
Currently supported only on
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- The input Tensor must be two-dimensional or three-dimensional (with one channel). The output tensor must be one-dimensional, where the number of elements of the extremum
minValandmaxValmust be 1, and the number of elements of the extremum positions minLoc and maxLoc must be 2.
APP_ERROR MinMaxLoc(const Tensor &src, Tensor &minVal, Tensor &maxVal, Tensor &minLoc, Tensor &maxLoc, AscendStream &stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src | Input | Tensor class, the input tensor. float16, float32, and uint8 inputs are supported. |
| minVal | Output | Tensor class, the minimum value and output tensor. The data type is the same as that of src. An empty Tensor can be passed in. If minVal is not empty, memory must be allocated in advance by calling the Tensor.Malloc() interface. |
| maxVal | Output | Tensor class, the maximum value and output tensor. The data type is the same as that of src. An empty Tensor can be passed in. If maxVal is not empty, memory must be allocated in advance by calling the Tensor.Malloc() interface. |
| minLoc | Output | Tensor class, the position index of the minimum value. The data type is uint32. An empty Tensor can be passed in. If minLoc is not empty, memory must be allocated in advance by calling the Tensor.Malloc() interface. |
| maxLoc | Output | Tensor class, the position index of the maximum value. The data type is uint32. An empty Tensor can be passed in. If maxLoc is not empty, memory must be allocated in advance by calling the Tensor.Malloc() interface. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Multiply
Image processing algorithm. Multiply performs tensor multiplication. float16, float32, and uint8 are supported. Asynchronous calls are supported. Inplace operations are not supported.
Currently supported on
On
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- Pay attention to data type out-of-bounds issues.
- This interface performs saturation calculation. That is, when the
dstdata type is uint8 and the data value exceeds the uint8 maximum value (or is smaller than the uint8 minimum value), thedstvalue is 255 (or 0), and no wraparound occurs. - The shapes of the Tensors corresponding to the input and output parameters must be equal, and the dimensions must not exceed 4.
- When Prototype 1 is called, the data types of the input and output must be consistent. When Prototype 2 is called, different input data types are supported, and the output
dstdata type is consistent with the input Tensor with higher precision. - On
Atlas inference products : for Prototype 1, when the input size is larger than 720P (1280 × 720), the computing performance is better than that of cv::multiply on the CPU. For Prototype 2, when the input size is larger than 480P (640 × 480), the computing performance is better than that of cv::multiply on the CPU. - On
Atlas 200I/500 A2 inference products , when the input size is 720P (720 × 1280), the computing performance is better than that of cv::multiply on the CPU.
Prototype 1:
APP_ERROR Multiply(const Tensor &src1, const Tensor &src2, Tensor &dst, AscendStream &stream = AscendStream::DefaultStream());Prototype 2:
APP_ERROR Multiply(const Tensor &src1, const Tensor &src2, Tensor &dst, double scale, AscendStream& stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src1 | Input | Tensor class, the multiplier and input tensor. float16, float32, and uint8 inputs are supported. |
| src2 | Input | Tensor class, the multiplier and input tensor. float16, float32, and uint8 inputs are supported. |
| dst | Output | Tensor class, the output tensor. float16, float32, and uint8 outputs are supported. An empty Tensor can be passed in. If dst is not an empty Tensor, memory must be allocated in advance by calling the Tensor.Malloc() interface. |
| scale | Input | double type, the input scalar. The result tensor of multiplying the input Tensors src1 and src2 is then multiplied by the scalar. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Pow
Image processing algorithm. Pow performs tensor exponentiation. float16, float32, and uint8 are supported. Asynchronous calls are supported. Inplace operations are not supported.
Currently supported on
On
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- Pay attention to data type out-of-bounds issues.
- The shapes of the Tensors corresponding to the input and output parameters must be equal, the types must be consistent, and the dimensions must not exceed 4.
- On
Atlas inference products , when the Tensor size is larger than 480P (640 × 480) and the exponent value is greater than or equal to 3, the Pow computing performance is better than that of cv::pow on the CPU. - On
Atlas 200I/500 A2 inference products , when the input size is 720P (720 × 1280), the computing performance is better than that of cv::pow on the CPU.
APP_ERROR Pow(const Tensor &src1, const Tensor &src2, Tensor &dst, AscendStream& stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src1 | Input | Tensor class, the base and input tensor. float16, float32, and uint8 inputs are supported. |
| src2 | Input | Tensor class, the exponent and input tensor. float16, float32, and uint8 inputs are supported. |
| dst | Output | Tensor class, the output tensor. float16, float32, and uint8 outputs are supported. An empty Tensor can be passed in. If dst is not an empty Tensor, memory must be allocated in advance by calling the Tensor.Malloc() interface. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Reduce
Image processing algorithm. Reduce is a tensor reduction algorithm. float16, float32, and uint8 are supported. Asynchronous calls are supported, and preloading is supported (see Example of Initializing the Operator Preload File). Inplace operations are not supported.
Currently supported on
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- Pay attention to data type out-of-bounds issues.
- The types and number of channels of the Tensors corresponding to the input and output parameters must be consistent. HW, NHWC, and HWC inputs are supported, and the number of channels can be 1 to 4.
- On
Atlas inference products , when the input Tensor data type is float32 or float16 and the size is larger than 480P (640 × 480), the Reduce computing performance is better than that of cv::reduce on the CPU. - On
Atlas 200I/500 A2 inference products , when the input Tensor data type is float32 or float16 and the size is 480P (480 × 640), the Reduce computing performance is better than that of cv::reduce on the CPU.
APP_ERROR Reduce(const Tensor &src, Tensor &dst, const MxBase::ReduceDim &rDim, const MxBase::ReduceType &rType, AscendStream& stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src | Input | Tensor class, the input tensor. float16, float32, and uint8 inputs are supported. HW, HWC, and NHWC dimension inputs are supported, and the number of channels can be 1 to 4. |
| dst | Output | Tensor class, the output tensor. float16, float32, and uint8 outputs are supported. An empty Tensor can be passed in. If dst is not an empty Tensor, memory must be allocated in advance by calling the Tensor.Malloc() interface. The output shape is the result of removing the reduction axis from the input shape. For example, if the input Tensor is [2,32,16,3] and the reduction axis is H, the output Tensor shape is [2,16,3]. |
| rDim | Input | ReduceDim enumeration type, the reduction axis. Reduction along the height or width dimension is supported. For details, see ReduceDim. |
| rType | Input | ReduceType enumeration type, the reduction operation. Sum, average, maximum, and minimum are supported. For details, see ReduceType. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Rescale
Tensor scaling and addition operation of the Tensor class (that is, dst=src × scale + bias). float16, float32, and uint8 are supported. Asynchronous calls are supported. Inplace operations are not supported.
Currently supported on
On
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- Pay attention to data out-of-bounds issues.
- The shapes of the Tensors corresponding to the input and output parameters must be equal, the types must be consistent, and the dimensions must not exceed 4.
APP_ERROR Rescale(const Tensor &src, Tensor &dst, float scale, float bias, AscendStream& stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src | Input | Tensor class, the input tensor. float16, float32, and uint8 inputs are supported. The data memory must be on the device or DVPP side. |
| dst | Output | Tensor class, the output tensor. The types float16, float32, and uint8 are supported. An empty Tensor can be passed in. If dst is not empty, its shape must be the same as that of src, memory must be allocated in advance by calling the Tensor.Malloc() interface, and the data memory must be on the device side (the same device as src) or the DVPP side. |
| scale | Input | Float type, the scaling factor parameter and input scalar. |
| bias | Input | Float type, the value added to dst at the end of the calculation. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Resize
Scaling interface of the Tensor class. Asynchronous execution is supported. The Tensor memory applied for by using this interface does not need to be managed by you. It is released internally.
For the related usage process, see Scaling.
Currently supported only on
- The image formats supported by the input and output Tensor classes are YUV_400 and RGB_888, where the input resolution must not exceed (4096 × 4096).
- When the data type of the Tensor input to
Atlas inference products is uint8, RGBA format images are supported. - Atlas 800I A2 inference servers do not support RGBA format images.
- If the input Tensor dimensions are HW and HWC (c=1, 3), a valid area can be set, and scaling is performed based on the valid area. For setting the valid area, see Tensor. The output Tensor does not support setting a valid area.
APP_ERROR Resize(const Tensor &src, Tensor &dst, const Size &resize, const Interpolation interpolation = Interpolation::BILINEAR_SIMILAR_OPENCV, bool keepMargin = false, AscendStream& stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src | Input | Tensor class, the input tensor. It cannot be empty. Memory must be allocated on the device/DVPP side. The dimensions must be HW or HWC (c=1, 3, 4). On Atlas 800I A2 inference servers, the uint8 data type is supported. On |
| dst | Output | Tensor class, the output tensor. On Atlas 800I A2 inference servers, the uint8 data type is supported. On src) or the DVPP side. |
| resize | Input | Width and height of the scaled input Tensor. For the Size structure description, see Size. Maximum resolution: 4096 × 4096. Minimum resolution: 10 × 6. When the input image format is YUV_400, the minimum resolution is 18 × 6. The width and height of the scaled image must not exceed the [1/32, 32] multiple range of the real image. If a valid area is set for the input Tensor, the width and height of the scaled image must not exceed the [1/32, 32] multiple range of the valid area. |
| interpolation | Input | Scaling mode of the input Tensor. For the optional parameters, see the following. HUAWEI_HIGH_ORDER_FILTER = 0BILINEAR_SIMILAR_OPENCV = 1NEAREST_NEIGHBOR_OPENCV = 2The following algorithms are supported (the default value is 1). 0, 1: Industry-standard Bilinear algorithm (similar to the OpenCV calculation process. When both the input and output image formats are RGB, within the [1/32, 32] scaling range, the maximum difference from the OpenCV algorithm for a single pixel value is plus or minus 1). 2: Industry-standard Nearest Neighbor algorithm (similar to the OpenCV calculation process.) |
| keepMargin | Input | Whether to retain the invalid boundary area in the Tensor in the output dst. The default value is false, which means the invalid boundary area in the Tensor is not retained, that is, the width and height of the output Tensor are the same as the scaling parameter width and height. If keepMargin is set to true, the output width is automatically aligned to 16 (on |
| stream | Input | Stream used for asynchronous execution. The default value is AscendStream::DefaultStream(), which creates a default stream (that is, synchronous execution). |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
ResizePaste
Image scaling and pasting interface. Asynchronous execution is supported. The Tensor memory applied for by using this interface does not need to be managed by you. It is released internally. Implicit memory allocation is supported. If the size of the image to be pasted is inconsistent, scaling is required first.
Currently supported only on
- For the image formats supported by the input and output Tensor classes, see the following.
- Supported only on
Atlas inference products . The image formats YUV_400 and RGB_888 are supported, where the input resolution must not exceed (4096 × 4096). - The real resolution range of
background: [16 × 6, 4096 × 4096]. - Maximum resolution of the "PasteRects" parameter: 4096 × 4096. Minimum resolution: 10 × 6.
- If
keepMarginofdstis set totrue, the output width is automatically aligned to 16. If thedstwidth is aligned to 16 and the memory is on the DVPP side, the inputbackgroundmemory is reused. - The width and height of the scaled image must not exceed the [1/32, 16] multiple range of the real image.
- The number of input images to be pasted
inputPicsand the pasting areas "PasteRects" must correspond one to one, and the maximum value is "256". - The width of the
inputPicsarea in the result image is aligned to 16. keepMargincontrols whether the output resultdstretains the invalid boundary area in the Tensor. Ifdstreusesbackground,backgroundalso determines whether to retain the invalid boundary area based on thekeepMarginvalue. The default value isfalse.- When the input image format is "YUV_400", the minimum resolution is 18 × 6.
APP_ERROR ResizePaste(const MxBase::Tensor &background, std::vector<MxBase::Tensor> &inputPics, std::vector<MxBase::Rect> &pasteRects, MxBase::Tensor &dst, bool keepMargin = false, MxBase::AscendStream &stream = MxBase::AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| background | Input | Tensor class, the input tensor and the target tensor to be pasted on. uint8 input is supported. HW (2-dimensional) and HWC (3-dimensional) tensor dimensions are supported. The tensor width supports [16,4096], the height supports [6,4096], and grayscale supports [18,4096]. The data memory must be on the device side or the DVPP side. |
| inputPics | Input | std::vector<Tensor> class, the input tensors and the tensor group pasted onto the target tensor. uint8 input is supported. HW (2-dimensional) and HWC (3-dimensional) tensor dimensions are supported. The tensor width supports [10,4096], the height supports [6,4096], and grayscale supports [18,4096]. The data memory must be on the device side or the DVPP side. |
| PasteRects | Input | std::vector<Rect> class, the coordinate frames to be pasted. The coordinate frame width is aligned up to 16. After alignment, the coordinate frame width and height must not exceed the range of the background image background. |
| dst | Output | Tensor class, the output tensor and the pasting result tensor. When keepMargin is true, the result is automatically aligned to 16. uint8 input is supported. HW (2-dimensional) and HWC (3-dimensional) tensor dimensions are supported. The tensor width supports [10,4096], the height supports [6,4096], and grayscale supports [18,4096]. The data memory must be on the device side or the DVPP side. If the dst width is aligned to 16 and the memory is on the DVPP side, the input background memory is reused. |
| keepMargin | Input | bool type, whether to retain the invalid boundary area in the output dst. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Rotate
Image processing. Image rotation interface of the Tensor class. The image can be rotated to a specified angle. Asynchronous calls are supported.
Currently supported only on
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- The types of the Tensors corresponding to the input and output parameters must be consistent.
APP_ERROR Rotate(const Tensor &src, Tensor &dst, const RotateAngle angle, AscendStream& stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src | Input | Tensor class, the input tensor. It cannot be empty. The input must be HWC (three-dimensional) or HW (two-dimensional). For |
| dst | Output | Tensor class, the result after rotation. An empty Tensor can be passed in. For dst is not an empty Tensor, memory must be allocated in advance by calling the Tensor.Malloc() interface. float16, float32, and uint8 types are supported. For dst is not an empty Tensor, the input tensor width range is [10, 4096]. When the input image format is YUV_400, the minimum width is 18, and the height range is [10, 4096]. Memory must be allocated on the device/DVPP side, and the uint8 type is supported. If the rotation angle is 180 degrees, the shape is the same as that of src. If the rotation angle is 90 degrees or 270 degrees, the shape is the transposed shape of the HW channels of src. |
| angle | Input | RotateAngle enumeration class, specifying the clockwise rotation angle. 90 degrees, 180 degrees, and 270 degrees are supported (ROTATE_90, ROTATE_180, and ROTATE_270). |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
ScaleAdd
Tensor scaling and addition operation of the Tensor class (that is, dst=src1 × scale + src2). float16, float32, and uint8 are supported. Asynchronous calls are supported. Inplace operations are not supported.
Currently supported on
On
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- Pay attention to data out-of-bounds issues.
- The shapes of the Tensors corresponding to the input and output parameters must be equal, the types must be consistent, and the dimensions must not exceed 4.
- On
Atlas inference products , when the input Tensor data type is Float32 or Float16 and the size is larger than 480P (640 × 480), or the input Tensor data type is uint8 and the size is larger than 1080P (1920 × 1080), the ScaleAdd computing performance is better than that of cv::scaleAdd on the CPU. - On
Atlas 200I/500 A2 inference products , when the input size is 720P (720 × 1280), the computing performance is better than that of cv::scaleAdd on the CPU.
APP_ERROR ScaleAdd(const Tensor &src1, float scale, const Tensor &src2, Tensor &dst, AscendStream& stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src1 | Input | Tensor class, the input tensor. float16, float32, and uint8 inputs are supported. The data memory must be on the device or DVPP side. |
| scale | Input | Scaling factor parameter, the input scalar, of the Float type. |
| src2 | Input | Tensor class, the input tensor. float16, float32, and uint8 inputs are supported. The data memory must be on the device or DVPP side. |
| dst | Output | Tensor class, the output tensor. The types float16, float32, and uint8 are supported. An empty Tensor can be passed in. If dst is not empty, its shape must be the same as that of src1/src2, memory must be allocated in advance by calling the Tensor.Malloc() interface, and the data memory must be on the device side (the same device as src) or the DVPP side. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Sort
Image processing algorithm. Sort is a tensor sorting algorithm. The input and output tensors support float16, float32, and uint8. Asynchronous calls are supported. Preloading is supported (during preloading, the attr attribute needs to be added. For the example, see Example of Initializing the Operator Preload File). Inplace operations are not supported.
Currently supported on
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- The types of the Tensors corresponding to the input and output parameters must be consistent. Only HW is supported for input and output.
- On
Atlas inference products , when the input Tensor data type is float32 or float16 and the size is larger than 480P (640 × 480), or the input Tensor data type is uint8 and the size is larger than 1080P (1920 × 1080), the Sort computing performance is better than that of cv::sort on the CPU. - On
Atlas 200I/500 A2 inference products , when the input size is 720P (720 × 1280), the computing performance is better than that of cv::sort on the CPU.
APP_ERROR Sort(const Tensor &src, Tensor &dst, int axis, bool descending, AscendStream& stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src | Input | Tensor class, the input tensor. float16, float32, and uint8 inputs are supported. Only HW dimension input is supported. |
| dst | Output | Tensor class, the output tensor. The tensor content indicates the value sorting result. float16, float32, and uint8 outputs are supported. An empty Tensor can be passed in. If dst is not an empty Tensor, memory must be allocated in advance by calling the Tensor.Malloc() interface. |
| axis | Input | Dimension specified for sorting. The value range is [0, 1], where 0 indicates sorting by the height dimension and 1 indicates sorting by the width dimension. |
| descending | Input | Ascending/descending option. The default value is false, indicating ascending order. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
SortIdx
Image processing algorithm. SortIdx is a tensor sorting index algorithm. The input tensor supports float16, float32, and uint8, and the output tensor supports only int32. Asynchronous calls are supported. Preloading is supported (during preloading, the attr attribute needs to be added. For the example, see Example of Initializing the Operator Preload File). Inplace operations are not supported.
Currently supported on
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- The sizes of the Tensors corresponding to the input and output parameters must be consistent. Only HW is supported for input and output.
- On
Atlas inference products , when the input Tensor data type is float32 or float16 and the size is larger than 480P (640 × 480), or the input Tensor data type is uint8 and the size is larger than 1080P (1920 × 1080), theSortIdxcomputing performance is better than that of cv::sortIdx on the CPU. - On
Atlas 200I/500 A2 inference products , when the input size is 720P (720 × 1280), the computing performance is better than that of cv::sortIdx on the CPU.
APP_ERROR SortIdx(const Tensor &src, Tensor &`dstIdx`, int axis, bool descending, AscendStream& stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src | Input | Tensor class, the input tensor. float16, float32, and uint8 inputs are supported. Only HW dimension input is supported. |
| dstIdx | Output | Tensor class, the output tensor. The tensor content indicates the index sequence result after value sorting. Only int32 output is supported. An empty Tensor can be passed in. If dst is not an empty Tensor, memory must be allocated in advance by calling the Tensor.Malloc() interface. When the same values exist in src, the sorting result of dstIdx (sorting result index values) on |
| axis | Input | Dimension specified for sorting. The value range is [0, 1], where 0 indicates sorting by the height dimension and 1 indicates sorting by the width dimension. |
| descending | Input | Ascending/descending option. The default value is false, indicating ascending order. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Split
Image processing. Image channel splitting interface of the Tensor class, used to split a multi-channel image into single-channel images. Asynchronous calls are supported.
Currently supported on
On
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- The shapes of the Tensors corresponding to the input and output parameters must be equal (except the last dimension), and the types must be consistent.
APP_ERROR Split(const Tensor &src, std::vector<Tensor> &tv, AscendStream &stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src | Input | Tensor class. float16, float32, and uint8 inputs are supported. HWC (three-dimensional) and NHWC (four-dimensional) dimensions are supported, where C (number of channels) is 3 or 4. |
| tv | Input/Output | std::vector<Tensor> class, used to store the split single-channel Tensors. The elements of the Tensor class support float16, float32, and uint8 types. An empty vector can be passed in. If the vector is not empty, memory must be allocated in advance for the Tensors in the vector by calling the Tensor.Malloc() interface. The length of tv is the same as that of src, and C of each element is 1. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Sqr
Image processing algorithm. Sqr performs tensor square calculation. float16, float32, and uint8 are supported. Asynchronous calls are supported. Inplace operations are not supported.
Currently supported on
On
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- Pay attention to data type out-of-bounds issues.
- The shapes of the Tensors corresponding to the input and output parameters must be equal, the types must be consistent, and the dimensions must not exceed 4.
- On
Atlas inference products , when the input size is 480P (640 × 480), the Sqr computing performance is better than that of cv::pow(src, 2,dst) on the CPU. - On
Atlas 200I/500 A2 inference products , when the input size is 720P (720 × 1280), the computing performance is better than that of cv::pow on the CPU.
APP_ERROR Sqr(const Tensor &src, Tensor &dst, AscendStream& stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src | Input | Tensor class, the input tensor. float16, float32, and uint8 inputs are supported. |
| dst | Output | Tensor class, the output tensor. float16, float32, and uint8 outputs are supported. An empty Tensor can be passed in. If dst is not an empty Tensor, memory must be allocated in advance by calling the Tensor.Malloc() interface. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
SqrSum
Image processing algorithm. SqrSum calculates the sum of squares of a tensor. float32 and uint8 are supported. Asynchronous calls are supported.
Currently supported only on
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- Pay attention to data type out-of-bounds issues.
- The number of channels of the Tensors corresponding to the input and output parameters must be consistent. The input Tensor supports only HWC, and the number of channels can be 1 or 3. The data type of the output Tensor is always float32.
APP_ERROR SqrSum(const Tensor &src, Tensor &dst, AscendStream &stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src | Input | Tensor class, the input tensor. float32 and uint8 inputs are supported. |
| dst | Output | Tensor class, the output tensor. Only float32 output is supported. An empty Tensor can be passed in. If dst is not an empty Tensor, memory must be allocated in advance by calling the Tensor.Malloc() interface. If the input Tensor shape is HWC, the output shape is C. For example, if the input Tensor is [16,16,3], the output Tensor shape is [3]. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Sqrt
Image processing algorithm. Sqrt performs tensor square root calculation. float16 and float32 are supported. Asynchronous calls are supported. Inplace operations are not supported.
Currently supported on
On
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- The shapes of the Tensors corresponding to the input and output parameters must be equal, the types must be consistent, and the dimensions must not exceed 4. The values cannot be negative.
- On
Atlas inference products , when the Tensor size is larger than 480P (640 × 480), the Sqrt computing performance is better than that of cv::sqrt on the CPU. - On
Atlas 200I/500 A2 inference products , when the input size is 720P (720 × 1280), the computing performance is better than that of cv::sqrt on the CPU.
APP_ERROR Sqrt(const Tensor &src, Tensor &dst, AscendStream &stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src | Input | Tensor class, the input tensor. float16 and float32 inputs are supported. |
| dst | Output | Tensor class, the output tensor. float16 and float32 outputs are supported. An empty Tensor can be passed in. If dst is not an empty Tensor, memory must be allocated in advance by calling the Tensor.Malloc() interface. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Subtract
Image processing algorithm. Subtract performs tensor subtraction. float16, float32, and uint8 are supported. Asynchronous calls are supported. Inplace operations are not supported.
Currently supported on
On
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- Pay attention to data type out-of-bounds issues.
- The shapes of the Tensors corresponding to the input and output parameters must be equal, the types must be consistent, and the dimensions must not exceed 4.
- On
Atlas inference products , when the input Tensor data type is float32 or float16 and the size is larger than 1080P (1920 × 1080), the computing performance is better than that of cv::subtract on the CPU. - On
Atlas 200I/500 A2 inference products , when the input size is 720P (720 × 1280), the computing performance is better than that of cv::subtract on the CPU.
APP_ERROR Subtract(const Tensor &src1, const Tensor &src2, Tensor &dst, AscendStream &stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src1 | Input | Tensor class, the minuend and input tensor. float16, float32, and uint8 inputs are supported. |
| src2 | Input | Tensor class, the subtrahend and input tensor. float16, float32, and uint8 inputs are supported. When the type is uint8, the element at the corresponding position in src2 cannot be greater than the element in src1. |
| dst | Output | Tensor class, the output tensor. float16, float32, and uint8 outputs are supported. An empty Tensor can be passed in. If dst is not an empty Tensor, memory must be allocated in advance by calling the Tensor.Malloc() interface. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Sum
Image processing algorithm. Sum is a tensor channel summation algorithm. float16, float32, and uint8 are supported. Asynchronous calls are supported. Inplace operations are not supported.
Currently supported only on
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- Pay attention to data type out-of-bounds issues.
- The types and number of channels of the Tensors corresponding to the input and output parameters must be consistent. NHWC and HWC inputs are supported, and the number of channels can be 1 to 4.
- On
Atlas inference products , when the input Tensor data type is Float32 and the size is larger than 480P (640 × 480), or the input Tensor data type is Float16 and the size is larger than 540P (960 × 540), the Sum computing performance is better than that of cv::sum on the CPU.
APP_ERROR Sum(const Tensor &src, Tensor &dst, AscendStream& stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src | Input | Tensor class, the base and input tensor. float16, float32, and uint8 inputs are supported. |
| dst | Output | Tensor class, the output tensor. float16, float32, and uint8 outputs are supported. An empty Tensor can be passed in. If dst is not an empty Tensor, memory must be allocated in advance by calling the Tensor.Malloc() interface. When the input Tensor shape is NHWC, the output shape is NC. When the input Tensor shape is HWC, the output shape is C. For example, if the input Tensor is [2,16,16,3], the output Tensor shape is [2,3]. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Threshold
Image processing. Threshold processing interface of the Tensor class. float16, float32, and uint8 are supported. Asynchronous calls are supported. Inplace operations are not supported.
Currently supported on
On
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- Pay attention to data out-of-bounds issues.
- On
Atlas inference products , this interface performs saturation calculation. When the data value exceeds the data type range, no wraparound occurs. OnAtlas 200I/500 A2 inference products , this interface is a non-saturation interface. - The shapes of the Tensors corresponding to the input and output parameters must be equal, the types must be consistent, and the dimensions must not exceed 4.
APP_ERROR Threshold(const Tensor &src, Tensor &dst, float thresh, float maxVal, const ThresholdType &thresholdType = ThresholdType::THRESHOLD_BINARY, AscendStream &stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src | Input | Tensor class, the input tensor. float16, float32, and uint8 inputs are supported. The data memory must be on the device or DVPP side. |
| dst | Output | Tensor class, the output tensor. The types float16, float32, and uint8 are supported. An empty Tensor can be passed in. If dst is not empty, its shape must be the same as that of src, memory must be allocated in advance by calling the Tensor.Malloc() interface, and the data memory must be on the device side (the same device as src) or the DVPP side. |
| thresh | Input | float type, the threshold for comparing src. |
| maxVal | Input | float type, the value set when src meets the condition after being compared with the threshold thresh. |
| thresholdType | Input | Enumeration type ThresholdType, representing the specific rule of threshold segmentation. Binarization and inverse binarization are currently supported (the default is binarization, that is, dst = maxVal (src>thresh) or 0 (src<= thresh). Inverse binarization is supported only on |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
ThresholdBinary
Image processing. Binarization interface of the Tensor class (that is, dst = maxVal (src>thresh) or 0 (src<= thresh)). float16, float32, and uint8 are supported. Asynchronous calls are supported.
This interface is expected to be officially discontinued in September 2025. You are advised to use Threshold.
Inplace operations are not supported.
Currently supported on
On
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- Pay attention to data out-of-bounds issues.
- On
Atlas inference products , this interface performs saturation calculation. When the data value exceeds the data type range, no wraparound occurs. OnAtlas 200I/500 A2 inference products , this interface is a non-saturation interface. - The shapes of the Tensors corresponding to the input and output parameters must be equal, the types must be consistent, and the dimensions must not exceed 4.
APP_ERROR ThresholdBinary(const Tensor &src, Tensor &dst, float thresh, float maxVal, AscendStream &stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src | Input | Tensor class, the input tensor. float16, float32, and uint8 inputs are supported. The data memory must be on the device or DVPP side. |
| dst | Output | Tensor class, the output tensor. The types float16, float32, and uint8 are supported. An empty Tensor can be passed in. If dst is not empty, its shape must be the same as that of src, memory must be allocated in advance by calling the Tensor.Malloc() interface, and the data memory must be on the device side (the same device as src) or the DVPP side. |
| thresh | Input | float type, the threshold for comparing src. |
| maxVal | Input | float type, the value set when src is greater than the threshold thresh. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Tile
Image processing. Tensor expansion interface of the Tensor class, which expands dimensions based on the input tensor and returns a new tensor. Asynchronous calls are supported, and preloading is supported (see Example of Initializing the Operator Preload File).
Currently supported only on
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- The types of the Tensors corresponding to the input and output parameters must be consistent, and the dimensions must not exceed 4.
APP_ERROR Tile(const Tensor &src, Tensor &dst, const std::vector<uint32_t> &multiples, AscendStream& stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src | Input | Tensor class. float16, float32, and uint8 inputs are supported. |
| multiples | Input | std::vector <uint32_t> class, the expansion multiples. The number of elements must be the same as the dimension of src. |
| dst | Output | Tensor class. float16, float32, and uint8 types are supported. An empty Tensor can be passed in. If dst is not an empty Tensor, memory must be allocated in advance by calling the Tensor.Malloc() interface. The shape of each dimension of dst is equal to the shape of the corresponding dimension of src multiplied by the expansion multiple of each axis. The shape obtained by multiplying each axis of src by the expansion multiple must be consistent with the output, and the expansion multiples cannot be 0. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Transpose
Image processing. Multi-dimensional transposition interface of the Tensor class, which transposes the tensor according to the given axes dimension arrangement. Asynchronous calls are supported.
Currently supported on
On
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- The types of the Tensors corresponding to the input and output parameters must be consistent, and the shape must not exceed 4 dimensions.
APP_ERROR Transpose(const Tensor &src, Tensor &dst, std::vector<int> axes, AscendStream &stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src | Input | Tensor class. float16, float32, and uint8 inputs are supported. |
| dst | Output | Tensor class. float16, float32, and uint8 outputs are supported. An empty Tensor can be passed in. If dst is not an empty Tensor, memory must be allocated in advance by calling the Tensor.Malloc() interface. The shape must be the shape of src after the axes are exchanged according to the axes rules. For example, if src is {1, 480, 640, 3} and the axes value is {0, 2, 1, 3}, the dst shape must be {1, 640, 480, 3}. |
| axes | Input | std::vector<int> class, specifying the arrangement of the transposition operation dimensions. The axes length must be the same as the dimension of the input Tensor. For example, if src is four-dimensional, the axes length must be 4. The elements in axes must include the numbers in the [0, size-1] range, and each number can appear only once. If an empty vector is passed in, transposition is performed in reverse order. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Vstack
Image processing algorithm. Vertical stacking operation of tensors. float16, float32, and uint8 are supported. Asynchronous calls are supported, and preloading is supported (see Example of Initializing the Operator Preload File).
Currently supported on
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- Pay attention to data type out-of-bounds issues.
- The shapes of the Tensors corresponding to the input and output parameters must be equal (except the "H" dimension), the types must be consistent, and the dimensions must not exceed 4.
- The total height of the input Tensors must be smaller than or equal to the maximum height of the Tensor type (the maximum value of the uint32 type).
- When the output Tensor is not empty, the output Tensor height must be equal to the total height of the input Tensors.
APP_ERROR Vstack(const std::vector <Tensor> &tv, Tensor &dst, AscendStream &stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| tv | Input | std::vector<Tensor> class, used to store the Tensors waiting to be concatenated. The Tensor supports float16, float32, and uint8 types. The data memory must be on the device side or the DVPP side. HW (2-dimensional), HWC (3-dimensional), and NHWC (4-dimensional) dimensions are supported, and the length of the tv tensor must be greater than 1 (at least 2 Tensors must be passed in). The length of tv is subject to the successful construction of the vector. The sum of the heights of the Tensors in tv must not exceed the maximum height of the Tensor class (the maximum value of uint32). |
| dst | Output | Tensor class, the output tensor and the concatenated Tensor. float16, float32, and uint8 are supported (must be consistent with tv). An empty Tensor can be passed in. If dst is not empty, its shape must be the same as that of tv, the "H" dimension (height) must be equal to the sum of the "H" of all Tensors in tv, memory must be allocated in advance by calling the Tensor.Malloc() interface, and the data memory must be on the device side (the same device as tv) or the DVPP side. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
WarpAffineHiper
Affine transformation interface, which scales, translates, and rotates a two-dimensional image. Asynchronous calls are supported.
Currently supported only on
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- The output tensor supports being an empty Tensor (when it is an empty Tensor, the default output shape is the same as the shape of the input tensor).
- When the input Tensor data type is Float32 or Uint8, the recommended size is 480P (640 × 480). In this case, the computing performance is better than that of cv::warpAffine on the CPU.
APP_ERROR WarpAffineHiper(const Tensor &src, Tensor &dst, const std::vector<std::vector<float>> transMatrix,const PaddingMode paddingMode, const float borderValue,const WarpAffineMode warpAffineMode, AscendStream& stream=AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src | Input | Tensor class, the input tensor and the tensor to be affine transformed. uint8, float16, and float32 types are supported. The NHWC (four-dimensional) dimension is required, where "N" (number of tensors) is [1,16] and "C" (number of channels) is [1,4]. The tensor width supports [32,2160], and the tensor height supports [32,3840]. The data memory must be on the device side or the DVPP side. An empty Tensor cannot be passed in. |
| dst | Output | Tensor class, the output tensor. If it is a non-empty Tensor, memory must be allocated in advance by calling the Tensor.Malloc() interface. The NHWC (four-dimensional) dimension is required. The data type, chip ID, "N" (number of tensors), and "C" (number of channels) must be the same as those of the input tensor. The tensor width supports [32,2160], and the tensor height supports [32,3840]. The data memory must be on the device side or the DVPP side. When it is an empty Tensor, the default output shape is the same as the shape of the input tensor. |
| transMatrix | Input | Transformation matrix. The size must be in the 2x3 format. The interface internally adds (0,0,1) to the third row to form a 3x3 matrix. The determinant value of this matrix cannot be 0. |
| paddingMode | Input | Enumeration value, corresponding to the padding mode. Currently, only constant value (that is, PADDING_CONST) is supported. For details, see PaddingMode. |
| borderValue | Input | Value of the padding. The value range is [0, 255]. |
| WarpAffineMode | Input | Enumeration value, corresponding to the interpolation mode. Currently, only bilinear interpolation (that is, INTER_LINEAR) is supported. For details, see WarpAffineMode. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
If the "Synchronize stream execution failed" error occurs when the WarpAffineHiper interface is run, see Synchronize stream execution failed when Running the WarpAffineHiper or WarpPerspective Interface to resolve the issue.
WarpPerspective
Perspective transformation interface, which projects a two-dimensional image onto a three-dimensional view plane and then converts it back to two-dimensional coordinates. Asynchronous calls are supported.
Currently supported only on
The following conditions must be met:
- The input and output Tensors of the interface must be on the device or DVPP side, and all parameters (stream and data memory) must reside on the same device.
- In the synchronous scenario, the device where the data memory resides must be the same as the initialized device.
- The output tensor width and height are determined by the actual result calculated from the input tensor and the transformation matrix. The output tensor supports being an empty Tensor (when it is an empty Tensor, the default output shape is the same as the shape of the input tensor).
- When the input Tensor data type is Float32 or Uint8, the recommended size is 480P (640 × 480). In this case, the computing performance is better than that of cv::warpPerspective on the CPU.
APP_ERROR WarpPerspective(const Tensor &src, Tensor &dst, const std::vector<std::vector<float>> transMatrix, const PaddingMode paddingMode, const float borderValue, const WarpPerspectiveMode warpPerspectiveMode, AscendStream &stream = AscendStream::DefaultStream());
| Parameter | Input/Output | Description |
|---|---|---|
| src | Input | Tensor class, the input tensor and the tensor to be perspective transformed. uint8, float16, and float32 types are supported. The NHWC (four-dimensional) dimension is supported, where "N" (number of tensors) is [1,16] and "C" (number of channels) is [1,4]. The tensor width supports [32,2160], and the tensor height supports [32,3840]. The data memory must be on the device side or the DVPP side. An empty Tensor cannot be passed in. |
| dst | Output | Tensor class, the output tensor. If it is a non-empty Tensor, memory must be allocated in advance by calling the Tensor.Malloc() interface. The NHWC (four-dimensional) dimension is supported, where "N" (number of tensors) is [1,16] and "C" (number of channels) is [1,4]. The tensor width and height are determined by the actual result calculated from the input tensor and the transformation matrix. The data memory must be on the device side or the DVPP side. The data type, chip ID, "N" (number of tensors), and "C" (number of channels) must be the same as those of the input tensor. An empty Tensor can be passed in (when it is an empty Tensor, the default output shape is the same as the shape of the input tensor). |
| transMatrix | Input | Transformation matrix. The size must be in the 3x3 format. The determinant value of this matrix is 0. |
| paddingMode | Input | Enumeration value, corresponding to the padding mode. Currently, only constant value (that is, PADDING_CONST) is supported. For details, see PaddingMode. |
| borderValue | Input | Value of the padding. The value range is [0, 255]. |
| warpPerspectiveMode | Input | Enumeration value, corresponding to the interpolation mode. Currently, only bilinear interpolation (that is, INTER_LINEAR) is supported. For details, see WarpPerspectiveMode. |
| stream | Input | AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the interface is a synchronous operation. In other cases, the interface is an asynchronous operation. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
If the "Synchronize stream execution failed" error occurs when the WarpPerspective interface is run, see Synchronize stream execution failed when Running the WarpAffineHiper or WarpPerspective Interface to resolve the issue.
Sift
Class Description
This class implements scale-invariant feature transform, used to detect and extract feature points with scale invariance and rotation invariance in images.
For the related usage process, see Feature Extraction.
DetectAndCompute
Extracts and computes image feature points.
APP_ERROR Sift::DetectAndCompute(Tensor _image, Rect _mask, std::vector<cv::KeyPoint> &keyPoints, cv::OutputArray descriptors, bool useProvidedKeyPoints);
| Parameter | Input/Output | Description |
|---|---|---|
| _image | Input | Tensor class, the input image for feature extraction. The Tensor supports the HWC (three-dimensional) dimension. It cannot be empty. The third dimension C (number of channels) is 1, and only a single channel is supported. Input image sizes of 1280 × 720 are supported. |
| _mask | Input | Rect class, the input image mask, used to limit the area where features need to be calculated. Feature extraction is performed on the image within this area. The mask rectangle frame represented by _mask must be placed within the image, and the top-left and bottom-right coordinates corresponding to the Rect class must be within the valid range of the image. |
| keyPoints | Input/Output | List of extracted feature points. |
| descriptors | Output | List of generated descriptors. |
| useProvidedKeyPoints | Input | Whether to provide a feature point list, that is, this function only generates descriptors. When the parameter is true, the interface generates the descriptor list based on the feature point list passed in through keyPoints. When the parameter is false, the interface extracts the feature point list based on the Sift algorithm and generates the descriptor list based on the list. |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Init
Initializes the model processing resources for scale space construction.
APP_ERROR Sift::Init(int32_t deviceId = 0);
| Parameter | Input/Output | Description |
|---|---|---|
| deviceId | Input | Chip ID where the model is deployed. The default value is 0. (Currently, only chip 0 is supported.) |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Sift
Constructor of the Sift class. As the implementation class of image scale-invariant feature transform, it mainly provides feature point extraction and computing interfaces. Currently, only the Atlas 200I A2 acceleration module (20 TOPS, 12GB) is supported.
explicit Sift::Sift(int nFeatures = 0, int nOctaveLayers = 3, double contrastThreshold = 0.04, double edgeThreshold = 10, double sigma = 1.6, int descriptorType = CV_32F);// If construction fails, a std::runtime_error exception is thrown
| Parameter | Input/Output | Description |
|---|---|---|
| nFeatures | Input | Ranking of extracted feature points, that is, the extracted feature points are sorted and the best top nFeatures (including ties) are returned. The default value is 0, indicating that all feature points are extracted. The number of recognized feature points is subject to the actual returned result. |
| nOctaveLayers | Input | Number of middle layers in each group of images in the scale space. The default value is 3. Currently, only the default value is supported. If other parameters are configured, the construction fails and a std::runtime_error exception is thrown. nOctaveLayers + 3 is the number of layers contained in each group of images in the Gaussian pyramid. nOctaveLayers + 2 is the number of layers contained in each group of images in the difference pyramid. |
| contrastThreshold | Input | Feature point filtering threshold. The default value is 0.04, and the value range is [0.0, 20.0]. |
| edgeThreshold | Input | Edge effect filtering threshold. The default value is 10, and the value range is [0.0, 1000.0]. |
| sigma | Input | Initial blur scale, the Gaussian filter coefficient of the image at layer 0 of the Gaussian pyramid. The default value is 1.6. Currently, only the default value is supported. If other parameters are configured, the construction fails and a std::runtime_error exception is thrown. |
| descriptorType | Input | Data type of the feature descriptors. The default value is CV_32F. The following data types are currently supported. CV_8U CV_32F |
Class Description
The VideoEncoder class is a video encoding class that mainly provides video encoding interfaces.
For the related usage process, see Video Encoding.
- The VideoEncoder class involves applying for device-side resources, which conflicts with the scope of MxDeInit. Therefore, its scope cannot be greater than or equal to the scope of MxDeInit.
- During encoder runtime, a frame may fail to be encoded because frames are sent too frequently or the chip processing speed is exceeded. You are advised to reasonably control the frequency of calling the
Encodeinterface. For example, when the encoding frame rate is 30 fps, the interval betweenEncodeinterface calls can be controlled to 33 ms. - When a frame fails to be encoded, the encoder continues to process subsequent frame data. You can perceive that the encoding result of this frame has not been obtained through information such as the frame ID in the callback function.
Encode
Video encoding interface of VideoEncoder.
APP_ERROR VideoEncoder::Encode(const Image &inputImage, const uint32_t frameId, void* userData);
| Parameter | Input/Output | Description |
|---|---|---|
| inputImage | Input | Image class before encoding. |
| frameId | Input | Index of the video frame. |
| userData | Input/Output | User-defined data (passed into the user-defined callback function, mainly used to obtain the encoding result). |
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
VideoEncoder
Constructor of the VideoEncoder class. If the construction fails due to insufficient memory or failure to identify the chip, a std::runtime_error exception is thrown.
VideoEncoder::VideoEncoder(const VideoEncodeConfig& vEncodeConfig, const int32_t deviceId = 0, const uint32_t channelId = 0);
| Parameter | Input/Output | Description |
|---|---|---|
| vEncodeConfig | Input | Video encoding parameters (passed in as a structure). For the parameter description of the structure, see VideoEncodeConfig. |
| deviceId | Input | Chip on which the video encoder is deployed. The default value is chip 0. Value range: [0, the number of recognized chips - 1]. |
| channelId | Input | Video stream index of the video encoder.channelId. Repeated construction causes failure. |
~VideoEncoder
Default destructor of the VideoEncoder class.
VideoEncoder::~VideoEncoder();Class Description
The VideoDecoder class is a video decoding class that mainly provides video decoding interfaces.
In the scenario where pre-allocated decoding memory is passed in, you need to destroy the VideoDecoder class first, and then release the pre-allocated memory (you are advised to use a smart pointer to manage VideoDecoder. The reset method of the smart pointer can destroy it in advance).
For the related usage process, see Video Decoding.
The VideoDecoder class involves applying for device-side resources, which conflicts with the scope of MxDeInit. Therefore, its scope cannot be greater than or equal to the scope of MxDeInit.
Decode
Video decoding interface of VideoDecoder.
When an instantiated decoder calls the Decode interface for the first time, it determines whether it is a pre-allocation scenario. In the pre-allocation scenario, you need to call the Decode interface subsequently to pre-allocate output memory, preventing interface call failures.
APP_ERROR VideoDecoder::Decode(const std::shared_ptr<uint8_t> data, const uint32_t dataSize, const uint32_t frameId, void* userData);APP_ERROR VideoDecoder::Decode(const std::shared_ptr<uint8_t> data, const uint32_t dataSize, const uint32_t frameId, Image& preMallocData, void* userData);
| Parameter | Input/Output | Description |
|---|---|---|
| data | Input | Memory address of the data before decoding. |
| dataSize | Input | Memory size of the data before decoding. |
| frameId | Input | Frame ID of the video frame before decoding. The output frame order may not be consistent with the sending order. |
| userData | Input/Output | User-defined data (passed into the user-defined callback function, mainly used to obtain the decoding result). |
| preMallocData | Input | In the pre-allocation scenario, you need to construct an Image class using the allocated memory address, memory size, image width and height, device ID, and image format. |
The frameId is output in display order, which is different from the decoding order (in the decoding order, the output frame order is consistent with the sending order). The output frame order may not be consistent with the sending order, but it is consistent with the actual display of the picture.
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
Flush
After all bitstreams are sent, obtains the cached data and clears the cache queue. After the interface call is complete, the decoding process ends.
Because video decoding is implemented asynchronously internally, retain a certain waiting time after using this interface so that the callback function can obtain and process the cached data.
APP_ERROR VideoDecoder::Flush();
| Data Structure | Description |
|---|---|
| APP_ERROR | Error code returned by the program execution. See APP_ERROR description. |
VideoDecoder
Constructor of the VideoDecoder class. If the construction fails due to insufficient memory or failure to identify the chip, a std::runtime_error exception is thrown.
VideoDecoder::VideoDecoder(const VideoDecodeConfig& vDecodeConfig, const int32_t deviceId = 0, const uint32_t channelId = 0);
| Parameter | Input/Output | Description |
|---|---|---|
| vDecodeConfig | Input | Video decoding parameters (passed in as a structure). |
| deviceId | Input | Chip on which the video decoder is deployed. The default value is chip 0. Value range: [0, the number of recognized chips - 1]. |
| channelId | Input | Video stream index of the video decoder.channelId is constructed repeatedly, the construction fails.channelId is constructed repeatedly, the channelId is automatically adjusted.channelId is constructed repeatedly, the channelId is automatically adjusted. Note that the total number of concurrently occupied video decoding channels is at most 32. When the limit is exceeded, creating a new channel fails. |
~VideoDecoder
Default destructor of the VideoDecoder class.
VideoDecoder::~VideoDecoder();

