美文网首页
[OpenCV官方教程中文版-段力辉译]-图像阈值处理cv2.t

[OpenCV官方教程中文版-段力辉译]-图像阈值处理cv2.t

作者: 六千宛 | 来源:发表于2021-06-18 12:18 被阅读0次
cv2.threshold(src, thresh, maxval, type[, dst]) 

在其中:

src:表示的是图片源
thresh:表示的是阈值(起始值)
maxval:表示的是最大值
type:表示的是这里划分的时候使用的是什么类型的算法**,常用值为0(cv2.THRESH_BINARY)**
image.png
(x,y)表示的是图像中的坐标
INV 表示的是取反
一般的(BINARY)效果是:
将一个灰色的图片,变成要么是白色要么就是黑色。(大于规定thresh值就是设置的最大值(常为255,也就是白色))
import cv2
import numpy as np

img = np.zeros((200, 200), dtype=np.uint8)
img[50:150, 50:150] = 255  # create a image with black color in the middle and its background is white.
cv2.imshow("Image-Old", img)
ret, thresh = cv2.threshold(img, 127, 255, 0)
cv2.imshow("Image-New", thresh)
cv2.waitKey()
cv2.destroyAllWindows()

相关文章

网友评论

      本文标题:[OpenCV官方教程中文版-段力辉译]-图像阈值处理cv2.t

      本文链接:https://www.haomeiwen.com/subject/taekyltx.html