Python OpenCV documentation
Question:
Original question for posterity below
I understood that functions are technically only in C++ and only the wrapper is available in Python with function calls examples in the documentation.
It’s quite possible that, for those who are just starting out with OpenCV, the concept may not be as simple and intuitive as it is for our more experienced users.
Thanks to all the moderators that helped and explained.
Original question:
I am studying Python and cannot understand (I lack of knowledge for sure) why some functions are documented as returning void
(that is related to C++) and instead their main use is when they return something.
This is an example: OpenCV resize() that is regularly used like this:
resized = cv2.resize(to_be_resized,None,fx=2, fy=2)
Answers:
That Python function is not documented as returning void
. void
is not even a thing in Python.
A C++ function documented alongside the Python function is documented as returning void
, and indeed, that C++ function returns void
. The Python function does not.
It appears you have some confusion between the terms void
and "returning a value". In C++, void
is a keyword that signifies a function doesn’t return any value. However, Python doesn’t have the concept of void
functions. Instead, a function that doesn’t return anything explicitly will implicitly return None
.
The OpenCV resize() function is a Python function that takes an input image and returns a resized image. The example usage is correct:
resized = cv2.resize(to_be_resized, None, fx=2, fy=2)
In this case, the resize() function returns a new image (NumPy array) with the specified scaling factors (fx=2, fy=2). It doesn’t modify the input image to_be_resized in-place.
The fact that you read that the function returns void
it’s because it’s referred to the C++ function, not the Python function wrapper that you are calling using Python.
In fact, the OpenCV resize() function in Python does return a value, which is the resized image.
Hope this clears up the confusion!
Original question for posterity below
I understood that functions are technically only in C++ and only the wrapper is available in Python with function calls examples in the documentation.
It’s quite possible that, for those who are just starting out with OpenCV, the concept may not be as simple and intuitive as it is for our more experienced users.
Thanks to all the moderators that helped and explained.
Original question:
I am studying Python and cannot understand (I lack of knowledge for sure) why some functions are documented as returning void
(that is related to C++) and instead their main use is when they return something.
This is an example: OpenCV resize() that is regularly used like this:
resized = cv2.resize(to_be_resized,None,fx=2, fy=2)
That Python function is not documented as returning void
. void
is not even a thing in Python.
A C++ function documented alongside the Python function is documented as returning void
, and indeed, that C++ function returns void
. The Python function does not.
It appears you have some confusion between the terms void
and "returning a value". In C++, void
is a keyword that signifies a function doesn’t return any value. However, Python doesn’t have the concept of void
functions. Instead, a function that doesn’t return anything explicitly will implicitly return None
.
The OpenCV resize() function is a Python function that takes an input image and returns a resized image. The example usage is correct:
resized = cv2.resize(to_be_resized, None, fx=2, fy=2)
In this case, the resize() function returns a new image (NumPy array) with the specified scaling factors (fx=2, fy=2). It doesn’t modify the input image to_be_resized in-place.
The fact that you read that the function returns void
it’s because it’s referred to the C++ function, not the Python function wrapper that you are calling using Python.
In fact, the OpenCV resize() function in Python does return a value, which is the resized image.
Hope this clears up the confusion!