Skip to content

ximgproc: run the RICInterpolator model passes one after another - #4261

Merged
asmorkalov merged 2 commits into
opencv:4.xfrom
pctablet505:fix-ximgproc-ric-propagate-race
Nov 3, 2026
Merged

asmorkalov merged 2 commits into
opencv:4.xfrom
pctablet505:fix-ximgproc-ric-propagate-race

Conversation

@pctablet505

@pctablet505 pctablet505 commented Nov 1, 2026 •

Copy link
Copy Markdown

Resolves #4260

RICInterpolator::interpolate() returns a different flow on every run when OpenCV uses several threads, and sometimes one far from the reference. PropagateModels() ran its model passes in parallel although each pass builds on the previous one. They now run one after another.

Problem

PropagateModels() ran its iterCnt passes with parallel_for_. Each pass improves the models that the previous pass left in outModels, inLierFlag and bestCost, and all passes share tmpModel and tmpInlierFlag, so on several threads the passes overwrite each other. This is why RICReferenceAccuracy fails now and then, including in the Ubuntu2404-ARM64-FastCV CI job of #4257, which does not touch ximgproc.

Changes

  • Run the passes in a plain for loop. On one thread they run in the same order as before.
  • New test InterpolatorTest.RICSameResultOnAnyNumberOfThreads: three runs on 4 threads must each match the flow on 1 thread within 0.01 pixel. The limit is not zero because, with the fix, the two flows still differ by about 5e-6 pixel.

Tests (x86-64, 32 threads)

4.x with the fix
new test fails 200 of 200 runs passes 200 of 200
RICReferenceAccuracy 13 failures in 1000 runs 0 in 2000
RICReferenceAccuracy time 148 ms 160 ms

All 473 ximgproc tests pass. The cost is about 8% on 32 threads, because the passes no longer overlap. I could not test on ARM64 or with ThreadSanitizer.

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

PropagateModels() ran its passes with parallel_for_, but every pass starts from
the models the previous pass left in outModels, inLierFlag and bestCost, and all
passes share tmpModel and tmpInlierFlag. On more than one thread the passes
overwrote each other's data, so the flow changed from run to run and was
sometimes far off. InterpolatorTest.RICReferenceAccuracy failed at random
because of it.

Run the passes in a plain loop. The new test RICSameResultOnAnyNumberOfThreads
compares the flow on one thread with the flow on four.

Fixes opencv#4260
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