资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

PythonOpenCV处理图像之滤镜和图像运算-创新互联

本文实例为大家分享了Python OpenCV处理图像之滤镜和图像运算的具体代码,供大家参考,具体内容如下

创新互联从2013年成立,是专业互联网技术服务公司,拥有项目做网站、网站制作网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元静海做网站,已为上家服务,为静海各地企业和个人服务,联系电话:028-86922220

0x01. 滤镜

喜欢自拍的人肯定都知道滤镜了,下面代码尝试使用一些简单的滤镜,包括图片的平滑处理、灰度化、二值化等:

import cv2.cv as cv
 
image=cv.LoadImage('img/lena.jpg', cv.CV_LOAD_IMAGE_COLOR) #Load the image
cv.ShowImage("Original", image)
 
grey = cv.CreateImage((image.width ,image.height),8,1) #8depth, 1 channel so grayscale
cv.CvtColor(image, grey, cv.CV_RGBA2GRAY) #Convert to gray so act as a filter
cv.ShowImage('Greyed', grey)
 
# 平滑变换
smoothed = cv.CloneImage(image)
cv.Smooth(image,smoothed,cv.CV_MEDIAN) #Apply a smooth alogrithm with the specified algorithm cv.MEDIAN
cv.ShowImage("Smoothed", smoothed)
 
# 均衡处理
cv.EqualizeHist(grey, grey) #Work only on grayscaled pictures
cv.ShowImage('Equalized', grey)
 
# 二值化处理
threshold1 = cv.CloneImage(grey)
cv.Threshold(threshold1,threshold1, 100, 255, cv.CV_THRESH_BINARY)
cv.ShowImage("Threshold", threshold1)
 
threshold2 = cv.CloneImage(grey)
cv.Threshold(threshold2,threshold2, 100, 255, cv.CV_THRESH_OTSU)
cv.ShowImage("Threshold 2", threshold2)
 
element_shape = cv.CV_SHAPE_RECT
pos=3
element = cv.CreateStructuringElementEx(pos*2+1, pos*2+1, pos, pos, element_shape)
cv.Dilate(grey,grey,element,2) #Replace a pixel value with the maximum value of neighboors
#There is others like Erode which replace take the lowest value of the neighborhood
#Note: The Structuring element is optionnal
cv.ShowImage("Dilated", grey)
 
cv.WaitKey(0)

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网站栏目:PythonOpenCV处理图像之滤镜和图像运算-创新互联
文章路径:http://cdkjz.cn/article/cdejis.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220