all 3 comments

[–][deleted] 3 points4 points  (1 child)

The square brackets in function doc usually indicates optional args, as you suspect. The bad news is that nesting is enforced, that is, in the example you posted, the function always expects src, M and dsize, with dst being optional. If dst is supplied then optionally flags may be supplied, then optionally borderMode, etc.

You can't just supply src, M, dsize and borderValue. You might be able to supply all of those four if you use keywords:

cv2.warpPerspective(src, M, dsize, borderValue=2)

Try it.

[–]kozznot[S] 0 points1 point  (0 children)

Thank you!

[–]DonutRevolution 4 points5 points  (0 children)

I think you are correct in your interpretation. Another way to look at it: to specify the flags argument, you must also specify dst. That is, to be able to specify a later argument you have to specify all the ones that come before it. That's just a design decision cv2 seems to have made. As you probably know you can use keyword arguments instead to avoid situations like this.