opencv git倉庫地址:
https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv.git
cd opencv/
git checkout tags/2.4.13
mkdir build
cd build/
#已將opencv3安裝到/usr/local,防止衝突,將opencv2安裝到/usr下
cmake \
-DCMAKE_BUILD_TYPE=RELEASE \
-DCMAKE_INSTALL_PREFIX=/usr \
\
-DWITH_CUDA=OFF \
\
-DBUILD_DOCS=OFF \
-DBUILD_EXAMPLES=OFF \
-DBUILD_TESTS=OFF \
-DBUILD_PERF_TESTS=OFF \
-D ENABLE_PRECOMPILED_HEADERS=OFF \
..
make -j4
sudo make install
cmake時,報錯:
Q1:linux/videodev.h not found
R1:
sudo ln -s /usr/include/libv4l1-videodev.h /usr/include/linux/videodev.h
Q2:sys/videoio.h not found
R2:
sudo cp /usr/include/opencv2/videoio/videoio_c.h /usr/include/x86_64-linux-gnu/sys
sudo ln -s /usr/include/x86_64-linux-gnu/sys/videoio_c.h /usr/include/x86_64-linux-gnu/sys/videoio.h
Q3:ffmpeg/avformat.h not found
R3:
sudo ln -s /usr/local/include/libavformat ffmpeg
參考:OpenCV-3編譯安裝方法及常見錯誤解決(Ubuntu平臺)
Q4: /usr/include/c++/7/cstdlib:75:15: fatal error: stdlib.h: 沒有那個檔案或目錄
R4:
cmake的時候後面加上:
-DENABLE_PRECOMPILED_HEADERS=OFF
make時報錯:
O5:/usr/bin/ld: /usr/local/lib/libavcodec.a(vc1dsp_mmx.o): relocation R_X86_64_PC32 against symbol `ff_pw’ can not be used when making a shared object; recompile with -fPIC
R5:
make -j CFLAGS=-fPIC