_, thresh = cv2.threshold(
img, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
# 使用cv.RETR_CCOMP寻找轮廓
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_CCOMP, 2)
# 绘制轮廓内部
cv2.drawContours(img, contours, i, 255, -1)


该文章介绍了如何使用OpenCV库进行图像处理,包括应用Otsu的二值化阈值处理和寻找图像的轮廓。通过cv2.threshold进行二值化,接着使用cv2.findContours寻找图像的连通组件轮廓,并用cv2.drawContours绘制轮廓到图像内部。
_, thresh = cv2.threshold(
img, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
# 使用cv.RETR_CCOMP寻找轮廓
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_CCOMP, 2)
# 绘制轮廓内部
cv2.drawContours(img, contours, i, 255, -1)


9933

被折叠的 条评论
为什么被折叠?