Raspberry Pi Install OpenCV 4.0.0 (2018.12.05)

本版討論Raspberry PI相關技術開發、設計與應用
回覆文章
inho
文章: 53
註冊時間: 2017-12-08, 23:00

Raspberry Pi Install OpenCV 4.0.0 (2018.12.05)

文章 inho » 2018-02-05, 13:18

參考網站:
1、https://www.pyimagesearch.com/2018/09/2 ... pberry-pi/ (recommended)
2、https://hk.saowen.com/a/50583de6a24dd4f ... 8e6a8232a2
3、https://blog.gtwang.org/iot/raspberry-p ... ll-opencv/

一、更新套件清單並升級
$ sudo apt-get update
$ sudo apt-get dist-upgrade -y
二、建置並安裝編譯 OpenCV 所需要的套件與工具
$ sudo apt-get install build-essential gcc cmake pkg-config
Python相關套件與工具:
$ sudo apt-get install python python-dev python-numpy
圖形視窗程式庫:
$ sudo apt-get install libgtk2.0-dev
音訊視訊的編解碼、錄製、轉換、串流:
$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev
圖檔格式:
$ sudo apt-get install libjpeg-dev libpng-dev libtiff-dev libjasper-dev
IEEE 1394相機介面:
$ sudo apt-get install libdc1394-22-dev
TBB(Intel's Threading Building Blocks):
$ sudo apt-get install libtbb2 libtbb-dev
如果出現錯誤訊息:
E: Unable to locate package libtbb2
E: Package 'libtbb-dev' has no installation candidate
到TBB網站,查詢原始碼檔案的網址,下載並解壓縮,得到含原始碼檔案的目錄,切換進去:
$ wget https://www.threadingbuildingblocks.org ... ss_src.tgz
$ tar zxvf tbb43_20150611oss_src.tgz
$ cd tbb43_20150611oss
上述如果不成功,試試這個版本:tbb43_20150611oss_src.tgz


開始建置,應加上參數:(參考網站:https://raspberrypi.stackexchange.com/q ... spberry-pi)
$ make tbb CXXFLAGS="-DTBB_USE_GCC_BUILTINS=1 -D__TBB_64BIT_ATOMICS=0"
$ cd build
$ cd linux_armv7_gcc_cc4.9.2_libc2.19_kernel4.14.22_release/
$ source tbbvars.sh

以git下載位於GitHub的OpenCV原始碼,得到目錄opencv,切換進去:
$ git clone https://github.com/Itseez/opencv.git
$ cd opencv
$ git checkout 3.4.0

$ mkdir build
$ cd build
執行cmake產生建置需要的設定檔:
$ cmake -DWITH_TBB:BOOL=TRUE -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
然後開始建置:
$ make -j4

二、安裝編譯 OpenCV 所需要的套件:
$ sudo apt-get install build-essential cmake cmake-curses-gui pkg-config libpng12-0 libpng12-dev libpng++-dev libpng3 libpnglite-dev zlib1g-dbg zlib1g zlib1g-dev pngtools libtiff4-dev libtiff4 libtiffxx0c2 libtiff-tools libeigen3-dev
$ sudo apt-get install libjpeg8 libjpeg8-dev libjpeg8-dbg libjpeg-progs ffmpeg libavcodec-dev libavcodec53 libavformat53 libavformat-dev libgstreamer0.10-0-dbg libgstreamer0.10-0 libgstreamer0.10-dev libxine1-ffmpeg libxine-dev libxine1-bin libunicap2 libunicap2-dev swig libv4l-0 libv4l-dev python-numpy libpython2.6 python-dev python2.6-dev libgtk2.0-dev

參考網站:
http://yehnan.blogspot.tw/2015/12/raspb ... pencv.html
官方的安裝步驟:
https://docs.opencv.org/master/d7/d9f/t ... #gsc.tab=0

回覆文章