在Windows环境下使用opencv2.2的python绑定

使用VS2008编译OpenCV2.2,在F:/CV/OpenCV/OpenCV-2.2.0/Build/Python2.6/Lib/site-packages目录下,

生成cv.lib和cv.pyd两个文件。

1、 将F:/CV/OpenCV/OpenCV-2.2.0/Build/bin添加到系统环境变量中;

2、 将cv.lib 和 cv.pyd文件拷贝到python安装路径下的E:/programs/Python2.6.5/Lib/site-packages目录中;

然后即可以使用OpenCV的python rapper了。/(^o^)/~

下面以提取surf特征,并绘制到原图上为例:

 

from numpy import *

import cv

img = cv.LoadImage('F:/removed_haze.jpg')

gray = cv.CreateImage(cv.GetSize(img), 8, 1)

cv.CvtColor(img, gray, cv.CV_BGR2GRAY)

(keys, descs) = cv.ExtractSURF(gray, None, cv.CreateMemStorage(0), (0, 300, 3, 1))

 

for key, desc in zip(keys, descs):

    r = key[2]

    cv.Circle(img, key[0], r, cv.RGB(255,255,0), 1, cv.CV_AA)

    angle = key[3]

    sx = key[0][0]

    sy = key[0][1]

    ex = sx + r * cos(angle/360 * pi)

    ey = sy + r * sin(angle/360 * pi)

    cv.Line(img, (sx,sy), (ex, ey), cv.RGB(0, 255, 0), 1, cv.CV_AA)

 

cv.ShowImage('test', img)

cv.WaitKey(0)

 

你可能感兴趣的:(windows,python,import,360)