pythonlibtiff
① 如何在樹莓派2上搭建python opencv
安裝 OpenCV 編譯相關套件
sudo apt-get install build-essential
sudo apt-get install cmake
sudo apt-get install pkg-config
sudo apt-get install libgtk2.0-dev libgtk2.0
sudo apt-get install zlib1g-dev
sudo apt-get install libpng-dev
sudo apt-get install libjpeg-dev
sudo apt-get install libtiff-dev
sudo apt-get install libjasper-dev
sudo apt-get install libavcodec-dev
sudo apt-get install swig
下載OpenCV2.4.9 for linux 利用wget+檔案的網址
cd
wget http //downloads sourceforge net/project/opencvlibrary/opencv-unix/2.4.9/opencv-2.4.9.zip
(wget 和 http 之間為一個空格,2.4.9為版本,載下來的檔案會放在資料夾pi中,檔名為download)
解壓縮 並建立 編譯暫存資料夾
cd
unzip opencv-2.4.9
cd opencv-2.4.9
mkdir release
cd release
編譯及安裝 OpenCV,Raspberry Pi 安裝需要大約10小時
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
sudo apt-get update
make
sudo make install
定義環境變數
sudo nano /etc/bash.bashrc
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
加入後按Ctrl+O存檔,按Enter後,再按Ctrl+X離開文件
確認opencv版本
pkg-config –modversion opencv
最後新增一個 sample code 執行編譯與測試
nano showimage.c (新增一個.c檔)
showimage.c 內容:
#include 「highgui.h"
int main( int argc, char **argv ) {
IplImage *img = cvLoadImage( argv[1] );
//大寫I小寫pl 大寫I小寫 mage
cvNamedWindow(「ShowImage 「, CV_WINDOW_AUTOSIZE);
cvShowImage(「ShowImage 「, img);
cvWaitKey(0);
cvReleaseImage(&img);
cvDestroyWindow(「ShowImage 「);
}
編譯指令
g++ `pkg-config --cflags --libs opencv` showimage.c -o showimage
(注意:pkg 前以及 opencv 後的符號並非單引號,而是esc按鍵下方的 ` 符號,cflags 與 libs 前為雙 -- 符號)
執行指令
./showimage /home/pi/opencv-2.4.9/samples/c/lena.jpg
執行完這行指令後,若有出現error: libopencv_calib3d cannot share object file
可先輸入 sudo sudo idconfig - v
再執行
./showimage /home/pi/opencv-2.4.9/samples/c/lena.jpg
② 如何在OSX系統上安裝Opencv3和Python2.7
setp1
安裝CodeX,不解釋,在AppStop中搜索安裝即可
setp2
安裝Homebrew
Homebrew即MacOSX上的apt-get
按照官網的安裝方式,在terminal中輸入下列命令即可完成安裝
cd ~
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
setp3
使用Homebrew安裝Python,注意:避免使用系統Python解釋器作為我們自己的主解析器,尤其是在使用virtualenv和virtualenvwrapper的時候。安裝命令:
$ brew install python
注意安裝結束後會有下列提示,提示我們把/usr/local/opt/python/libexec/bin增加到環境變數中,此舉正是為了我們在使用python時,使用的是用Homebrew安裝的python而不是系統python。
If you wish to have this formula's python executable in your PATH then add
the following to ~/.bash_profile:
export PATH="/usr/local/opt/python/libexec/bin:$PATH"
這是重要的一步,請不要跳過。
setp4
安裝 virtualenv 和 virtualenvwrapper
這兩個工具是為了創建獨立的python環境,不了解的朋友請自行Google
值得注意的是,這兩個工具對於搭建opencv3.0+python2.7運行環境來說不是必須的,但是強烈建議安裝,以保證python環境的干凈,易於管理。
安裝只需執行命令:
$ pip install virtualenv virtualenvwrapper
安裝完成後,在~/.bash_profile文件中追加如下內容:
# Virtualenv/VirtualenvWrapper
source /usr/local/bin/virtualenvwrapper.sh
然後執行命令:
$ source ~/.bash_profile
至此,virtualenv 和virtualenvwrapper已經正確完成安裝。我們可以使用如下命令創建一個獨立的python環境:
$ mkvirtualenv cv
setp5
我們開始安裝一些必須的python包,安裝NumPy
We need to install NumPy since the OpenCV Python bindings represent images as multi-dimensional NumPy arrays
安裝方式:
$ pip install numpy
注意:如果你使用了step4中的virtualenv創建python虛擬環境,則需要在您之前創建的虛擬環境中安裝需要的python包
step6
之前的步驟,主要目的是建立和配置編譯安裝OpenCv的環境,從這一步開始,我們開始真正的工作。
首先,我們使用brew安裝需要的開發者工具,例如CMake。
$ brew install cmake pkg-config
還有一些必要的圖像I/O包,這些包可以使我們能夠載入各種不同類型的圖像文件例如JPEG,PNG,TIFF等。
$ brew install jpeg libpng libtiff openexr
And finally, let』s install libraries that are used to optimize various operations within OpenCV (if we so choose):
$ brew install eigen tbb
setp7
恭喜,截止目前系統已經搭建完成,我們開始著手編譯和安裝python支持的opencv。下載代碼:
$ cd ~
$ git clone https://github.com/Itseez/opencv.git
$ cd opencv
$ git checkout 3.0.0
最後一個命令$ git checkout 3.0.0其中的3.0.0可以替換成你需要的版本號
之後下載opencv_contrib代碼,這部分不是必須的,但是強烈建議同時下載,原因是opencv_contrib包含很多有用的功能,包括:
feature detection, local invariant descriptors (SIFT, SURF, etc.), text detection in natural images, line descriptors, and more
$ cd ~
$ git clone https://github.com/Itseez/opencv_contrib
$ cd opencv_contrib
$ git checkout 3.0.0
請確保checkout opencv_contrib的版本號要與上面checkout opencv的版本號相同
step8
創建一個bulid目錄:
$ cd ~/opencv
$ mkdir build
$ cd build
使用CMake配置我們的構建:
$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local \
-D PYTHON2_PACKAGES_PATH=~/.virtualenvs/cv/lib/python2.7/site-packages \
-D PYTHON2_LIBRARY=/usr/local/Cellar/python/2.7.13_1/Frameworks/Python.framework/Versions/2.7/bin \
-D PYTHON2_INCLUDE_DIR=/usr/local/Frameworks/Python.framework/Headers \
-D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON \
-D BUILD_EXAMPLES=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/moles ..
注意:在執行上述命令之前,請務必切換到之前建立的虛擬python環境cv:
workon cv
cmake命令執行完成後,需要關注它的總結輸出,尤其是其中的Opencv moles部分:
-- OpenCV moles:
-- To be built: core flann imgproc ml objdetect photo video dnn imgcodecs shape videoio highgui superres ts features2d calib3d stitching videostab python2
-- Disabled: world
-- Disabled by dependency: -
-- Unavailable: cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cubjdetect cuptflow cudastereo cudawarping cudev java python3 viz
-- Python 2:
-- Interpreter: /Users/zhuangyuan/.virtualenvs/cv/bin/python2.7 (ver 2.7.13)
-- Libraries: /usr/local/Cellar/python/2.7.13_1/Frameworks/Python.framework/Versions/2.7/bin (ver 2.7.13)
-- numpy: /Users/zhuangyuan/.virtualenvs/cv/lib/python2.7/site-packages/numpy/core/include (ver 1.13.1)
-- packages path: /Users/zhuangyuan/.virtualenvs/cv/lib/python2.7/site-packages
如果python2部分的信息不完整,或者python2沒有出現在OpenCV moles的To be built:後面,而是出現在Unvailable:後面,則說明Cmake沒有正確完成,需要檢查此步驟中Cmake命令的參數中的路徑是否正確已經是否確實切換到了我們為opencv建立的虛擬python環境中。
再次提醒,此步驟中參數路徑必須仔細核對,如果錯誤,後續的編譯將無法成功
這時候可以開始編譯了:
$ make -j4
這里的4是利用4核CPU全速並行編譯,也可以不帶-j4參數,或者把4修改成你的CPU核心數
編譯完成後,進行安裝:
make install
如果有錯誤,加上sudo再執行:
sudo make install
setp9
檢查一下~/.virtualenvs/cv/lib/python2.7/site-packages/路徑下可以看到cv2.so就說明安裝成功了:
$ cd ~/.virtualenvs/cv/lib/python2.7/site-packages/
$ ls -l cv2.so
-rwxr-xr-x 1 adrian staff 2013052 Jun 5 15:20 cv2.so
用一下吧:
(cv) promote:lib zhuangyuan$ python
Python 2.7.13 (default, Jul 18 2017, 09:17:00)
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)] on darwin
Type "help", "right", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'3.3.0'
恭喜,OSX系統下opencv3 with python2.7環境搭建成功。
③ python 怎麼安裝pillow
1. 安裝pip
[plain] view plain
sudo easy_install pip
pip 安裝成功就可以直接安裝pil或者pillow
2. 通過命令pip install pil
[plain] view plain
pip install Pil
Downloading/unpacking Pil
Could not find any downloads that satisfy the requirement Pil
Some externally hosted files were ignored (use --allow-external Pil to allow).
Cleaning up...
No distributions at all found for Pil
Storing debug log for failure in /Users/macbook/Library/Logs/pip.log
3. 所以就安裝pillow
[plain] view plain
pip install --use-wheel Pillow
Downloading/unpacking Pillow
Downloading Pillow-2.4.0.zip (6.5MB): 5.0MB downloaded
Cleaning up...
弄了會別的回來發現還沒有下載完,這叫一個慢呀,於是放棄
4. 通過Git下載源碼地址https://github.com/python-imaging/Pillow
[plain] view plain
git clone https://github.com/python-imaging/Pillow.git
然後開始編譯安裝
4.1
[plain] view plain
python setup.py build_ext -i
編譯完之後會提示運行測試例子,並且發現JPEG support not available
[plain] view plain
--------------------------------------------------------------------
version Pillow 2.4.0
platform darwin 2.7.5 (default, Aug 25 2013, 00:04:04)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)]
--------------------------------------------------------------------
--- TKINTER support available
*** JPEG support not available
*** OPENJPEG (JPEG2000) support not available
--- ZLIB (PNG/ZIP) support available
*** LIBTIFF support not available
--- FREETYPE2 support available
*** LITTLECMS2 support not available
*** WEBP support not available
*** WEBPMUX support not available
--------------------------------------------------------------------
To add a missing option, make sure you have the required
library, and set the corresponding ROOT variable in the
setup.py script.
To check the build, run the selftest.py script.
4.2 因為JPEG support not available,運行python selftest.py報告錯誤
[plain] view plain
1 tests of 57 failed.
於是只好卸載pillow
可以通過pip命令來卸載
[plain] view plain
pip uninstall pillow
sudo pip uninstall pillow
Password:
Uninstalling Pillow:
/Library/Python/2.7/site-packages/Pillow-2.4.0-py2.7-macosx-10.9-intel.egg
/usr/local/bin/pilconvert.py
/usr/local/bin/pildriver.py
/usr/local/bin/pilfile.py
/usr/local/bin/pilfont.py
/usr/local/bin/pilprint.py
Proceed (y/n)? y
Successfully uninstalled Pillow
成功之後需要安裝libjpeg的支持
[plain] view plain
brew install libjpeg
安裝成功之後重新編譯pillow
[plain] view plain
--------------------------------------------------------------------
version Pillow 2.4.0
platform darwin 2.7.5 (default, Aug 25 2013, 00:04:04)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)]
--------------------------------------------------------------------
--- TKINTER support available
--- JPEG support available
*** OPENJPEG (JPEG2000) support not available
--- ZLIB (PNG/ZIP) support available
*** LIBTIFF support not available
--- FREETYPE2 support available
*** LITTLECMS2 support not available
*** WEBP support not available
*** WEBPMUX support not available
--------------------------------------------------------------------
[plain] view plain
python selftest.py
[plain] view plain
--------------------------------------------------------------------
Pillow 2.4.0 TEST SUMMARY
--------------------------------------------------------------------
Python moles loaded from /Users/macbook/yyang/app-devel-source/python/Pillow/PIL
Binary moles loaded from /Users/macbook/yyang/app-devel-source/python/Pillow/PIL
--------------------------------------------------------------------
--- PIL CORE support ok
--- TKINTER support ok
--- JPEG support ok
*** JPEG 2000 support not installed
--- ZLIB (PNG/ZIP) support ok
*** LIBTIFF support not installed
--- FREETYPE2 support ok
*** LITTLECMS2 support not installed
*** WEBP support not installed
--------------------------------------------------------------------
Running selftest:
--- 57 tests passed.
最後執行安裝
[plain] view plain
sudo python setup.py install
④ python2.70有沒有libtiff板塊
python中支持tiff文件處理的是libtiff模塊中的TIFF類,第三方庫
https://pypi.python.org/pypi/libtiff
⑤ 如何讓opencv2.4和opencv3共存
OpenCV2和OpenCV3是目前主流的兩個版本,有些程序使用OpenCV2,同時有些程序使用了OpenCV3,但是OpenCV2和OpenCV3的API和結構並不完全相同,比如在OpenCV3以後,SIFT和SURF之類的屬性被移到了contrib中了,因此我們需要在一台計算機上同時安裝並使用多個版本OpenCV。
二、 安裝OpenCV2和OpenCV3
1. 安裝依賴庫
安裝官方要求必選包:
sudo apt-get install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev1
安裝官方可選包:
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev1
添加對OpenGL的支持所需要的包:
sudo apt-get install freeglut3-dev mesa-common-dev libgtkglext1 libgtkglext1-dev1
安裝視頻處理所需的包
sudo apt-get install checkinstall yasm libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev libtbb-dev libqt4-dev libgtk2.0-dev libmp3lame-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils ffmpeg1
優化opencv的功能包
sudo apt-get install libatlas-base-dev gfortran qt5-default qtcreator1
2.下載源代碼
下載OpenCV2.4.13.3源代碼:
git clone https://github.com/opencv/opencv/tree/2.4.13.31
下載OpenCV3.3.0源代碼:
git clone https://github.com/opencv/opencv/tree/3.3.01
下載OpenCV3.3.0_contrib源代碼:
git clone https://github.com/opencv/opencv_contrib/tree/3.3.01
2.安裝OpenCV2和OpenCV3 (無CUDA版本)
安裝OpenCV2.4.13.3
$ cd opencv-2.4.13.3/
$ mkdir build
$ cd build
$ cmake -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr/local/opencv2 \
-DWITH_TBB=ON \
-DWITH_IPP=ON \
-DWITH_QT=ON \
-DWITH_GTK=ON \
-DWITH_V4L=ON \
-DWITH_LIBV4L=ON \
-DWITH_OPENGL=ON \
-DWITH_FFMPEG=ON \
-DBUILD_EXAMPLES=ON \
-DINSTALL_PYTHON_EXAMPLES=ON \
-DINSTALL_C_EXAMPLES=ON \
-DPYTHON_EXECUTABLE=/usr/bin/python \
-DPYTHON_INCLUDE_DIR=/usr/include/python2.7 \
-DPYTHON_INCLUDE_DIR2=/usr/include/x86_64-linux-gnu/python2.7 \
-DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython2.7.so \
-DPYTHON_NUMPY_INCLUDE_DIRS=/usr/lib/python2.7/dist-packages/numpy/core/include/ ..
$ make -j $(($(nproc) + 1))
$ sudo make
安裝OpenCV3.3.0:
首先將OpenCV3.3.0_contrib-3.3.0放到opencv-3.3.0目錄下,然後執行下面命令。
$ cd opencv-3.3.0/
$ mkdir build
$ cd build
$ cmake -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr/local/opencv3 \
-DOPENCV_EXTRA_MODULES_PATH=/home/bdd/opencv-3.3.0/opencv_contrib-3.3.0/moles \
-DWITH_TBB=ON \
-DWITH_QT=ON \
-DWITH_GTK=ON \
-DWITH_V4L=ON \
-DWITH_LIBV4L=ON \
-DWITH_OPENGL=ON \
-DWITH_FFMPEG=ON \
-DBUILD_EXAMPLES=ON \
-DINSTALL_PYTHON_EXAMPLES=ON \
-DINSTALL_C_EXAMPLES=ON \
-DPYTHON_EXECUTABLE=/usr/bin/python \
-DPYTHON_INCLUDE_DIR=/usr/include/python2.7 \
-DPYTHON_INCLUDE_DIR2=/usr/include/x86_64-linux-gnu/python2.7 \
-DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython2.7.so \
-DPYTHON_NUMPY_INCLUDE_DIRS=/usr/lib/python2.7/dist-packages/numpy/core/include/ ..
$ make -j $(($(nproc) + 1))
$ sudo make
其中OPENCV_EXTRA_MODULES_PATH:指定的OpenCV3.3.0_contrib路徑
⑥ python pil 怎麼安裝
關於Pillow與PIL
PIL(Python Imaging Library)是Python一個強大方便的圖像處理庫,名氣也比較大。不過只支持到Python 2.7。
PIL官方網站:http://www.pythonware.com/procts/pil/
Pillow是PIL的一個派生分支,但如今已經發展成為比PIL本身更具活力的圖像處理庫。目前最新版本是3.0.0。
Pillow的Github主頁:https://github.com/python-pillow/Pillow
Pillow的文檔(對應版本v3.0.0):https://pillow.readthedocs.org/en/latest/handbook/index.html
Pillow的文檔中文翻譯(對應版本v2.4.0):http://pillow-cn.readthedocs.org/en/latest/
Python 3.x 安裝Pillow
給Python安裝Pillow非常簡單,使用pip或easy_install只要一行代碼即可。
在命令行使用PIP安裝:
pip install Pillow
或在命令行使用easy_install安裝:
easy_install Pillow
安裝完成後,使用from PIL import Image就引用使用庫了。比如:
from PIL import Image
im = Image.open("bride.jpg")
im.rotate(45).show()
⑦ linux python libtiff庫怎麼安裝
1. 先安裝pip b) 獲取上面網址的get-pip.py c) 運行python get-pip.py d) 安裝完成之後 pip應用程序安裝在C:\Python27\Scripts目錄下,把這個路徑加到path環境變數裡面 e) cmd-》 輸入pip -》可看到命令幫助,表示安裝成功
⑧ 如何執行python第三方包windows exe格式
python第三方包的windows安裝文件exe格式, 這上面有很多python第三方包的二進制安裝文件,包括32位和64位的。下載安裝就ok了!
這下面有很多python第三方包的二進制安裝文件,包括32位和64位的。下載安裝就ok了!
包括了mysqldb,ldap等。
Index by date:
fiona
scikit-image
netcdf4
mercurial
scikits.audiolab
numba
llvmpy
python-igraph
rpy2
numpy
opencv
zope.interface
sfepy
quantlib
gdal
imread
django
psychopy
cx_freeze
msgpack
regex
cellcognition
vigra
scikit-learn
pytables
h5py
blender-mathutils
htseq
bioformats
simplejson
pyzmq
mako
simpleitk
qimage2ndarray
ujson
vlfd
libsvm
liblinear
cgkit
scipy
distribute
noise
theano
pyalembic
openimageio
pyaudio
pymca
pyamg
pgmagick
lxml
steps
sqlalchemy
cffi
biopython
python-ldap
pycurl
nipy
nibabel
pygments
mahotas
py-postgresql
pyamf
planar
holopy
pyvisa
jcc
polymode
polygon
cython
pyropes
llist
shapely
vtk
pymongo
libpython
meshpy
pandas
umysql
epydoc
coverage
cheetah
pyrxp
pybluez
pythonmagick
bsdiff4
pymssql
pymol
boost.python
orange
requests
pywcs
python-sundials
pymix
pyminuit
pylzma
pyicu
assimulo
basemap
pygraphviz
pyproj
mpi4py
spyder
pytz
pyfits
mysql-python
pygame
pycparser
twisted
pil
qutip
openexr
nipype
python-snappy
visvis
docutils
pyhdf
pyqwt
kivy
scikits.umfpack
psycopg
ets
guiqwt
veusz
pyqt
pyside
dpmix
py-fcm
scikits.hydroclimpy
smc.freeimage
scipy-stack
ipython
nose
mxbase
numexpr
pyyaml
ode
virtualenv
aspell_python
tornado
pywavelets
bottleneck
networkx
statsmodels
pylibdeconv
pyhook
lmfit
slycot
ndimage
scikits.scattpy
cvxopt
pymc
pysparse
scikits.odes
matplotlib
vpython
pycuda
pyopencl
pymvpa
pythonnet
cld
mod_wsgi
nltk
python-levenshtein
rtree
pywin32
scientificpython
sympy
thrift
pyopengl-accelerate
mdp
pyopengl
gmpy
reportlab
natgrid
scikits.vectorplot
pyreadline
milk
blosc
pycogent
pip
gevent
scons
carray
python-dateutil
jinja2
markupsafe
jsonlib
pysfml
fonttools
silvercity
console
python-cjson
pycluster
cdecimal
pytst
autopy
sendkeys
ceodbc
fipy
psutil
pyephem
pycifrw
blist
line_profiler
pydbg
bitarray
pyglet
python-lzo
faulthandler
delny
pyexiv2
ilastik
twainmole
scitools
pyspharm
casuarius
pyodbc
greenlet
nitime
pylibtiff
mmtk
pycairo
pysqlite
curses
videocapture
bazaar
nlopt
trfit
libsbml
oursql
sphinx
cellprofiler
py2exe
re2
liblas
cgal-python
pymedia
ffnet
pyfftw
libxml-python
pyfltk
pymex
pymatlab
zodb3
mmlib
pygtk
pyserial
babel
scikits.ann
scikits.delaunay
numeric
pulp
nmoldyn
pymutt
iocbio
jpype
wxpython
pybox2d
dipy
mmseg
pynifti
scikits.samplerate
scikits.timeseries
vitables
quickfix
⑨ python 3.6中如何引用libtiff包
先要安裝pip install numpy
再安裝pip install libtiff
不過需要編譯環境,安裝好後就可以引用了