您的位置:首页 > 编程语言 > Python开发

python + opencv 学习系列 1 : Getting Started with Images

2015-10-03 22:50 721 查看
本文主要是根据 opencv 官网中 使用 Python的 教程写的,主要是为了个人学习记忆。

本节学习官网地址:
http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_gui/py_image_display/py_image_display.html#display-image
下面给出代码整合以及注释

def startWithImage():
'''
load and display an image
'''
#load an color image in grayscale
grayImage = cv2.imread("girl and green.jpg", 0) #中文标题不行 待解

#display an image
cv2.namedWindow("girl and green", cv2.WINDOW_AUTOSIZE)
cv2.imshow("girl and green", grayImage)
cv2.waitKey(10000)
cv2.destroyAllWindows()

#write an image
cv2.imwrite("gary girlAndGreen.jpg", grayImage )

def SumItUp():
''' copy from opencv python tutorial '''
grayImage = cv2.imread("girl and staircase.jpg", 0)
cv2.imshow("girl and staircase",grayImage)
k = cv2.waitKey(0 )
if k == 27:   # wait for ESC key to exit
cv2.destroyAllWindows()
elif k == ord("s"): # wait for "s" key to save and exit
cv2.imwrite("gray girlAndStaircase.jpg", grayImage )
cv2.destroyAllWindows()

def usingMatplotlib():
'''
Matplotlib is a plotting library for Python
which gives you wide variety of plotting methods.
'''
from matplotlib import pyplot as plt

grayImage = cv2.imread("girl and sexy.jpg", 0 )
plt.imshow(grayImage, cmap='gray', interpolation= 'bicubic')
plt.xticks([]), plt.yticks([] ) # to hide tick values on X and Y axis
plt.show()

def mainPy():
''' python入口函数 '''
#startWithImage( )
#SumItUp()
usingMatplotlib()

if __name__ == "__main__":
mainPy( )
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: