您的位置:首页 > 编程语言 > Python开发

python27 与opencv2.3.1 学习笔记 2012年草稿

2014-05-06 13:24 435 查看
这段时间在学习这两个工具的结合想要实现视频中车牌号的识别。在之前已经安装好了这些工具,安装花费了一些时间,因为不是那么轻车熟路网上的资源太多反而眼花缭乱了。我是菜鸟,这里写的东西都是用来总结的,如果有高手看到可以指点捷径那么不胜感激。车牌号的识别 网上一大堆程序 貌似用C++的很多哦,过一段时间我还是会回去看C++的源码,不过现在我想尽可能使用python先不要纠结自己写算法的问题,我想先跑一遍流程,算法慢慢来。关于算法其实我看了不少文章了~不过还停留在matlab的环境里,入门opencv我觉得很有必要。这里附上我看的参考文章的名字《Automatic License Plate Recognition using Python and OpenCV》总的说来,昨天晚上完成了两个步骤(真是汗颜),等再做几步再来总结好了。现在的情况是CvBlobsLib在python中的安装比较棘手。http://opencv.willowgarage.com/wiki/PythonInterface找到latest cookbookhttp://opencv.willowgarage.com/documentation/python/cookbook.html但是我需要的是CvBlobsLib的python接口http://code.google.com/p/pyblobs/source/browse/?r=9#svn%2Ftrunk这个网址提供了python接口的CvBlobsLIb的安装。于是我看中了pyblob(事实上我没有发现别的选择)http://code.google.com/p/pyblobs/source/browse/wiki/InstallationAndUsage.wiki?r=4对安装的要求是:
Make sure you have the prerequisites:
* swig
* libcv-dev
* python-dev
* python-opencv
为了看起来更清晰一点,分点吧:一、swigswig :http://www.swig.org/Doc1.3/Python.html#Python_nn2SWIG uses a layered approach in which parts of the extension module are defined in C and other parts are defined in Python. The C layer contains low-level wrappers whereas Python code is used to define high-features.这句话说明了为什么我不仅要学习c还要学习python,当然,现在我有点怀疑,觉得自己貌似应该从c入手opencv,所以不久后我想我就会对与c相关的部分一起学习。SWIG是一个能将C或者C++编写的程序与其它各种高级语言如Perl, Python, Ruby, 和 Tcl进行联接的开发工具。其原理是从C/C++头文件中找到申明并利用他们生成脚本语言访问C/C++代码所必须的封装代码。SWIG具有高度可自定义的特点,它能帮助你生成适合你的应用程序的封装包。In order to compile SWIG generated code into an extension module, you usually have to create a shared library.This page contains information about doing this on different platforms.http://www.dabeaz.com/cgi-bin/wiki.pl?SwigFaq/SharedLibraries1.下载swigwinwindows下SWIG需要去官网下载一个安装包:http://www.swig.org/如果你想自己编译生成exe文件,可以参考这里(众里寻他千百度啊)http://www.swig.org/Doc1.3/Windows.html从学校里翻出去颇为不易,网速更加不给力(所以下错了重来花了不少时间),应该下swigwin这个文件,是针对windows用户的可执行文件。感觉如果我直接用C或者C++好多问题都免了啊~咳咳..端正学习态度,多学点总不会坏吧。2.一个例子我将下载下来的swigwin解压后,所在的exe文件的位置添加到环境变量中,在桌面上我生成两个文件example.c 以及example.i都是用记事本写好后直接改的名字,python的bin我已经添加到环境变量中了。然后cmd 中先cd到桌面,再直接
$  swig -python example.i 
这样就生成了 "example_wrap.doc" and "example.py"
好了,这里就是重复下别人的步骤,只是我学习swig的过程,
如果源代码的话,可以到这里来看看
http://www.penzilla.net/tutorials/python/swig/
由于gcc本身在windows下是不支持的,所以我还需要一个工具。
传说中有两个选择,MinGW或者cygin
我首先选择了cygin,
Cygwin is:a collection of tools which provide a Linux look and feel environment for Windows.http://www.cygwin.com/
上这个网站上得到的定义,精炼。
翻墙的童鞋记住设置代理服务器,我是不能直接连到服务器在线安装的。
选一个服务器
When installing packages for the first time, setup.exe doesnot install every package. Only the minimal base packages from the Cygwin distribution areinstalled by default. Clicking on categories and packages in thesetup.exe package installation screen will provide you with the ability to control what is installed or updated. Clicking on the"Default" field next to the "All" category will provide you with the opportunity to install every Cygwin package. Be advised that this will download and install hundreds of megabytes to your computer. The bestplanis probably to click on individual categories and install either entire categories or packages from the categories themselves.如果你不做任何修改,将默认安装Cygwin运行所需的最少的程序和组件。不过,gcc编译器不在默认安装程序之列,所以你必须选择安装gcc。具体是,在上述窗口中的列表中展开Devel目录,找到gcc-g++一项,点击“Default”,它就变成了“Install”,同时由于程序之间的依赖性 gcc-core条目的“Default”,也变成了“Install”。注:以上这段话摘录自http://www.linuxidc.com/Linux/2007-12/9546.htm万恶啊,断网了。。。第二天继续上线。最后安装好了,但是在生成o文件时始终出错。。。这一点我真的想不通,后面我尝试了http://techblog.99fang.com/?p=17这里提到的其实就是最早我看的文献,只是自己没有耐心看下去。总想找捷径~~~http://www.swig.org/Doc1.3/Python.html#PythonDistutils takes care of making sure that your extension is built with all the correct flags, headers, etc. for the version of Python it is run with. Distutils will compile your extension into a shared objectfile or DLL (.so on Linux, .pyd on Windows, etc). In addition, distutils can handle installing your package into site-packages,if that is desired. A configuration file (conventionally called: setup.py) describes the extension (and related python modules). The distutils will then generate all the right compiler directivesto build it for you.什么是distutils呢。我又查了一下:The distutils packageprovides support for building and installing additional modules into a Python installation. The new modules may be either 100%-pure Python, or may be extension modules written in C, or may be collections of Python packages which include modules coded in bothPython and C.http://docs.python.org/distutils/introduction.html#concepts-terminology结果十分悲剧的遇到了unable to find vcvarsall.bat在网上查了一下,有人说只要安装vs2008就可以了,另有人推荐用mingw说后者的其实是大多数。我实在有点郁闷自己一开始没有用现在就算同时知道了两个工具,又是一段非常漫长的爬出墙外的下载,没有在国内网站好好看过,没准其实有的。然后我迫不及待的尝试,Installed mingw32 to 
C:\programs\mingw\
Add mingw32's bin directory to your environment variable: append PATH with
c:\programs\MinGW\bin;
Edit ( create if not existing ) distutils.cfg locatedat
C:\Python26\Lib\distutils\distutils.cfg
tobe:
[build]
compiler=mingw32
这是国外的一个人的做法,中国更多的做法是setup.py install build --compiler=mingw32其实是一样的但是我又遇到了一个问题,command 'gcc' failed: no such file or directory我真是命苦的人,一个可能的原因,网上说的,就是cmd.exe不能够找到,因为gcc是一个连接,是一个shortcut而不是程序。
我在怀疑,是否是因为我先安装了cygwin的原因,于是我把cygwin的bin添加到环境变量中,于是错误变成了
gcc failed with exit status,这个实在是纠结了我一晚上,最后thanks God 我找了一个折中的方法http://www.develer.com/oss/GccWinBinaries

Unofficial MinGW GCC binaries for Windows

最重要的一点是

Python support (compiling distutils extensions)

This installer provides full support for integration with Python. This basically means 3 things:Add the GCC binary directory to the PATH.Python distutils just tries to run gcc and expects to automatically find it (there's no magic discovery involved, like that with Visual Studio where it finds the compiler through the registry). You don't want to know how many people just forget toset the PATH and waste hours trying to figure out why distutils isn't picking up their GCC (or, worse, it's picking up an older gcc somewhere else, maybe in cygwin...).Set GCC as default compiler in global distutils.cfg.The platform-wide distutils.cfg (located in PYTHON\Lib\distutils) allows to configure the default compiler to use for extension compilation. The installer will show the user all the existing Python installation in the system (discovered throughregistries) and will let the user choose which ones to configure so that GCC is used by default when compiling extensions.Configure the runtime library to use (MSVCRT.DLL or MSVCR71.DLL).As you probably know, Python 2.3 (and older) are compiled with Visual Studio 98 and linked against MSVCRT.DLL. Instead, Python 2.4 and 2.5 are compiled with Visual Studio .NET 2003 and linked against MSVCR71.DLL. There is some widespread confusionabout how to configure GCC properly to handle this. The installer will let the user decide which runtime library to use for compilation. Moreover, the setting can be changed at any time by using the gccmrt script (see below).它有我最需要的功能,python support 哇咔咔~~>>> import example>>> example.fact(4)24>>>成功了~~~我思路还比较混乱,要学习的还有很多·~~~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: