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

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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值