Skip to content

ximgproc: move accumulate functions from imgproc - #4155

Open
JArmandoAnaya wants to merge 2 commits into
opencv:5.xfrom
JArmandoAnaya:move-accumulate-to-ximgproc
Open

ximgproc: move accumulate functions from imgproc#4155
JArmandoAnaya wants to merge 2 commits into
opencv:5.xfrom
JArmandoAnaya:move-accumulate-to-ximgproc

Conversation

@JArmandoAnaya

@JArmandoAnaya JArmandoAnaya commented Jun 20, 2026

Copy link
Copy Markdown

This adds accumulate, accumulateSquare, accumulateProduct and accumulateWeighted to the ximgproc module, as part of the imgproc cleanup in opencv/opencv#25001. These accumulator functions are rarely used and are largely covered by core arithmetic (accumulate and accumulateWeighted by add and addWeighted, the other two by multiply and add), so they are a good fit for opencv_contrib rather than the base imgproc module.

The change comes in two commits. The first is a faithful move of the implementation from imgproc, keeping the dispatched SIMD kernel, the OpenCL kernel and the IPP paths intact; the only differences are the namespace
(cv::ximgproc) and the OpenCL kernel source reference (ocl::ximgproc::accumulate_oclsrc). The second commit applies C++17 style to the portable code paths (using-aliases instead of function-pointer typedefs, reinterpret_cast for the dispatch tables, and nullptr), leaving the IPP integration untouched.

The functions keep their existing signatures and behavior under the new cv::ximgproc namespace. The accuracy and performance tests move with them: the CPU accuracy test that previously lived in the opencv video module and the OpenCL accuracy test from imgproc are combined into a single ximgproc test, and the CPU and OpenCL performance tests are brought over as well. The tests are self-contained and generate their own input, so no opencv_extra data is required.

Part of opencv/opencv#25001.

This is one half of a linked pair and is meant to be merged together with the opencv PR that removes the functions from imgproc, so they are never defined in both modules at once:

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

accumulate, accumulateSquare, accumulateProduct and accumulateWeighted
move out of imgproc into the ximgproc module of opencv_contrib as part of
the imgproc cleanup (opencv/opencv#25001). These accumulator functions are
rarely used and are largely covered by core arithmetic: accumulate and
accumulateWeighted by add and addWeighted, the other two by a combination
of multiply and add. No other module depends on them.

This is a faithful move of the implementation (including the dispatched
SIMD kernel, the OpenCL kernel and the IPP paths), the public declarations,
and the accuracy and performance tests. The only change to the code is the
namespace (cv::ximgproc) and the OpenCL kernel source reference
(ocl::ximgproc::accumulate_oclsrc). The CPU accuracy test, previously housed
in the video module, and the OpenCL accuracy test from imgproc are combined
into a single ximgproc test.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Moves OpenCV’s accumulator routines (accumulate*) out of the base imgproc module into opencv_contrib’s ximgproc as part of the ongoing imgproc cleanup (linked to opencv/opencv#25001), preserving CPU SIMD dispatch, OpenCL, and IPP fast paths while updating tests/perf coverage under the new namespace.

Changes:

  • Adds cv::ximgproc::{accumulate, accumulateSquare, accumulateProduct, accumulateWeighted} implementation with CPU dispatch + OpenCL kernels.
  • Introduces a new public header (opencv2/ximgproc/accumulate.hpp) and wires it into opencv2/ximgproc.hpp.
  • Moves/creates accuracy + performance tests for both CPU and OpenCL in the ximgproc module.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
modules/ximgproc/test/test_accumulate.cpp Adds combined CPU + OpenCL accuracy tests for the moved accumulator functions.
modules/ximgproc/src/opencl/accumulate.cl Adds OpenCL kernels for all four accumulation operations (incl. masked variants).
modules/ximgproc/src/accum.simd.hpp Adds SIMD + portable CPU implementations and dispatch glue declarations.
modules/ximgproc/src/accum.dispatch.cpp Adds the CPU dispatch entry points for the dispatched SIMD implementations.
modules/ximgproc/src/accum.cpp Adds the main ximgproc implementations, including OpenCL + IPP paths and dispatch tables.
modules/ximgproc/perf/perf_accumulate.cpp Adds CPU + OpenCL perf coverage for the accumulator functions under ximgproc.
modules/ximgproc/include/opencv2/ximgproc/accumulate.hpp Adds the public API declarations and documentation for the moved functions.
modules/ximgproc/include/opencv2/ximgproc.hpp Exposes the new accumulate header from the umbrella ximgproc header.
modules/ximgproc/CMakeLists.txt Registers the new dispatched “accum” compilation unit for SIMD dispatch builds.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread modules/ximgproc/test/test_accumulate.cpp Outdated
Comment thread modules/ximgproc/perf/perf_accumulate.cpp
Comment thread modules/ximgproc/include/opencv2/ximgproc/accumulate.hpp
Comment thread modules/ximgproc/include/opencv2/ximgproc/accumulate.hpp
Comment thread modules/ximgproc/include/opencv2/ximgproc/accumulate.hpp
Comment thread modules/ximgproc/src/accum.dispatch.cpp Outdated
Apply C++17 style to the portable code paths of the moved accumulate
implementation: replace the function-pointer typedefs with using-aliases,
use reinterpret_cast for the dispatch-table entries instead of C-style
casts, and use nullptr in place of the 0 and NULL pointer literals. Behavior
is unchanged. The IPP integration paths are left in their original form.

Also fix two small issues carried over with the move: the closing namespace
comment in accum.dispatch.cpp read cv::hal although the file opens namespace
cv, and the OpenCL accumulateWeighted mask test did not pass the mask, so it
duplicated the non-masked case; it now exercises the masked path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants