运城网站开发,商丘网站制作电话,网站建设的基本准则是什么,近期时政热点新闻20条OpenCV是Intel开源计算机视觉库。它由一系列 C 函数和少量 C 类构成#xff0c;实现了图像处理和计算机视觉方面的很多通用算法。在这篇文章(译自 http://glowingpython.blogspot.com/2011/10/beginning-with-opencv-in-python.html) 中将介绍如何使用 Python 版的 OpenCV。 下…OpenCV是Intel®开源计算机视觉库。它由一系列 C 函数和少量 C 类构成实现了图像处理和计算机视觉方面的很多通用算法。在这篇文章(译自 http://glowingpython.blogspot.com/2011/10/beginning-with-opencv-in-python.html) 中将介绍如何使用 Python 版的 OpenCV。 下面的代码打开磁盘中的图片打印一些图片属性并在一个窗口中显示这个图片# load and show an image in gray scaleimage cv.LoadImage(ariellek.jpg,cv.CV_LOAD_IMAGE_GRAYSCALE)# print some image propertiesprint Depth:,image.depth,# Channels:,image.nChannelsprint Size:,image.width,image.heightprint Pixel values average,cv.Avg(image)# create the windowcv.NamedWindow(my window, cv.CV_WINDOW_AUTOSIZE)cv.ShowImage(my window, image) # show the imagecv.WaitKey() # the window will be closed with a (any)key press我使用的是下面这张图片在控制台中显示的内容Depth: 8 # Channels: 1Size: 366 550Pixel values average (80.46735717834079, 0.0, 0.0, 0.0)现在可对图片更改其大小# resize the imagedst cv.CreateImage((150,150), 8, 1)cv.Resize(image,dst,interpolationcv.CV_INTER_LINEAR)cv.ShowImage(my window, dst)cv.WaitKey()cv.SaveImage(image2.jpg, dst) # save the image 结果是ASobel operator can be applied as follow:# Sobel operatordstSobel cv.CreateMat(image.height, image.width, cv.CV_32FC1)cv.Sobel(image,dstSobel,1,1,3)cv.ShowImage(my window, dstSobel)cv.WaitKey()cv.SaveImage(imageSobel.jpg, dstSobel)运行结果:最后的例子使用两个操作平滑过滤和截取操作# image smoothing and subtractionimageBlur cv.CreateImage(cv.GetSize(image), image.depth, image.nChannels)# filering the original imagecv.Smooth(image, imageBlur, cv.CV_BLUR, 15, 15)diff cv.CreateImage(cv.GetSize(image), image.depth, image.nChannels)# subtraction (original - filtered)cv.AbsDiff(image,imageBlur,diff)cv.ShowImage(my window, diff)cv.WaitKey()cv.SaveImage(imageDiff.jpg, diff)运行结果