mirror of
https://github.com/opencv/opencv.git
synced 2026-11-23 17:57:56 -06:00
Add a calcHistRunParallel wrapper that splits the input image across threads, each accumulating into a private histogram, then sums the local copies at the end. This avoids atomic contention on shared bins. The thread count follows the suggestion from PR #28635 review: - if N < 256K elements, use a single thread - otherwise nstripes = clamp(cvRound(N*0.001/M), 1, 8), where M is the total number of histogram bins - nstripes is further capped by getNumThreads(), so setNumThreads(0) and setNumThreads(1) keep the single-histogram path This keeps large histograms (e.g. 2D 256x256) single-threaded to avoid excessive memory, while small histograms (e.g. 1D 256 bins) on large images get up to 8x parallelism. Performance (1920x1080, 8 threads, median of 20 runs): - 8U 1D: 0.62ms -> 0.17ms (3.7x) - 16U 1D: 3.81ms -> 0.95ms (4.0x) - 32F 1D: 3.62ms -> 0.37ms (9.7x) Adds a parameterized consistency test verifying that results match a row-by-row single-threaded baseline bit-exactly across 8U/16U/32F, 1D-3D and various image sizes. Both stripe-splitting branches are covered: a non-contiguous ROI takes the row-split path, a contiguous clone takes the column-split path. A 1D mask bypasses IPP/HAL.