Wtf does this syntax mean (CVI/opencv python)?

cv.warpPerspective(src, M, dsize[, dst[, flags[, borderMode[, borderValue]]]] ) ->dst Does anyone know what are these random [ in between the parameter names? Source: https://docs.opencv.org/4.x/da/d54/group__imgproc__transform.html#gaf73673a7e8e18ec6963e3774e6a94b87
26 Replies
the magic guy
the magic guy2y ago
Like… deeply nested arrays? Lol Judging by all the ]]] at the end
Eakam
Eakam2y ago
Yea, I assumed so. Sorry should have added this here too. This is completely the opposite of that:
Eakam
Eakam2y ago
Like it expects normal non nested params. And then there is that nonsense at the bottom????? And this code works: transformed_image = cv.warpPerspective(img, matrix, (width, height)) So I have no idea what to think
CaramelCorn
CaramelCorn2y ago
I think it's bc dsize contains all of those sub variables
the magic guy
the magic guy2y ago
Idk if that matches up with the param signature….
CaramelCorn
CaramelCorn2y ago
dsize is a Size type that has numerous nested parameters maybe? and flags is the first layer, which holds a borderMode flag, which then holds a border Value??? weird structure but that's my best guess hahaha
Eakam
Eakam2y ago
Yea, it is kind of a weird structure
Eakam
Eakam2y ago
Found another one in the meantime:
Eakam
Eakam2y ago
And this is how it also works: resized_image = cv.resize(img, (scaled_width, scaled_height), cv.INTER_AREA) I am so lost on this syntax Maybe I will find out some day by learning python
CaramelCorn
CaramelCorn2y ago
maybe it's just fucked up syntax for default values?? lmfao
the magic guy
the magic guy2y ago
Hmmmmm
sigma
sigma2y ago
It means that the parameters are optional
CaramelCorn
CaramelCorn2y ago
ayyy I guess right
sigma
sigma2y ago
In the picture, I think the function signature at the top is C++ syntax, the one in the bottom being Python syntax The reason why it works it's because the last argument, (width, height) is a tuple, and because the method expects src, M, and dsize, then we know that the third argument is the value for dsize, which I guess is defined as a tuple
Eakam
Eakam2y ago
Yea, though I am still confused by why they wrote it with the [ They could have just said cv.warpPerspective(src, M, dsize, flags, borderMode, borderValue)
CaramelCorn
CaramelCorn2y ago
fr fr, just odd documentation style ig
Eakam
Eakam2y ago
I guess this is not an odd documentation style but actually means something
CaramelCorn
CaramelCorn2y ago
ah see, it makes sense like that it was the nesting syntax that was weird yk ohhhhh maybe the nesting meant that they had a different version for each variation of default variables? func(a) func(a,b) func(a,b,c) etc. so they nest the syntax to indicate that ig ?? lmfao idk
Eakam
Eakam2y ago
Wait, this one still doesn't make sense to me. Why is the comma after the [ Looks like the second argument is optional
CaramelCorn
CaramelCorn2y ago
ah to imply that a second argument is optional
Eakam
Eakam2y ago
Maybe it signifies that in some weird way
CaramelCorn
CaramelCorn2y ago
yeah
Eakam
Eakam2y ago
Ahhhh It all makes sense now So in the previous ones, the arguments were optional
CaramelCorn
CaramelCorn2y ago
yess
Want results from more Discord servers?
Add your server