Skip to content

Add RISC-V HAL implementation for cv::moments#27096

Merged
asmorkalov merged 1 commit intoopencv:4.xfrom
amane-ame:moments_hal_rvv
Mar 20, 2025
Merged

Add RISC-V HAL implementation for cv::moments#27096
asmorkalov merged 1 commit intoopencv:4.xfrom
amane-ame:moments_hal_rvv

Conversation

@amane-ame
Copy link
Copy Markdown
Contributor

This patch implements cv_hal_imageMoments using native intrinsics, optimizing the performance of cv::moments for data types CV_16U/CV_16S/CV_32F/CV_64F.

Tested on MUSE-PI (Spacemit X60) for both gcc 14.2 and clang 20.0.

$ ./opencv_test_imgproc --gtest_filter="*Moments*"
$ ./opencv_perf_imgproc --gtest_filter="*Moments*" --perf_min_samples=1000 --perf_force_samples=1000

image

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • 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
  • 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

Co-authored-by: Liutong HAN <liutong2020@iscas.ac.cn>
@asmorkalov
Copy link
Copy Markdown
Contributor

My perf results for Muse Pi v 30 (gcc 14.2):

Moments1::MomentsFixture_val::(127x61, CV_16S, false) 	0.046 	0.038 	1.21
Moments1::MomentsFixture_val::(127x61, CV_16S, true) 	0.105 	0.032 	3.28
Moments1::MomentsFixture_val::(127x61, CV_16U, false) 	0.046 	0.038 	1.21
Moments1::MomentsFixture_val::(127x61, CV_16U, true) 	0.105 	0.032 	3.26
Moments1::MomentsFixture_val::(127x61, CV_32F, false) 	0.093 	0.052 	1.78
Moments1::MomentsFixture_val::(127x61, CV_32F, true) 	0.123 	0.037 	3.34
Moments1::MomentsFixture_val::(127x61, CV_64F, false) 	0.080 	0.045 	1.79
Moments1::MomentsFixture_val::(127x61, CV_64F, true) 	0.140 	0.058 	2.40
Moments1::MomentsFixture_val::(640x480, CV_16S, false) 	1.867 	0.415 	4.50
Moments1::MomentsFixture_val::(640x480, CV_16S, true) 	4.238 	0.349 	12.13
Moments1::MomentsFixture_val::(640x480, CV_16U, false) 	1.891 	0.416 	4.55
Moments1::MomentsFixture_val::(640x480, CV_16U, true) 	4.188 	0.362 	11.57
Moments1::MomentsFixture_val::(640x480, CV_32F, false) 	3.708 	0.579 	6.40
Moments1::MomentsFixture_val::(640x480, CV_32F, true) 	4.842 	0.419 	11.55
Moments1::MomentsFixture_val::(640x480, CV_64F, false) 	5.595 	1.220 	4.59
Moments1::MomentsFixture_val::(640x480, CV_64F, true) 	7.863 	1.342 	5.86
Moments1::MomentsFixture_val::(1280x720, CV_16S, false) 	10.886 	1.845 	5.90
Moments1::MomentsFixture_val::(1280x720, CV_16S, true) 	14.358 	1.666 	8.62
Moments1::MomentsFixture_val::(1280x720, CV_16U, false) 	10.935 	1.824 	5.99
Moments1::MomentsFixture_val::(1280x720, CV_16U, true) 	14.547 	1.666 	8.73
Moments1::MomentsFixture_val::(1280x720, CV_32F, false) 	19.416 	2.889 	6.72
Moments1::MomentsFixture_val::(1280x720, CV_32F, true) 	22.858 	2.573 	8.88
Moments1::MomentsFixture_val::(1280x720, CV_64F, false) 	16.026 	4.016 	3.99
Moments1::MomentsFixture_val::(1280x720, CV_64F, true) 	27.478 	4.482 	6.13
Moments1::MomentsFixture_val::(1920x1080, CV_16S, false) 	25.859 	4.188 	6.18
Moments1::MomentsFixture_val::(1920x1080, CV_16S, true) 	42.074 	3.813 	11.03
Moments1::MomentsFixture_val::(1920x1080, CV_16U, false) 	25.907 	4.241 	6.11
Moments1::MomentsFixture_val::(1920x1080, CV_16U, true) 	42.115 	3.811 	11.05
Moments1::MomentsFixture_val::(1920x1080, CV_32F, false) 	49.898 	6.746 	7.40
Moments1::MomentsFixture_val::(1920x1080, CV_32F, true) 	57.286 	6.083 	9.42
Moments1::MomentsFixture_val::(1920x1080, CV_64F, false) 	30.765 	7.795 	3.95
Moments1::MomentsFixture_val::(1920x1080, CV_64F, true) 	71.333 	8.220 	8.68 

@asmorkalov asmorkalov self-assigned this Mar 19, 2025
@asmorkalov
Copy link
Copy Markdown
Contributor

@mshabunin @fengyuentau Do you have any comments?

@asmorkalov asmorkalov merged commit 46fbe18 into opencv:4.x Mar 20, 2025
26 of 28 checks passed
@asmorkalov asmorkalov mentioned this pull request Apr 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants