cv2.findTransformECC() (sometimes) missing defaults

It seems there might be a confusion among developers with allowing default parameters in the rather incredibly useful function cv2.findTransformECC(). (This has been going on since at least 2017.)

This function can automatically create an affine and even a perspective-distorting transform (a warp) between two images which can then be applied using cv2.warpPerspective() or cv2.warpAffine() to make them the same. (See Learn openCV: Image Alignment (ECC) in OpenCV ( C++ / Python ) for an excellent example.

The problem is that in several older versions of openCV and the version I’m currently using ‘4.5.1’ under Windows 10 Python 3.7.0 fails when the documented ‘optional’ arguments 6 or 7 are missing.
When both arguments 6 and 7 are missing (as shown in nearly every example instantiation), this error is thrown:

TypeError: findTransformECC() missing required argument ‘inputMask’ (pos 6)

When argument 7 is missing this error is thrown:

TypeError: findTransformECC() missing required argument ‘gaussFiltSize’ (pos 7)

The help() documentation shows:


inputMask An optional mask to indicate valid values of inputImage.
gaussFiltSize An optional value indicating size of gaussian blur filter; (DEFAULT: 5)

Note that the help (or the documentation) does not specify a default for inputMask. Specifying None will satisfy this argument.
The default (which sometimes isn’t applied if the argument 7 is missing) is specified as 5, and applying an odd integer value here will satisfy.

Example:

(correlationCoefficient, warp_matrix) = cv2.findTransformECC(img0, img1, warp_matrix, warp_mode, tform_termination_criterial_list, None, 15)

Good luck, and happy warping!

-Jim

1 Like

Hi,
You can post an issue

(correlationCoefficient, warp_matrix) = cv2.findTransformECC(img0, img1, warp_matrix, warp_mode, tform_termination_criterial_list, inputMask=None, gaussFiltSize=15)

If u’re encountered problem in postion 6. U can remove inputMask=

I wrote a PR (two characters)
It is merged now. You can build opencv and python binding yourself using cmake or wait for next opencv python release.

1 Like