python圖形庫(1)


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_12\build\python\2.7\x64下的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()

顯示效果即可:

 

 注意:scipyhttp://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()
View Code

 

 

大致意思說的是scipy需要numpy不是上面的那種,而是numpy+mkl


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM