zoukankan      html  css  js  c++  java
  • python手记(25)

    pyopencv使用,首先安装好opecv,在官网http://opencv.org/上下载并安装,然后将其python绑定库opencvuildpython2.7cv2.pyd复制到python2.x的Lib/Sitepackage目录下

    然后进行测试,复制以下代码 ,如果运行正常,则表示安装成功,注意要安装numpy库

    #!/usr/bin/env python
    
    '''
    browse.py
    =========
    
    Sample shows how to implement a simple hi resolution image navigation
    
    Usage
    -----
    browse.py [image filename]
    
    '''
    
    import numpy as np
    import cv2
    import sys
    
    if __name__ == '__main__':
        print 'This sample shows how to implement a simple hi resolution image navigation.'
        print 'USAGE: browse.py [image filename]'
        print
    
        if len(sys.argv) > 1:
            fn = sys.argv[1]
            print 'loading %s ...' % fn
            img = cv2.imread(fn)
        else:
            sz = 4096
            print 'generating %dx%d procedural image ...' % (sz, sz)
            img = np.zeros((sz, sz), np.uint8)
            track = np.cumsum(np.random.rand(500000, 2)-0.5, axis=0)
            track = np.int32(track*10 + (sz/2, sz/2))
            cv2.polylines(img, [track], 0, 255, 1, cv2.CV_AA)
    
        small = img
        for i in xrange(3):
            small = cv2.pyrDown(small)
    
        def onmouse(event, x, y, flags, param):
            h, w = img.shape[:2]
            h1, w1 = small.shape[:2]
            x, y = 1.0*x*h/h1, 1.0*y*h/h1
            zoom = cv2.getRectSubPix(img, (800, 600), (x+0.5, y+0.5))
            cv2.imshow('zoom', zoom)
    
        cv2.imshow('preview', small)
        cv2.setMouseCallback('preview', onmouse)
        cv2.waitKey()
        cv2.destroyAllWindows()
    




  • 相关阅读:
    ES基本介绍
    Mybatis 读写分离简单实现
    分享一个Flink checkpoint失败的问题和解决办法
    一次“内存泄露”引发的血案
    记一次堆外内存泄漏排查过程
    MySQL主从复制读写分离,看这篇就够了!
    JVM运行时内存数据区域
    .NET MVC 页面传值方式
    jQuery 对表格内容进行搜索筛选
    泛型
  • 原文地址:https://www.cnblogs.com/bbsno1/p/3268676.html
Copyright © 2011-2022 走看看