用于模糊图像的OpenCV Python程序

注意:这篇文章包含不能使用在线编译器运行的代码。在尝试在系统上运行该程序之前,请确保已安装Python 2.7和cv2模块。

null

大家好!我读了一本作者的精彩作品 阿迪蒂亚·普拉卡什 OpenCV C++程序模糊图像 ,所以我决定提出类似的东西,但这次是Python。这是一个非常简单的程序,结果基本相同。

# Python Program to blur image
# Importing cv2 module
import cv2
# bat.jpg is the batman image.
img = cv2.imread( 'bat.jpg' )
# make sure that you have saved it in the same folder
# You can change the kernel size as you want
blurImg = cv2.blur(img,( 10 , 10 ))
cv2.imshow( 'blurred image' ,blurImg)
cv2.waitKey( 0 )
cv2.destroyAllWindows()


输出: 图片[1]-用于模糊图像的OpenCV Python程序-yiteyi-C++库

现在,上面的这个程序使用的是图像模糊技术,叫做 平均投资 还有其他一些选择—— 高斯模糊,中值模糊,双边滤波。 让我们在程序中添加一些内容,并比较结果。

# importing opencv CV2 module
import cv2
# bat.jpg is the batman image.
img = cv2.imread( 'gfg.png' )
# make sure that you have saved it in the same folder
# Averaging
# You can change the kernel size as you want
avging = cv2.blur(img,( 10 , 10 ))
cv2.imshow( 'Averaging' ,avging)
cv2.waitKey( 0 )
# Gaussian Blurring
# Again, you can change the kernel size
gausBlur = cv2.GaussianBlur(img, ( 5 , 5 ), 0 )
cv2.imshow( 'Gaussian Blurring' , gausBlur)
cv2.waitKey( 0 )
# Median blurring
medBlur = cv2.medianBlur(img, 5 )
cv2.imshow( 'Media Blurring' , medBlur)
cv2.waitKey( 0 )
# Bilateral Filtering
bilFilter = cv2.bilateralFilter(img, 9 , 75 , 75 )
cv2.imshow( 'Bilateral Filtering' , bilFilter)
cv2.waitKey( 0 )
cv2.destroyAllWindows()


原始图像: 图片[2]-用于模糊图像的OpenCV Python程序-yiteyi-C++库 平均值: 图片[3]-用于模糊图像的OpenCV Python程序-yiteyi-C++库

高斯模糊: 图片[4]-用于模糊图像的OpenCV Python程序-yiteyi-C++库

媒体模糊: 图片[5]-用于模糊图像的OpenCV Python程序-yiteyi-C++库

双边过滤: 图片[6]-用于模糊图像的OpenCV Python程序-yiteyi-C++库

希望你喜欢这个帖子!奥夫·维德森!

关于作者:

维什韦什·施里马里 是BITS Pilani大学机械工程专业的本科生。他满足了分支机构没有教过的所有要求——白帽黑客、网络安全运营商,以及一位前竞争对手程序员。作为Python强大功能的坚定信徒,他的大部分作品都是用同一种语言完成的。每当他有时间除了编程、上课、看CSI网络之外,他就会去散步,默默地弹吉他。他的人生座右铭是:“享受生活,因为它值得享受!”

如果你也想在这里展示你的博客,请参见 吉微博 在Geeksforgek上写客博。

© 版权声明
THE END
喜欢就支持一下吧
点赞14 分享