一、先安装的配置文件 sudo apt-get install build-essential sudo apt-get install cmake sudo apt-get install pkg-config sudo apt-get install libgtk2.0-dev sudo apt-get install libavcodec-dev sudo apt-get install libavformat-dev sudo apt-get install libswscale-dev sudo apt-get install libtiff-dev sudo apt-get install libjasper-dev sudo apt-get install libopencv-dev
二、编译OpenCV源码(先下载opencv2.4.9安装包) sudo unzip opencv-2.4.9.zip cd opencv-2.4.9 sudo mkdir release cd release sudo cmake -DCMAKE_BUILD_TYPE=RELEASE -DWITH_FFMPEG=OFF -DENABLE_PRECOMPILED_HEADERS=OFF -DCMAKE_INSTALL_PREFIX=/usr/local .. /**************************出现错误********************************/ 第一个错误与解决 linux/videodev.h not found sudo apt-get install libv4l-dev sudo ln -s /usr/include/libv4l1-videodev.h /usr/include/linux/videodev.h 第二个错误与解决 sys/videoio.h not found sudo cp /usr/include/opencv2/videoio/videoio_c.h /usr/include/arm-linux-gnueabihf/sys sudo ln -s /usr/include/arm-linux-gnueabihf/sys/videoio_c.h /usr/include/arm-linux-gnueabihf/sys/videoio.h 第三个错误与解决 Cmake error in cmakefile********SMP4300 sudo apt-get install gedit sudo gedit /home/pi/Downloads/opencv-2.4.9/cmake/OpenCVEetectCXXCompiler.cmake 将原文全部删除,改为如下内容,重新执行sudo cmake ****指令
# ----------------------------------------------------------------------------# Detect Microsoft compiler:# ----------------------------------------------------------------------------if(CMAKE_CL_64) set(MSVC64 1)endif()if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") set(CMAKE_COMPILER_IS_GNUCXX 1) set(CMAKE_COMPILER_IS_CLANGCXX 1)endif()if(CMAKE_C_COMPILER_ID STREQUAL "Clang") set(CMAKE_COMPILER_IS_GNUCC 1) set(CMAKE_COMPILER_IS_CLANGCC 1)endif()if("${CMAKE_CXX_COMPILER};${CMAKE_C_COMPILER}" MATCHES "ccache") set(CMAKE_COMPILER_IS_CCACHE 1)endif()# ----------------------------------------------------------------------------# Detect Intel ICC compiler -- for -fPIC in 3rdparty ( UNIX ONLY ):# see include/opencv/cxtypes.h file for related ICC ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/pi/Downloads/opencv-2.4.9/modules/highgui/src/window_QT.cpp:3102:12: note: suggested alternative: ‘GL_RELATIVE_MOVE_TO_NV sudo gedit /home/pi/Downloads/opencv-2.4.9/modules/highgui/src/window_QT.cpp 将GL_PERSPECTIVE_CORRECTION_HINT全部替换成GL_RELATIVE_MOVE_TO_NV 再次执行sudo make install 第二个错误与解决 error**will be never beNULL[-Werror=address] sudo gedit opencv-2.4.9/release/modules/contrib/CMakeFiles/opencv_contrib.dir/flags.make 将-Werror=address删除并保存 再次执行sudo make install /***********************************************************************/ sudo ldconfig 编译安装完成