Home > Back-end >  Why cv2.threshold has to have 2 argument (ret, thresh)?
Why cv2.threshold has to have 2 argument (ret, thresh)?

Time:09-23

Simple question

what is ret?

I know that thresh is the result of numpy array after thresholding an image but what is the function of ret ? (I only know ret is the constant but still don't know how to get this value and how it works)

Thank you for the answer even it's such an idiot answer for expert

CodePudding user response:

I quote from this link
That said:

The cv2.threshold function then returns a tuple of 2 values: the first, T, is the threshold value. In the case of simple thresholding, this value is trivial since we manually supplied the value of T in the first place. But in the case of Otsu’s thresholding where T is dynamically computed for us, it’s nice to have that value. The second returned value is the thresholded image itself.

What you mean by ret is the T from above explanation.

CodePudding user response:

This page have a very detailed explanation:

https://opencv24-python-tutorials.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_thresholding/py_thresholding.html

Search for retval gives you the following:
Then the algorithm finds the optimal threshold value and returns you as the second output, retVal. If Otsu thresholding is not used, retVal is same as the threshold value you used.

  • Related