mirror of
https://github.com/opencv/opencv.git
synced 2026-07-21 19:33:03 +04:00
666ad5bfcf2d93a4cc5d3f8d77e58c615ec71f17
RISC-V: add RVV convertScale paths for selected depth conversions #29058 ### Summary This PR extends the RISC-V RVV HAL `convertScale` implementation with optimized paths for selected `convertTo()` depth conversions: - `CV_32F -> CV_8U` - `CV_16U -> CV_32F` - `CV_16S -> CV_32F` The change is confined to `hal/riscv-rvv/src/core/convert_scale.cpp`. It does not modify the generic `convertTo()` implementation or affect dispatch for non-RISC-V targets. ### Rationale `Mat::convertTo()` reaches architecture-specific implementations through the HAL `convertScale` interface. Adding these paths in the RVV HAL keeps the optimization in the existing backend layer and avoids introducing RISC-V-specific branches into common OpenCV code. The selected conversions were chosen based on measured benefit and practical relevance. `CV_32F -> CV_8U` provides the largest speedup, while `CV_16U -> CV_32F` and `CV_16S -> CV_32F` provide consistent improvements for common image-processing data paths. ### Benchmark Tested on Banana Pi BPI-F3, an 8-core RISC-V board with RVV 1.0 support. Build and test configuration: - OpenCV `4.14.0-pre` - Release build - RVV HAL enabled - Compiler: `riscv64-unknown-linux-gnu-g++ 14.2.1` - Test binary: `opencv_perf_core` - Test filter: `*convertTo*` - Samples: `--perf_force_samples=20 --perf_min_samples=20` Benchmark command: ```bash ./opencv_perf_core \ --gtest_filter=*convertTo* \ --perf_force_samples=20 \ --perf_min_samples=20 ``` Each benchmark case was measured with 20 forced samples. The baseline/after comparison was repeated to check run-to-run stability. The optimized conversion pairs showed consistent improvements. Second-run comparison for the optimized pairs: ```text OPTIMIZED_PAIRS: 24 cases, gmean 2.6009x CV_32F -> CV_8U: 16.0718x CV_16U -> CV_32F: 1.2334x CV_16S -> CV_32F: 1.1376x ``` `CV_32F -> CV_8U` showed the largest improvement, with speedups in the `14.5x` to `18.8x` range across the tested image sizes, channel counts, and alpha values. ### Notes on Measurement The initial benchmark run showed noise in conversion pairs not touched by this PR, likely due to board-level variance such as frequency scaling, thermal state, or background scheduling. A second run showed untouched pairs close to neutral: ```text UNTOUCHED_OTHER: gmean 0.9941x ``` The optimized conversion pairs remained consistently faster across both runs, with no observed regression in the added RVV paths. ### 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 - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake
OpenCV: Open Source Computer Vision Library
Resources
- Homepage: https://opencv.org
- Courses: https://opencv.org/courses
- Docs: https://docs.opencv.org/4.x/
- Q&A forum: https://forum.opencv.org
- previous forum (read only): http://answers.opencv.org
- Issue tracking: https://github.com/opencv/opencv/issues
- Additional OpenCV functionality: https://github.com/opencv/opencv_contrib
- Donate to OpenCV: https://opencv.org/support/
Contributing
Please read the contribution guidelines before starting work on a pull request.
Summary of the guidelines:
- One pull request per issue;
- Choose the right base branch;
- Include tests and documentation;
- Clean up "oops" commits before submitting;
- Follow the coding style guide.
Additional Resources
- Submit your OpenCV-based project for inclusion in Community Friday on opencv.org
- Subscribe to the OpenCV YouTube Channel featuring OpenCV Live, an hour-long streaming show
- Follow OpenCV on LinkedIn for daily posts showing the state-of-the-art in computer vision & AI
- Apply to be an OpenCV Volunteer to help organize events and online campaigns as well as amplify them
- Follow OpenCV on Mastodon in the Fediverse
- Follow OpenCV on Twitter
- OpenCV.ai: Computer Vision and AI development services from the OpenCV team.
Description
Languages
C++
87.6%
C
3.2%
Python
2.9%
CMake
2%
Java
1.5%
Other
2.6%