mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 15:23:05 +04:00
da11697f8ce7f7168a35cac1c65ed1a7ce21c69a
## Summary Replace the existing RVV HAL FAST-16 implementation (`hal/riscv-rvv/src/features2d/fast.cpp`) with a score-first approach, achieving **2-4x speedup** over the previous HAL implementation on RISC-V hardware. ## Approach The previous HAL implementation used a count-based approach (XOR trick + per-pixel bitmask scanning + separate cornerScore computation). This PR replaces it with a **score-first** approach that processes multiple horizontal pixels in parallel using RVV vectors. Key optimizations: 1. **Score-first approach**: Directly compute corner scores via min/max reduction over all 9-arc windows, then threshold on score. This eliminates the arc-counting pass and the separate `cornerScore` function. 2. **u8 to i16 zero-extension**: Zero-extend pixel values to int16 for natural signed comparison, eliminating the XOR-delta trick and preventing score overflow. 3. **vcompress batch output**: Extract all corner indices in one vector operation instead of per-lane bitmask scanning. 4. **vlen-adaptive**: Uses `vsetvl_e16m1` for dynamic vector length — works on any RVV 1.0 implementation regardless of VLEN (128, 256, 512, etc.) without code changes. ## Performance Benchmarked by maintainer on **Muse Pi v3.0** (GCC, SpacemiT toolchain v1.0.4): | Test | Previous HAL (ms) | This PR (ms) | Speedup | |------|-------------------|--------------|---------| | FAST-20 NMS=true | 23.06 | 7.99 | **2.89x** | | FAST-20 NMS=true (orig) | 7.31 | 1.80 | **4.06x** | | FAST-30 NMS=false | 20.10 | 7.75 | **2.59x** | | FAST_DEFAULT s2.jpg | 76.94 | 19.06 | **4.04x** | | ORB_DEFAULT chess9 | 64.46 | 25.43 | **2.53x** | Both NMS=true and NMS=false cases are supported. ## Files Changed - **`hal/riscv-rvv/src/features2d/fast.cpp`**: Replaced count-based implementation with score-first approach - No changes to `modules/features2d/src/fast.cpp` or any other files ## Test Plan - [x] Built with RISC-V cross-compilation toolchain (GCC 14.2, RVV 1.0) - [x] Tested on QEMU (rv64, v=true, vlen=256) — correct results for both NMS modes - [x] Maintainer tested on Muse Pi v3.0 hardware — 2-4x speedup confirmed - [ ] CI passes on all platforms
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.1%
Python
2.9%
CMake
2%
Java
1.5%
Other
2.7%