OpenCV
4.9.0
Open Source Computer Vision
|
In this guide, you will gain insights into the thread safety of Ascend operators already in use, as well as discover how to effectively employ Ascend operators for image preprocessing and understand their usage limitations.
We provide a suite of common matrix operation operators that support the Ascend NPU within OpenCV. For user convenience, the new 'AscendMat' structure and its associated operators maintain compatibility with the 'Mat' interface in OpenCV. These operators encompass a wide range of frequently used functions, including arithmetic operations, image processing operations, and image color space conversion. All of these operators are implemented utilizing CANN(Compute Architecture of Neural Networks). The Ascend operator facilitates accelerated operations on the NPU by making use of CANN. This acceleration effect is particularly noticeable when working with larger images, such as those with dimensions like 2048x2048, 3840x2160, 7680x4320, etc.
Our stream function is implemented by invoking the CANN operators. In the same stream, tasks are executed sequentially, while across different streams, tasks are executed in parallel. The use of event mechanisms ensures synchronization of tasks between streams, please refer to the Stream Management documentation for details.
In this section, you will discover how to use Ascend operators for image preprocessing, including functions below:
Input Image
Setup CANN
Image Preprocessing Example
Tear down CANN
Results
The original RGB input image with dimensions of (480, 640, 3):
After introducing Gaussian noise, we obtain the following result:
When applying the rotate operation with a rotation code of 0 (90 degrees clockwise), we obtain this result:
Upon applying the flip operation with a flip code of 0 (flipping around the x-axis), we achieve the final result:
While Ascend supports most commonly used operators, there are still some limitations that need to be addressed.
Operator | Supported Dtype |
---|---|
multiply (with scale) | float16,float32,int32 |
divide (with scale) | float16,float,int32,int8,uint8 |
bitwise add/or/xor/not | int32,int16,uint16 |
flip | float16,float,int64,int32,int16,uint16 |
transpose | float16,float,int64,int32,int16,int8,uint64,uint32,uint16,uint8,bool |
rotate | float16,float,int64,int32,int16,uint16 |