您好,登錄后才能下訂單哦!
本篇文章為大家展示了怎么在MacOS中安裝Tclip擴展,內容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。
安裝opencv
根據github上的說明,在CentOS上安裝沒有問題,但在我的MacOS上就掛了。
首先遇到的問題就是,opencv安裝不過去。還好,上github下載最新的opencv-2.4.11 安裝成功。
下載地址:https://github.com/Itseez/opencv/releases
使用當前最新版本 OpenCV 2.4.11
安裝依賴
在安裝opencv之前,先安裝一些依賴包:
復制代碼 代碼如下:
brew install gtk+ pkgconfig libpng zlib libjpeg libtiff cmake
提示: brew的安裝使用請參考 http://brew.sh/
安裝opencv
開始安裝 opencv:
復制代碼 代碼如下:
tar zxf opencv-2.4.11.tar.gz
cd opencv-2.4.11
cmake CMakeLists.txt
make && make install
安裝php tclip
先下載:https://github.com/exinnet/tclip/archive/master.zip
然后繼續:
復制代碼 代碼如下:
unzip tclip-master.zip
cd tclip-master/php_ext
phpize
./configure
如果不出意外,到這一步,應該就掛掉了,提示:
復制代碼 代碼如下:
checking for opencv.pc file in default path... found in /usr/lib/pkgconfig
found in /usr/local/lib/pkgconfig
configure: error: no result from pkg-config opencv --libs --cflags opencv
在 Tclip 作者的頁面上 http://www.bo56.com/tclip%E4%BA%BA%E8%84%B8%E8%AF%86%E5%88%AB%E5%9B%BE%E7%89%87%E8%A3%81%E5%89%AA/#download
評論中,也有網友遇到了類似的問題,提出修改辦法為:
將 config.m4 中的 判斷語句test ${i:${#i}-3} = “.so”,改為 test ${i:${#i}-6} = ".dylib”,并嘗試將46行的.so 也改稱 .dylib
依然提示no result的錯誤~
再翻翻config.m4的代碼和執行 pkg-config opencv --libs --cflags opencv的輸出結果:
復制代碼 代碼如下:
-I/usr/local/include/opencv -I/usr/local/include -L/usr/local/lib -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_ocl -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab
感覺怎么對不上,于是跑到Linux安裝成功的服務器執行了一下,輸出結果如下:
復制代碼 代碼如下:
-I/usr/local/include/opencv -I/usr/local/include /usr/local/lib/libopencv_calib3d.so /usr/local/lib/libopencv_contrib.so /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_features2d.so /usr/local/lib/libopencv_flann.so /usr/local/lib/libopencv_gpu.so /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_imgproc.so /usr/local/lib/libopencv_legacy.so /usr/local/lib/libopencv_ml.so /usr/local/lib/libopencv_nonfree.so /usr/local/lib/libopencv_objdetect.so /usr/local/lib/libopencv_photo.so /usr/local/lib/libopencv_stitching.so /usr/local/lib/libopencv_ts.so /usr/local/lib/libopencv_video.so /usr/local/lib/libopencv_videostab.so
再看他的判斷代碼:
復制代碼 代碼如下:
OPENCV_FLAGS="`pkg-config opencv --libs --cflags opencv`"
for i in $OPENCV_FLAGS;do
if test ${i:0:2} = "-I" ;then
PHP_ADD_INCLUDE(${i:2})
elif test ${i:${#i}-3} = ".so" ;then
dir_name=`dirname $i`
file_name=${i/$dir_name/}
file_name=${file_name/\/lib/}
file_name=${file_name/.so/}
PHP_ADD_LIBRARY_WITH_PATH($file_name,$dir_name,TCLIP_SHARED_LIBADD)
else
AC_MSG_ERROR([no result from pkg-config opencv --libs --cflags opencv])
fi
done
我立刻就明白了,Linux上輸出的都是具體的.so路徑,MacOS上都是相對的路徑,而config.m4中是根據具體路徑和擴展名判斷的,明白了問題,解決就簡單了。
將 pkg-config opencv --libs --cflags opencv 的執行結果修改為具體的路徑,并替換到config.m4中:
復制代碼 代碼如下:
OPENCV_FLAGS="-I/usr/local/include/opencv -I/usr/local/include /usr/local/lib/libopencv_calib3d.dylib /usr/local/lib/libopencv_contrib.dylib /usr/local/lib/libopencv_core.dylib /usr/local/lib/libopencv_features2d.dylib /usr/local/lib/libopencv_flann.dylib /usr/local/lib/libopencv_gpu.dylib /usr/local/lib/libopencv_highgui.dylib /usr/local/lib/libopencv_imgproc.dylib /usr/local/lib/libopencv_legacy.dylib /usr/local/lib/libopencv_ml.dylib /usr/local/lib/libopencv_nonfree.dylib /usr/local/lib/libopencv_objdetect.dylib /usr/local/lib/libopencv_photo.dylib /usr/local/lib/libopencv_stitching.dylib /usr/local/lib/libopencv_ts.dylib /usr/local/lib/libopencv_video.dylib /usr/local/lib/libopencv_videostab.dylib"
再繼續執行:
復制代碼 代碼如下:
phpize
./configure
make
make install
上述內容就是怎么在MacOS中安裝Tclip擴展,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。