2

I'm trying to understand the syntax on the OpenCV documentation... For example, any function shows the Python implementation in a similar form, such as:

dst =   cv.boxFilter(   src, ddepth, ksize[, dst[, anchor[, normalize[, borderType]]]]  )

Is ksize, dst, anchor, etc optional parameters? Why are they all nested? (e.g. why is borderType inside the normalize brackets, normalize inside the anchor brackets, etc.?) What is that supposed to imply?

1 Answer 1

2

The arguments outside of brackets are all required. Each subsequent argument is optional but can only be supplied if all preceding arguments are provided. If we wrote

cv.boxFilter(src, ddepth, ksize[, dst][, anchor])

That would imply that I could call boxFilter and provide anchor but not dst (perhaps using keyword arguments). By writing the optional arguments in this nested form, it makes clear that only the procedural method of providing arguments in the proper order and without skipping over any is officially accepted.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much for the quick response and the example. This was confusing me for so long! That makes complete sense. Cheers.
Thanks for providing such a clear and concise answer, for such a confusing bit of the documentation! I stared at the documentation for a long time trying to figure out how and why OpenCV expects arguments to be in nested arrays. I wish there were some better way to represent this in the documentation, which didn't overlap with common code syntax. If I were making the documentation, I may have instead added " = null" to each of the optional parameters, and in the description I'd say that each depends on the prior ones. Then, I'd let console outputs report the error if some parameter is missing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.