opencv函数库查询手册(python)(持续更新)_Opencv库中的Python函数原型

1586010002-jmsa.png

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值