本文为大家分享了opencv图片模糊和锐化的具体实现代码,供大家参考,具体内容如下
一、模糊操作
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
#!/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()
|
运行结果,如图:
二、锐化操作
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
#!/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()
|
运行结果,如下图:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/elegentbeauty/article/details/79849887