import cv2 as cv
img = cv.imread('./shangyi.jpg',cv.IMREAD_COLOR)
gray = cv.cvtColor(img,cv.COLOR_BGR2GRAY)
#固定阈值 手动决定thresh大小
#src:灰度图资源 thresh:阈值 maxval:像素最大值 type:像素值分配方式
#将灰度图中的灰度值进行二值化变换,变换方式由type决定
# eq:cv.THRESH_BINARY表示大于thresh的灰度值会转为maxval,小于thresh的灰度值会转为0
ret,thresh1 = cv.threshold(gray,127,255,cv.THRESH_BINARY)
ret,thresh2 = cv.threshold(gray,127,255,cv.THRESH_BINARY_INV)
ret,thresh3 = cv.threshold(gray,127,255,cv.THRESH_TRUNC)
ret,<
python-opencv利用阈值函数将灰度图二值化
最新推荐文章于 2023-07-13 02:49:20 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)