python有很好图形库cv2(包含很多图形处理的算法),pylab(绘图工具模块)
这两个“模块”是肯定要配置的。
安装这两个模块可用了我不少时间。
pylab它不是一个包,而是 numpy, scipy 和 matplotlab 的合体,要安装这3个部分。
然后检测一下:
1 import pylab as pl 2 listOfInt = [] 3 for c in range(10): 4 listOfInt.append(c*2) 5 6 print listOfInt 7 8 pl.plot(listOfInt) 9 pl.show()
出现效果:就成功了pylab模块的安装.
然后就是cv2了,找了好多资料,python库那里面下载东西,目录结构刚开始没搞清楚,不知道粘贴哪个。
http://blog.csdn.net/qq_14845119/article/details/52354394这篇文章有很详细的讲解。说的比较多。只要看一部分就ok了
opencv2.4.12 http://opencv.org/downloads.html下载地址。
点击下载的opencv-2.4.12.exe,一路next下去,例如本人安装到E盘根目录下。安装完成后,将E:opencv2_4_12uildpython2.7x64下的cv2.pyd拷贝到你的Lib文件夹下就可以了。
然后测试一下
1 import cv2 2 import numpy as np 3 4 img = cv2.imread("1.jpg") 5 emptyImage = np.zeros(img.shape, np.uint8) 6 7 emptyImage2 = img.copy() 8 9 emptyImage3=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) 10 11 cv2.imshow("EmptyImage3", emptyImage3) 12 cv2.waitKey (0) 13 cv2.destroyAllWindows()
显示效果即可:
注意:scipy:http://sourceforge.net/projects/scipy/files/scipy/0.12.0/
里面是没有64位操作系统的exe文件的,解决方案有很多,但是有效的不多,改注册表麻烦。
写一个register.py的脚本,我试了一下是没有用的。可以去尝试一下。
1 # 2 # script to register Python 2.0 or later for use with win32all 3 # and other extensions that require Python registry settings 4 # 5 # written by Joakim Loew for Secret Labs AB / PythonWare 6 # 7 # source: 8 # http://www.pythonware.com/products/works/articles/regpy20.htm 9 # 10 # modified by Valentine Gogichashvili as described in http://www.mail-archive.com/distutils-sig@python.org/msg10512.html 11 12 import sys 13 14 from _winreg import * 15 16 # tweak as necessary 17 version = sys.version[:3] 18 installpath = sys.prefix 19 20 regpath = "SOFTWARE\Python\Pythoncore\%s\" % (version) 21 installkey = "InstallPath" 22 pythonkey = "PythonPath" 23 pythonpath = "%s;%s\Lib\;%s\DLLs\" % ( 24 installpath, installpath, installpath 25 ) 26 27 def RegisterPy(): 28 try: 29 reg = OpenKey(HKEY_CURRENT_USER, regpath) 30 except EnvironmentError as e: 31 try: 32 reg = CreateKey(HKEY_CURRENT_USER, regpath) 33 SetValue(reg, installkey, REG_SZ, installpath) 34 SetValue(reg, pythonkey, REG_SZ, pythonpath) 35 CloseKey(reg) 36 except: 37 print "*** Unable to register!" 38 return 39 print "--- Python", version, "is now registered!" 40 return 41 if (QueryValue(reg, installkey) == installpath and 42 QueryValue(reg, pythonkey) == pythonpath): 43 CloseKey(reg) 44 print "=== Python", version, "is already registered!" 45 return 46 CloseKey(reg) 47 print "*** Unable to register!" 48 print "*** You probably have another Python installation!" 49 50 if __name__ == "__main__": 51 RegisterPy()
大致意思说的是scipy需要numpy不是上面的那种,而是numpy+mkl