标签:lan simple 技术 count key 画图 blur print lang
import cv2 as cv
import numpy as np
# 读路径下的图片
img = cv.imread("./cat.jpg")
# 创建纯黑画板
blank = np.zeros(img.shape, dtype="uint8")
# 变灰
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
cv.imshow("gray", gray)
# 模糊, 如果不用模糊,边缘点会非常多
blur = cv.GaussianBlur(gray, (5,5), cv.BORDER_DEFAULT)
# 二值化 寻找边缘点并画图
ret, thresh = cv.threshold(gray, 125, 225,cv.THRESH_BINARY)
counters, heirarchies = cv.findContours(thresh, cv.RETR_LIST, cv.CHAIN_APPROX_SIMPLE)
cv.drawContours(blank, counters, -1, (255,255,255), 1)
# print(len(counters))
# 边缘检测
canny = cv.Canny(blur, threshold1=100, threshold2=200)
cv.imshow("canny",canny)
cv.imshow("THRESH_BINARY",blank)
cv.waitKey(0)
标签:lan simple 技术 count key 画图 blur print lang
原文地址:https://www.cnblogs.com/Coder-Photographer/p/14375459.html