ubuntu安装opencv3.10遇到的坑

本文介绍在Ubuntu系统中编译安装OpenCV 2.4.8过程中遇到的问题及解决办法,包括配置cmake时的参数调整、依赖库的查找与配置等。

1. ubuntu编译opencv3.10的过程可以参考下面博客

http://blog.youkuaiyun.com/cumt08113684/article/details/53006376#

2. make过程中可能会出现以下问题

fatal error: Eigen/Eigenvalues: No such file or directory

在cmake的时候可以加上WITH_EGEN=OFF

 

sudo cmake -D CMAKE_BUILD_TYPE=RELEASE -D WITH_EIGEN=OFF -D CMAKE_INSTALL_PREFIX=/usr/local/opencv/3.10 .. 

今天试了开源代码(KFsion)但是opencv要2.4.8,所以安装流一下,但是opencv2.4.8运行报错了,如下:

flycloud@E60-Server:~/下载/opencv-2.4.8/build$ cmake .. -Wno-dev
CMake Error at cmake/OpenCVDetectCXXCompiler.cmake:85 (list):
  list GET given empty list
Call Stack (most recent call first):
  CMakeLists.txt:77 (include)


CMake Error at cmake/OpenCVDetectCXXCompiler.cmake:86 (list):
  list GET given empty list
Call Stack (most recent call first):
  CMakeLists.txt:77 (include)


CMake Error at cmake/OpenCVDetectCXXCompiler.cmake:89 (math):
  math cannot parse the expression: "*100 + ": syntax error, unexpected
  exp_TIMES, expecting exp_PLUS or exp_MINUS or exp_OPENPARENT or exp_NUMBER
  (1)
Call Stack (most recent call first):
  CMakeLists.txt:77 (include)


-- Detected version of GNU GCC:  ()
-- Could NOT find Jasper (missing: JASPER_LIBRARIES JASPER_INCLUDE_DIR) 
-- Found OpenEXR: /usr/lib/x86_64-linux-gnu/libIlmImf.so
-- checking for module 'gstreamer-base-0.10'
--   package 'gstreamer-base-0.10' not found
-- checking for module 'libv4l1'
--   package 'libv4l1' not found
-- Looking for linux/videodev.h
-- Looking for linux/videodev.h - not found
-- Looking for linux/videodev2.h
-- Looking for linux/videodev2.h - found
-- Looking for sys/videoio.h
-- Looking for sys/videoio.h - not found
-- Looking for libavformat/avformat.h
-- Looking for libavformat/avformat.h - found
-- Looking for ffmpeg/avformat.h
-- Looking for ffmpeg/avformat.h - not found
-- CUDA detected: 8.0
-- CUDA NVCC target flags: -gencode;arch=compute_11,code=sm_11;-gencode;arch=compute_12,code=sm_12;-gencode;arch=compute_13,code=sm_13;-gencode;arch=compute_20,code=sm_20;-gencode;arch=compute_20,code=sm_21;-gencode;arch=compute_30,code=sm_30;-gencode;arch=compute_35,code=sm_35;-gencode;arch=compute_30,code=compute_30
-- Could NOT find JNI (missing: JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH) 
-- 
-- General configuration for OpenCV 2.4.8 =====================================
--   Version control:               unknown
-- 
--   Platform:
--     Host:                        Linux 4.13.0-46-generic x86_64
--     CMake:                       3.9.1
--     CMake generator:             Unix Makefiles
--     CMake build tool:            /usr/bin/make
--     Configuration:               Release
-- 
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ Compiler:                /usr/bin/c++  (ver 7.2.0)
--     C++ flags (Release):         -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -msse3 -ffunction-sections -O3 -DNDEBUG  -DNDEBUG
--     C++ flags (Debug):           -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -msse3 -ffunction-sections -g  -O0 -DDEBUG -D_DEBUG
--     C Compiler:                  /usr/bin/cc
--     C flags (Release):           -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -msse3 -ffunction-sections -O3 -DNDEBUG  -DNDEBUG
--     C flags (Debug):             -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -msse3 -ffunction-sections -g  -O0 -DDEBUG -D_DEBUG
--     Linker flags (Release):
--     Linker flags (Debug):
--     Precompiled headers:         YES
-- 
--   OpenCV modules:
--     To be built:                 core flann imgproc highgui features2d calib3d ml video legacy objdetect photo gpu ocl nonfree contrib python stitching superres ts videostab
--     Disabled:                    world
--     Disabled by dependency:      -
--     Unavailable:                 androidcamera dynamicuda java
-- 
--   GUI: 
--     QT:                          NO
--     GTK+ 2.x:                    YES (ver 2.24.31)
--     GThread :                    YES (ver 2.54.1)
--     GtkGlExt:                    NO
--     OpenGL support:              NO
-- 
--   Media I/O: 
--     ZLib:                        /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.11)
--     JPEG:                        /usr/lib/x86_64-linux-gnu/libjpeg.so (ver )
--     PNG:                         /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.6.34)
--     TIFF:                        /usr/lib/x86_64-linux-gnu/libtiff.so (ver 42 - 4.0.8)
--     JPEG 2000:                   build (ver 1.900.1)
--     OpenEXR:                     /usr/lib/x86_64-linux-gnu/libImath.so /usr/lib/x86_64-linux-gnu/libIlmImf.so /usr/lib/x86_64-linux-gnu/libIex.so /usr/lib/x86_64-linux-gnu/libHalf.so /usr/lib/x86_64-linux-gnu/libIlmThread.so (ver 2.2.0)
-- 
--   Video I/O:
--     DC1394 1.x:                  NO
--     DC1394 2.x:                  YES (ver 2.2.5)
--     FFMPEG:                      YES
--       codec:                     YES (ver 57.89.100)
--       format:                    YES (ver 57.71.100)
--       util:                      YES (ver 55.58.100)
--       swscale:                   YES (ver 4.6.100)
--       gentoo-style:              YES
--     GStreamer:                   NO
--     OpenNI:                      NO
--     OpenNI PrimeSensor Modules:  NO
--     PvAPI:                       NO
--     GigEVisionSDK:               NO
--     UniCap:                      NO
--     UniCap ucil:                 NO
--     V4L/V4L2:                    NO/YES
--     XIMEA:                       NO
--     Xine:                        NO
-- 
--   Other third-party libraries:
--     Use IPP:                     NO
--     Use Eigen:                   YES (ver 3.3.4)
--     Use TBB:                     NO
--     Use OpenMP:                  NO
--     Use GCD                      NO
--     Use Concurrency              NO
--     Use C=:                      NO
--     Use Cuda:                    YES (ver 8.0)
--     Use OpenCL:                  YES
-- 
--   NVIDIA CUDA
--     Use CUFFT:                   YES
--     Use CUBLAS:                  NO
--     USE NVCUVID:                 NO
--     NVIDIA GPU arch:             11 12 13 20 21 30 35
--     NVIDIA PTX archs:            30
--     Use fast math:               NO
-- 
--   OpenCL:
--     Version:                     dynamic
--     Include path:                /home/flycloud/下载/opencv-2.4.8/3rdparty/include/opencl/1.2
--     Use AMD FFT:                 NO
--     Use AMD BLAS:                NO
-- 
--   Python:
--     Interpreter:                 /usr/bin/python2 (ver 2.7.14)
--     Libraries:                   /usr/lib/x86_64-linux-gnu/libpython2.7.so (ver 2.7.14)
--     numpy:                       /home/flycloud/.local/lib/python2.7/site-packages/numpy/core/include (ver 1.14.0)
--     packages path:               lib/python2.7/dist-packages
-- 
--   Java:
--     ant:                         NO
--     JNI:                         NO
--     Java tests:                  NO
-- 
--   Documentation:
--     Build Documentation:         NO
--     Sphinx:                      NO
--     PdfLaTeX compiler:           NO
-- 
--   Tests and samples:
--     Tests:                       YES
--     Performance tests:           YES
--     C/C++ Examples:              NO
-- 
--   Install path:                  /usr/local
-- 
--   cvconfig.h is in:              /home/flycloud/下载/opencv-2.4.8/build
-- -----------------------------------------------------------------
-- 
-- Configuring incomplete, errors occurred!
See also "/home/flycloud/下载/opencv-2.4.8/build/CMakeFiles/CMakeOutput.log".
See also "/home/flycloud/下载/opencv-2.4.8/build/CMakeFiles/CMakeError.log".

官方链接:

sir, this error puzzled me for some hours and i found this github page. i will take OpenCV2.4.13 as example, in file opencv2.4.13/cmake/ OpenCVDetectCXXCompiler.cmake, u have to change "dumpversion" to "dumpfullversion"

explanation is that in gcc with higher version, dumpversion function can't get true full version number of compiler so that cmake progress will fail.

 

<think>嗯,用户需要了解Ubuntu系统安装OpenCV库的方法。从提供的引用资料来看,已经搜集了多篇博客资源,包含从基础安装到Qt配置的多种方法。 用户可能正在开发计算机视觉项目,需要快速搭建环境。引用[1]和[5]详细说明了依赖库安装,引用[2]和[4]则涉及Qt集成,这些都很实用。不过注意到引用[3]提到新手容易陷入依赖问题,所以安装步骤需要特别清晰。 准备按照标准流程组织回答:先安装依赖库,接着下载源码编译,最后配置环境变量。对于常见的权限问题(如/usr/local权限不足)和版本冲突问题(多版本共存),需要给出明确解决方案。Qt配置部分虽然用户没直接问,但考虑到引用多次提及,也应该包含。 用户可能还会关心版本选择(如OpenCV 4.x能否兼容Python3.10)、验证安装的测试方法,这些都要在回答中覆盖。编译过程中的多线程优化(make -j参数)能节省时间,也值得强调。 </think>以下是在Ubuntu系统上安装OpenCV库的详细步骤(以OpenCV 4.x为例): ### 一、安装依赖库 ```bash sudo apt update sudo apt install -y build-essential cmake git pkg-config libgtk-3-dev \ libavcodec-dev libavformat-dev libswscale-dev libv4l-dev \ libxvidcore-dev libx264-dev libjpeg-dev libpng-dev libtiff-dev \ gfortran libatlas-base-dev python3-dev python3-numpy \ libtbb2 libtbb-dev libdc1394-22-dev libopenexr-dev \ libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev ``` > **关键提示**:完整安装依赖可避免后续编译错误[^1][^5] ### 二、下载源码并编译 ```bash mkdir ~/opencv_build && cd ~/opencv_build git clone https://github.com/opencv/opencv.git git clone https://github.com/opencv/opencv_contrib.git cd opencv mkdir build && cd build ``` 配置编译参数(关键步骤): ```bash cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D INSTALL_C_EXAMPLES=ON \ -D INSTALL_PYTHON_EXAMPLES=ON \ -D OPENCV_GENERATE_PKGCONFIG=ON \ -D OPENCV_EXTRA_MODULES_PATH=~/opencv_build/opencv_contrib/modules \ -D BUILD_EXAMPLES=ON .. ``` 开始编译(根据CPU核心数调整-j参数): ```bash make -j$(nproc) # 使用所有CPU核心加速编译 sudo make install sudo ldconfig # 更新动态链接库缓存 ``` > **编译建议**:`-j8`参数可显著提升多核CPU编译速度[^4] ### 三、环境配置 1. 添加pkg-config路径: ```bash echo &#39;export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig&#39; >> ~/.bashrc source ~/.bashrc ``` 2. 验证安装: ```bash pkg-config --modversion opencv4 # 应显示版本号 ``` ### 四、测试安装 创建Python测试脚本`test_opencv.py`: ```python import cv2 print(f"OpenCV版本: {cv2.__version__}") img = cv2.imread("test.jpg") if img is not None: cv2.imshow("TestWindow", img) cv2.waitKey(0) ``` 运行: ```bash python3 test_opencv.py ``` ### 常见问题解决 1. **视频I/O错误**:安装`libdc1394`相关依赖 ```bash sudo apt install libdc1394-22-dev libxine2-dev ``` 2. **Qt兼容问题**:编译时禁用Qt ```cmake -D WITH_QT=OFF ``` 3. **CUDA支持**:添加编译选项 ```cmake -D WITH_CUDA=ON -D CUDA_ARCH_BIN="你的GPU计算能力版本" ``` > **经验提示**:推荐使用Ubuntu 20.04/22.04 LTS系统避免兼容性问题[^3][^5]
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值