potrace python绑定
pypotrace的Python项目详细描述
这些绑定为potrace库提供了一个面向对象的api。
示例用法
绑定与表示为numpy数组的输入图像一起工作:
import numpy as np import potrace # Make a numpy array with a rectangle in the middle data = np.zeros((32, 32), np.uint32) data[8:32-8, 8:32-8] = 1 # Create a bitmap from the array bmp = potrace.Bitmap(data) # Trace the bitmap to a path path = bmp.trace() # Iterate over path curves for curve in path: print "start_point =", curve.start_point for segment in curve: print segment end_point_x, end_point_y = segment.end_point if segment.is_corner: c_x, c_y = segment.c else: c1_x, c1_y = segment.c1 c2_x, c2_y = segment.c2
安装
ubuntu
安装系统依赖项:
$ sudo apt-get install build-essential python-dev libagg-dev libpotrace-dev pkg-config
安装Pypotrace:
$ git clone https://github.com/flupke/pypotrace.git $ cd pypotrace $ pip install -r requirements.txt $ pip install .
centos/redhat
- 安装系统依赖项::
- $sudo yum-y groupinstall“开发工具” $sudo yum-y安装agg devel potrace devel python devel
安装Pypotrace:
$ git clone https://github.com/flupke/pypotrace.git $ cd pypotrace $ pip install -r requirements.txt $ pip install .
OSX
安装系统依赖项:
$ brew install libagg pkg-config potrace
安装Pypotrace:
$ git clone https://github.com/flupke/pypotrace.git $ cd pypotrace $ pip install -r requirements.txt $ pip install .
窗口
感谢klonuo的指导
下面是如何使用mingw使这个包在windows上工作的说明 系统。也许可以用visual studio完成,但我缺乏技能 如此神奇。
因此,假设用户有mingw可用,则需要另外两个包:
- potrace源:http://potrace.sourceforge.net/#downloading
- agg源:http://www.antigrain.com/download/index.html
我在C:\src文件夹中提取了两个包。两者都很容易建立 分别在上执行./configure; make和./autogen.sh; make。 MSYS提示。
之后,我们需要一些变量来成功地构建pypotrace:
首先,包括路径:
- “numpy/arrayobject.h”:C:/Python27/Lib/site-packages/numpy/core/include
- potrace标题:C:/src/potrace-1.11/src
- agg头:C:/src/agg-2.5
agg includes有一个小陷阱,因为cpp源中引用了路径 指向agg2/*.h,而在下载的agg包中我们没有agg2 文件夹。对我来说,将C:/src/agg-2.5/include重命名为 C:/src/agg-2.5/agg2并使用C:/src/agg-2.5作为agg include文件夹。
接下来,libdirs用于我们在上面构建的库:
- Potrace:^{TT12}$
- 聚合:C:/src/agg-2.5/src
我们可以生成pypotrace build命令,并执行它:
python setup.py build_ext -IC:/Python27/Lib/site-packages/numpy/core/include;C:/src/potrace-1.11/src;C:/src/agg-2.5 -LC:/src/potrace-1.11/src/.libs;C:/src/agg-2.5/src
最后安装软件包:
C:\src\git\pypotrace>python setup.py install running install running build running build_py copying potrace\__init__.py -> build\lib.win32-2.7\potrace copying potrace\agg\__init__.py -> build\lib.win32-2.7\potrace\agg running build_ext skipping 'potrace\_potrace.c' Cython extension (up-to-date) skipping 'potrace\bezier.cpp' Cython extension (up-to-date) skipping 'potrace/agg\curves.cpp' Cython extension (up-to-date) running install_lib creating C:\Python27\Lib\site-packages\potrace creating C:\Python27\Lib\site-packages\potrace\agg copying build\lib.win32-2.7\potrace\agg\curves.pyd -> C:\Python27\Lib\site-packages\potrace\agg copying build\lib.win32-2.7\potrace\agg\__init__.py -> C:\Python27\Lib\site-packages\potrace\agg copying build\lib.win32-2.7\potrace\bezier.pyd -> C:\Python27\Lib\site-packages\potrace copying build\lib.win32-2.7\potrace\_potrace.pyd -> C:\Python27\Lib\site-packages\potrace copying build\lib.win32-2.7\potrace\__init__.py -> C:\Python27\Lib\site-packages\potrace byte-compiling C:\Python27\Lib\site-packages\potrace\agg\__init__.py to __init__.pyc byte-compiling C:\Python27\Lib\site-packages\potrace\__init__.py to __init__.pyc running install_egg_info Writing C:\Python27\Lib\site-packages\pypotrace-0.1-py2.7.egg-info
运行测试
您可以通过运行测试来检查一切是否正常工作:
$ pip install -r requirements-tests.txt $ nosetests -v
主页
此项目托管在github上:http://github.com/flupke/pypotrace