ParetoStackpareto-stackdocshpc-labs

OpenCV rules

OpenCV-heavy Python code often repeats work that does not need repeating, or hand-writes a loop that OpenCV already has a function for. ParetoStack has four rules for this, covering a large catalog of OpenCV functions. Each one is applied to a staged copy only, guarded at run time, and verified like every other change: identical output, or an accuracy contract you accept where noted.

Rule What it does for you Output
cv_hoist Builds OpenCV helper objects (kernels, matrices, detectors, classifiers) once instead of on every pass of a loop. identical
cv_cse Does the same OpenCV computation on the same image once instead of on every pass. identical
cv_loops Replaces a hand-written per-pixel loop with the OpenCV function that does the same job. identical
cv_approx The same, where OpenCV rounds slightly differently from the hand-written loop. within a declared contract

The rules are checked against real OpenCV, on 4.13 and on 5.0.0: the rewritten code must give the same results, bit for bit, wherever the rule says identical. paretostack opencv-rules prints the full list that your installed version knows.