-2

I was going through opencv docs for cv2.resize when I came across this:

cv2.resize(src, dsize[, dst[, fx[, fy[, interpolation]]]]) → dst

What do the square brackets imply? I have come across them in many places in docs. Does the hierarchy of the square brackets matter? (innermost and outermost) An example would really help. Here is the link to the docs: https://docs.opencv.org/3.0-beta/modules/imgproc/doc/filtering.html

Giorgos Myrianthous
  • 36,235
  • 20
  • 134
  • 156
SG213
  • 65
  • 1
  • 7
  • Means optional. – khelwood May 23 '19 at 21:28
  • In this context, it means optional. Note though that the brackets are written such that if you provide `fx` then you *must* also provide `dst` (based upon the nesting of the brackets). – lurker May 23 '19 at 21:28
  • Literally the first hit for "square brackets in Python docs": https://stackoverflow.com/questions/1718903/what-do-square-brackets-mean-in-function-class-documentation. Please put more effort into research. – jonrsharpe May 23 '19 at 21:29
  • If so, then why can't it just be 'cv2.resize(src,dsize,[dst,fx,fy....])' ? Why the bracket hierarchy? **bold** – SG213 May 23 '19 at 21:31
  • Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation, as suggested when you created this account. [On topic](https://stackoverflow.com/help/on-topic), [how to ask](https://stackoverflow.com/help/how-to-ask), and ... [the perfect question](https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/) apply here. StackOverflow is not a design, coding, research, or tutorial resource. In particular, we expect you to research your own question before you pos. – Prune May 23 '19 at 21:32
  • Because in the one you show the optional arguments are all optional together. If you provide the first, you must provide all in your notation. The hierarchy let's you provide, optionally, just `dst`, or `dst, fx` or `dst, fx, fy` etc. – lurker May 23 '19 at 21:32

2 Answers2

1

Its the documentation style:
Here are the few examples:

image = cv2.imread("my_image.jpg") # src

# resize the image to 200x200px, ignoring aspect ratio
resized = cv2.resize(image, (200, 200))
cv2.imshow("Fixed Resizing", resized)

and

# fixed resizing and distort aspect ratio 
# to be 300px but compute the new height based on the aspect ratio
image = cv2.imread("my_image.jpg") # src
(h, w, d) = image.shape
print("width={}, height={}, depth={}".format(w, h, d))
r = 300.0 / w
dim = (300, int(h * r))
resized = cv2.resize(image, dim)
cv2.imshow("Aspect Ratio Resize", resized)
BetaDev
  • 4,516
  • 3
  • 21
  • 47
0

The square brackets signify that the arguments are not required.

You're only required to pass the src and dsize arguments in.

Alec
  • 8,529
  • 8
  • 37
  • 63