Nobody will be able to decipher what your code does in some time. At the moment it's not easier than reading the OpenCV implementation. Use more descriptive variable names (o_m, o_set... ???), add more comments (explain what you do in the loop), add doc strings for all functions (even the internal Cython functions).