OpenCV——基本图像处理
作者:互联网
1. 灰度处理图像
函数接口:cv2.cvtColor(存储彩色图像的三维数组,cv2.COLOR_BGR2GRAY)
# 灰度图
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.imwrite('Lenna_gray.png', img_gray)
2. 二值化图像
# 二值化
_, img_bin = cv2.threshold(img_gray, 127, 255, cv2.THRESH_BINARY)
cv2.imwrite('Lenna_bin.png', img_bin)
3. 模糊图像
# 平滑
img_blur = cv2.blur(img, (5, 5))
cv2.imwrite('Lenna_blur.png', img_blur)
4. 边缘检测
# 边缘提取
_, contours, _ = cv2.findContours(img_bin, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
img_cont = np.zeros(img_bin.shape, np.uint8)
cv2.drawContours(img_cont, contours, -1, 255, 3)
cv2.imwrite('Lenna_cont.png', img_cont)
参考资料
标签:基本,bin,cont,img,cv2,OpenCV,图像处理,blur,imwrite 来源: https://blog.csdn.net/qq_56030168/article/details/122760669