这是该cv2.adaptiveThreshold()
方法的文档,可通过调用内置help()
方法访问:
>>> import cv2
>>> help(cv2.adaptiveThreshold)
Help on built-in function adaptiveThreshold:
adaptiveThreshold(...)
adaptiveThreshold(src, maxValue, adaptiveMethod, thresholdType, blockSize, C[, dst]) -> dst
. @brief Applies an adaptive threshold to an array.
.
. The function transforms a grayscale image to a binary image according to the formulae:
. - **THRESH_BINARY**
. \f[dst(x,y) = \fork{\texttt{maxValue}}{if \(src(x,y) > T(x,y)\)}{0}{otherwise}\f]
. - **THRESH_BINARY_INV**
. \f[dst(x,y) = \fork{0}{if \(src(x,y) > T(x,y)\)}{\texttt{maxValue}}{otherwise}\f]
. where \f$T(x,y)\f$ is a threshold calculated individually for each pixel (see adaptiveMethod parameter).
.
. The function can process the image in-place.
.
. @param src Source 8-bit single-channel image.
. @param dst Destination image of the same size and the same type as src.
. @param maxValue Non-zero value assigned to the pixels for which the condition is satisfied
. @param adaptiveMethod Adaptive thresholding algorithm to use, see #AdaptiveThresholdTypes.
. The #BORDER_REPLICATE | #BORDER_ISOLATED is used to process boundaries.
. @param thresholdType Thresholding type that must be either #THRESH_BINARY or #THRESH_BINARY_INV,
. see #ThresholdTypes.
. @param blockSize Size of a pixel neighborhood that is used to calculate a threshold value for the
. pixel: 3, 5, 7, and so on.
. @param C Constant subtracted from the mean or weighted mean (see the details below). Normally, it
. is positive but may be zero or negative as well.
.
. @sa threshold, blur, GaussianBlur
>>>
重点介绍这部分:
@param thresholdType Thresholding type that must be either #THRESH_BINARY or #THRESH_BINARY_INV
因此,您只需将您的更改cv2.THRESH_TRUNC
为cv2.THRESH_BINARY
or之一cv2.THRESH_BINARY_INV
。
该help()
方法是无需上网即可获得有关方法的更多信息的好工具!