In order to perform simple thresholding, OpenCV provides the cv2.threshold() function that was briefly introduced in the previous section. The signature for this method is as follows:
cv2.threshold(src, thresh, maxval, type, dst=None) -> retval, dst
The cv2.threshold() function applies a fixed-level thresholding to the src input array (multiple-channel, 8-bit or 32-bit floating point). The fixed level is adjusted by the thresh parameter, which sets the threshold value. The type parameter sets the thresholding type, which will be further explained in the next subsection.
Different types are as follows:
- cv2.THRESH_BINARY
- cv2.THRESH_BINARY_INV
- cv2.THRESH_TRUNC
- cv2.THRESH_TOZERO
- cv2.THRESH_TOZERO_INV
- cv2.THRESH_OTSU
- cv2.THRESH_TRIANGLE
Additionally, the maxval parameter sets the maximum value to use only with the cv2.THRESH_BINARY and cv2.THRESH_BINARY_INV...