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

来源:互联网 发布:21天阿里云推荐系统 编辑:程序博客网 时间:2024/06/10 18:48

本文主要是根据 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( )



0 0