9 图像分隔/二值化
- 使用分水岭算法基于掩模的图像分割
- 函数:cv2.watershed()
import cv2 as cv
import numpy as np
img = cv.imread('test.jpg')
cv.imshow('input image', img)
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
ret, thresh = cv.threshold(gray, 0, 255, cv.THRESH_BINARY_INV + cv.THRESH_OTSU)
cv.imshow('thresh', thresh)
cv.waitKey(0)
cv.destroyAllWindows()