opencv轮廓模糊识别
Opencv+Python实现图像运动模糊和高斯模糊的示例运动模糊:由于相机和物体之间的相对运动造成的模糊,又称为动态模糊
opencv+python实现运动模糊,主要用到的函数是cv2.filter2d()
:
|
# coding: utf-8 import numpy as np import cv2 def motion_blur(image, degree = 12 , angle = 45 ): image = np.array(image) # 这里生成任意角度的运动模糊kernel的矩阵, degree越大,模糊程度越高 m = cv2.getrotationmatrix2d((degree / 2 , degree / 2 ), angle, 1 ) motion_blur_kernel = np.diag(np.ones(degree)) motion_blur_kernel = cv2.warpaffine(motion_blur_kernel, m, (degree, degree)) motion_blur_kernel = motion_blur_kernel / degree blurred = cv2.filter2d(image, - 1 , motion_blur_kernel) # convert to uint8 cv2.normalize(blurred, blurred, 0 , 255 , cv2.norm_minmax) blurred = np.array(blurred, dtype = np.uint8) return blurred img = cv2.imread( './9.jpg" alt="opencv轮廓模糊识别(Opencv+Python实现图像运动模糊和高斯模糊的示例)" border="0" /> img_ = motion_blur(img) cv2.imshow( 'source image' ,img) cv2.imshow( 'blur image' ,img_) cv2.waitkey() |
原图:
运动模糊效果:
高斯模糊:图像与二维高斯分布的概率密度函数做卷积,模糊图像细节
opencv+python实现高斯模糊,主要用到的函数是cv2.gaussianblur()
:
|
# coding: utf-8 import numpy as np import cv2 img = cv2.imread( './9.jpg" alt="opencv轮廓模糊识别(Opencv+Python实现图像运动模糊和高斯模糊的示例)" border="0" /> img_ = cv2.gaussianblur(img, ksize = ( 9 , 9 ), sigmax = 0 , sigmay = 0 ) cv2.imshow( 'source image' ,img) cv2.imshow( 'blur image' ,img_) cv2.waitkey() |
高斯模糊效果:
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对开心学习网的支持。如果你想了解更多相关内容请查看下面相关链接
原文链接:https://blog.csdn.net/dcrmg/article/details/82317181