0

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 .

2
  • Whilst they do not state it in their documentation, by convention square brackets indicate optional fields/parameters Commented Jun 3, 2017 at 9:01
  • in this only mask is optional, so shouldn't it be cv2.bitwise_and(src1,src2,dst,[mask]) → dst ?? Commented Jun 3, 2017 at 9:06

1 Answer 1

2

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.

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

Comments

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.