PythonTip >> 博文 >> python

opencv2.2 in Python

zihua 2014-01-20 23:01:12 点击: 822 | 收藏


下面是怎么在windows下编译使用opencv2.2的python绑定的步骤:

1:CMake生成工程,勾上build_new_python_support, build_package

2: 在visual studio里面batch build all

3: 将opencv2.2\bin添加到系统变量PATH中

4: 将opencv2.2\Python2.x里面的Lib拷贝到Python2x的安装目录

5:打开ipython,或者Spyder,输入以下代码:

import cv

img = cv.LoadImage(‘C:\OpenCV-2.2.0\samples\c\cat.jpg’)

cv.ShowImage(‘cat’, img)

cv.WaitKey(0)

这样就能装载显示图像了。

下面干点稍微复杂一点的,提取surf特征,并绘制到原图上去,代码如下

from numpy import *

import cv

img = cv.LoadImage('C:\OpenCV-2.2.0\samples\c\cat.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('cat', img)

cv.WaitKey(0)
原文链接:http://www.wumii.com/item/TO0EEnOS

作者:zihua | 分类: python | 标签: python | 阅读: 822 | 发布于: 2014-01-20 23时 |