内容简介: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实现
- 从基本概念到实现,全卷积网络实现更简洁的图像识别
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
操作系统基础教程
戴维斯 / 第1版 (2006年7月1日) / 2006-7 / 34.0
这是一本关于操作系统基本原理的教科书,其最大特点就是从操作系统的分层概念出发,深入浅出地介绍了操作系统的基本概念和基本框架。本书可以作为高等院校非计算机专业相关课程的教材或参考书,也适合具有高中以上数学基础的计算机用户自学,还可以作为社会上计算机培训机构的教材。对所有想了解计算机操作系统,但又不需要或不打算深入学习其理论和实现细节的读者来说,本书是一本极具价值的入门指导书。一起来看看 《操作系统基础教程》 这本书的介绍吧!