'''
threshold segmentation
'''
import cv2
import imutils
import numpy as np
def threshold_seg(args):
''''''
threshold = cv2.getTrackbarPos(trackbar_name1, wname)
cimg = np.ones(img.shape, dtype=np.uint8)
cimg[img <= threshold] = 0
cimg[img > threshold] = 255
cv2.imshow(wname, cimg)
if __name__ == '__main__':
wname = 'threshold segmentation'
trackbar_name1 = 'threshold'
img = cv2.imread("./img_1596.png", 0)
cv2.imshow('img', img)
cv2.namedWindow(wname)
cv2.createTrackbar(trackbar_name1, wname, 100, 255, threshold_seg)
threshold_seg(0)
if cv2.waitKey(0) == 27:
cv2.destroyAllWindows()
python+opencv阈值分割
最新推荐文章于 2025-07-14 09:17:03 发布
本文介绍了一种基于阈值的图像分割技术,通过调整阈值实现图像的黑白化处理,利用OpenCV库读取图像并进行实时阈值分割,展示了如何使用轨迹条交互式调整阈值,以达到理想的分割效果。

8248

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



