#下載 opencv source code
git clone https://github.com/Itseez/opencv
#列出所有 tag
cd opencv
git tag
# source code 退回 2.4.2 版本
git reset --hard 2.4.2
# 將 cmake build 到 release 資料夾
mkdir release
cd release
# 可自行修改 library 安裝路徑 EX. /home/user/opencv2.4.2
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/home/user/opencv2.4.2 ..
# 開始 compile
make
# 如果 compile 有這個 bug (modules/highgui/src/cap_ffmpeg_impl.hpp:845:10: error: use of enum ‘CodecID’ without previous declaration)
# 請用 sed 取代修復 bug 後再重新 compile
sed -i 's/CodecID/AVCodecID/g' ../modules/highgui/src/cap_ffmpeg_impl.hpp && make
# 安裝 library 到安裝路徑
make install
# vim ~/.bashrc export LD_LIBRARY_PATH=library安裝路徑/lib:$LD_LIBRARY_PATH 並立即更新
vim ~/.bashrc
export LD_LIBRARY_PATH=/home/user/opencv2.4.2/lib:$LD_LIBRARY_PATH
source ~/.bashrc