Add additional image processing operators for Ascend NPU by utilizing DVPP #3608
The user base for [Ascend NPU](https://www.hiascend.com/en/) and programming with CANN is increasing rapidly, with a growing number of users joining each day. To facilitate the use of these users, this PR provides more support for Ascend backend operators. All operators this PR offers are using use DVPP as the computational unit. Digital Vision Pre-Processing (DVPP) is an image processing unit built into the Ascend AI processor. Its main functions include image and video encoding/decoding, as well as image cropping and scaling.
The high-frequency operators with NPU as the backend and basic data structure AscendMat has been provided in #3552, while it still lacks many image processing operators. Moreover, only two interpolation algorithms for the resize operator are supported in #3552. In this PR, the bilinear interpolation algorithm and nearest neighbour interpolation algorithm are implemented for the resize operator, as well as the Ascend implementation of the copyMakeBorder operator.
In addition, the serialization of image processing operations is widely used in the preprocessing and post-processing stages of computer vision deep learning methods. Therefore, providing integrated operators is very meaningful for improving the convenience of use for OpenCV and deep learning crossover users. For example, torchvision also provides similar operators: [RESIZED_CROP](https://pytorch.org/vision/stable/generated/torchvision.transforms.functional.resized_crop.html?highlight=resizedcrop).
Thus, this PR also provides two serialization processing operators: cropResize and cropResizeMakeBorder.
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [N/A] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
AscendC is an extended syntax for the C/C++ language that can be used to
write operators that run on Ascend NPU.
This commit introduce an operator(threshold) written in AscendC. Others
can refer to this to implement other operators.
AscendC can implement efficient fusion operators according to needs, in
this case, threshold execution speed increased by nearly 4 times.
Co-authored-by: CaoMengqing <cmq0113@163.com>
CANN (Compute Architecture of Neural Networks), developped by Huawei, is
a heterogeneous computing architecture for AI. Opencv DNN has already
suppoted CANN backend [#22634](https://github.com/opencv/opencv/pull/22634).
There are more and more users using [Ascend NPU](https://www.hiascend.com/)
and programming with CANN, and the number is still growing rapidly.
AI training and inference are inseparable from data preprocessing.
When users use OpenCV to work with CANN backend, data preprocessing can
only run on CPUs, resulting in inefficiency.
The purpose of this commit is to enable OpenCV operators on CANN backend.
The usage of CANN backend is consistent, Please refer to OpenCV DNN: [CANN backend manual]
(https://gist.github.com/fengyuentau/083f7f339592545c1f1d2c1fde6a53dc#file-a_ocv_cann-md):
1. [Install dependencies]
(https://gist.github.com/fengyuentau/083f7f339592545c1f1d2c1fde6a53dc#install-dependencies)
2. [Install CANN]
(https://gist.github.com/fengyuentau/083f7f339592545c1f1d2c1fde6a53dc#install-cann)
3. [Compile OpenCV with CANN]
(https://gist.github.com/fengyuentau/083f7f339592545c1f1d2c1fde6a53dc#build-opencv-with-cann)
The CANN backend is used in a similar way to CUDA:
| Object | CANN | CUDA |
| --------- | ------------ | -------- |
| Namespace | cv::cann | cv::cuda |
| Matrix | AscendMat | GpuMat |
| Stream | AscendStream | Stream |
| Event | AscendEvent | Event |
The current commit provides CANN backend operator support framework, In
order to make code viewing easy, only a few basic interfaces are
implemented, all of the following operators are tested and compared
result with CPU backend.
More operators will continue implement in new independent commits.
Co-authored-by: CaoMengqing <cmq0113@163.com>