时间:2020-12-21 18:51:35 | 栏目:Python代码 | 点击:次
本文为大家分享了opencv图片模糊和锐化的具体实现代码,供大家参考,具体内容如下
一、模糊操作
#!/usr/bin/env python # _*_ coding:utf-8 _*_ import cv2 as cv import numpy as np def blur_demo(image): dst = cv.blur(image, (15, 1)) cv.imshow("blur_demo", dst) src = cv.imread("F:\miao3.png") cv.namedWindow("input image", cv.WINDOW_AUTOSIZE) cv.imshow("input image", src) blur_demo(src) cv.waitKey(0) cv.destroyAllWindows()
运行结果,如图:
二、锐化操作
#!/usr/bin/env python # _*_ coding:utf-8 _*_ import cv2 as cv import numpy as np def custom_blur_demo(image): kernel = np.array([[0, -1, 0], [-1, 5, -1], [0, -1, 0]], np.float32) #锐化 dst = cv.filter2D(image, -1, kernel=kernel) cv.imshow("custom_blur_demo", dst) src = cv.imread("F:\miao3.png") cv.namedWindow("input image", cv.WINDOW_AUTOSIZE) cv.imshow("input image", src) custom_blur_demo(src) cv.waitKey(0) cv.destroyAllWindows()
运行结果,如下图: