内容简介:OpenCV+Python实现运动模糊,主要用到的函数是cv2.filter2D():原图与运动模糊效果如下:
运动模糊: 由于相机和物体之间的相对运动造成的模糊,又称为动态模糊
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('linuxidc.com.jpg')
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('linuxidc.com.jpg')
img_ = cv2.GaussianBlur(img, ksize=(9, 9), sigmaX=0, sigmaY=0)
cv2.imshow('Source image',img)
cv2.imshow('blur image',img_)
cv2.waitKey()
高斯模糊效果如下:
更多 Python 相关信息见 Python 专题页面 https://www.linuxidc.com/topicnews.aspx?tid=17
Linux公社的RSS地址 : https://www.linuxidc.com/rssFeed.aspx
本文永久更新链接地址: https://www.linuxidc.com/Linux/2019-05/158653.htm
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- 如何基于深度学习实现图像
- 数字图像处理-前端实现
- 使用DCGAN实现人脸图像生成
- 通过迁移学习实现OCT图像识别
- ResNet图像识别与tensorflow实现
- 从基本概念到实现,全卷积网络实现更简洁的图像识别
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
传统企业,互联网在踢门
刘润 / 中国华侨出版社 / 2014-7 / 42
1、第一本传统企业互联网化的战略指导书,首次提出“互联网加减法”,迄今最清晰的转型公式 鉴于目前很多传统企业“老办法不管用,新办法不会用”的现状,本书将用“互联网的加减法” 这个简单模型清晰地说明商业新时代的游戏规则和全新玩法,帮助传统企业化解“本领恐慌” 。 2、小米董事长&CEO 金山软件董事长雷军,新东方教育科技集团董事长兼CEO俞敏洪,复旦大学管理学院院长陆雄文,复旦大学博士、......一起来看看 《传统企业,互联网在踢门》 这本书的介绍吧!