Opencv库中的Python函数原型 [英] Python functions prototype in Opencv Library

查看:204
本文介绍了Opencv库中的Python函数原型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

cv2.bitwise_and(src1, src2[, dst[, mask]]) → dst

我试图了解此函数采用什么参数,为此,我正在阅读此页面 http://docs.opencv.org/2.4/modules/core/doc/operations_on_arrays.html#bitwise-and

它表示此函数采用以下参数

  • src1数组
  • src2数组
  • des数组
  • 遮罩[可选]

但是,我不理解该函数的表示形式,例如,为什么函数参数放在方括号中,并且逗号位置令人困惑.请解释.

就我所见,该库的文档似乎未指定所使用的正式语法,但是许多开发人员会认识到

现在,我们可以清楚地看到dstmask都是可选的(均默认为None).严格来说,我们可以不提供dst而提供mask,但是文档提示对我们来说,如果未指定dst,则不会使用该文件.

推测:我对这个库一点都不熟悉,但是我猜想dst是可选的,好像没有提供,输出将从函数返回.如果这样的话,实际上可以独立于dst提供mask,如果这样,我认为更好的文档字符串应该是:

cv2.bitwise_and(src1, src2[, dst][, mask]) → dst

但是,由于该文档没有正式定义的语法,因此可以进行解释和推测.

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.

这篇关于Opencv库中的Python函数原型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆