cv2.bitwise_and(src1, src2[, dst[, mask]]) → dst
I am trying to understand , what arguments this function takes, and for that I am reading this page http://docs.opencv.org/2.4/modules/core/doc/operations_on_arrays.html#bitwise-and
It says this function takes following arguments
src1 array
src2 array
des array
mask [optional]
But, I don't understand the representation of this function, like,why the function arguments in square brackets and also , position of commas is confusing. Please explain .
解决方案
The documentation for this library does not seem to specify the formal syntax used as far as I can see however many developers will recognise the convention of using square brackets to denote optional fields/parameters.
If we follow this convention and then break down the definition they have provided:
cv2.bitwise_and(src1, src2[, dst[, mask]]) → dst
This says that the function bitwise_and takes src1 and src2 as input unconditionally. dst appears inside a [...] block which indicates it is optional. The mask parameters appears as another optional block nested inside the dst optional block which suggests that, not only is it optional but it is only relevant if we have previously specified dst in the outer block.
So this documentation suggests that the following are all valid inputs:
cv2.bitwise_and(src1, src2)
cv2.bitwise_and(src1, src2, dst)
cv2.bitwise_and(src1, src2, dst, mask)
But suggests that this would be invalid (in some undefined way):
cv2.bitwise_and(src1, src2, mask)
However if we look at the actual Python function definition it is as follows:
def bitwise_and(src1, src2, dst=None, mask=None): # real signature unknown; restored from __doc__
""" bitwise_and(src1, src2[, dst[, mask]]) -> dst """
pass
Now we can clearly see that both dst and mask are optional (both default to None). Strictly speaking we could supply mask without supplying dst but the documentation is hinting to us that it will not be used if dst is not specified.
Speculation: I'm not at all familiar with this library but I would guess that dst is optional as if not supplied the output will be returned from the function instead. If so it may be that mask can in fact be provided independent of dst and if so I would argue that the a better documentation string would have been:
cv2.bitwise_and(src1, src2[, dst][, mask]) → dst
But again as there is no formally defined syntax for the documentation it is open to interpretation and speculation.