ubuntu安装OpenCV 及遇到的问题

本文提供了一份详细的OpenCV 3.4.0安装与配置指南,包括依赖包安装、编译选项设置、常见错误解决方法等内容。涉及CUDA、Qt等高级特性启用步骤,以及解决C++内部错误、imshow函数未实现等问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1. sudo apt-get install build-essential
  2. sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev qtbase5-dev libtiff-dev
  3. mkdir -p opencv-3.4.0 build
  4. cd opencv-3.4.0/build
  5. cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_CUDA=ON -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D BUILD_EXAMPLES=ON -D WITH_OPENGL=ON -D ENABLE_FAST_MATH=1 -D CUDA_FAST_MATH=1 -D WITH_CUBLAS=1 -D WITH_NVCUVID:BOOL=1 -D WITH_GSTREAMER=ON -D WITH_FFMPEG=ON -D WITH_QT=ON ..
    :在cmake时会去下载dnn模块的人脸模型,10M多点,不过下载速度比较慢,如果你之前下载过,可直接将模型 res10_300x300_ssd_iter_140000.caffemodel复制到文件夹**xx/opencv-3.4.0/samples/dnn/face_detector/**中。
  6. make -j6//(run 6 jobs in parallel,但最好不要超过cpu核数,不然可能会出现错误)
    :本人在make时会遇到C++内部错误,不用管它,再次make可继续编译,具体原因不知
  7. sudo make install
  8. 在执行imshow函数时,出现如下error
    OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvShowImage, file /home/nvidia/Documents/opencv-3.4.0/modules/highgui/src/window.cpp, line 611 terminate called after throwing an instance of cv::Exception
    解决方法:在cmake时加入-D WITH_QT=ON 选项
  9. 在-D WITH_QT=ON 编译时,出现如下error
    error: #error Please include the appropriate gl headers before including cuda_gl_interop.h
    解决办法:修改文件/usr/local/cuda-8.0/targets/aarch64-linux/include/cuda_gl_interop.h如下,注释掉第8-12及第14行即可
7.#else /* __APPLE__ */
8.//#if defined(__arm__) || defined(__aarch64__)
9.//#ifndef GL_VERSION
10.//#error Please include the appropriate gl headers before including cuda_gl_interop.h
11.//#endif
12.//#else
13.#include <GL/gl.h>
14.//#endif
15.#endif /* __APPLE__ */
  1. 读取视频时,出现error
    Unable to stop the stream: Inappropriate ioctl for device
    解决方法:安装ffmpeg
    sudo apt-get install ffmpeg
    sudo apt-get install libavcodec-dev libavformat-dev libavdevice-dev 注:必须要装才行
    在cmake时能看到如下显示,则说明cmake使用ffmpeg编译成功
    在这里插入图片描述
  2. error:calling a constexpr __host__ function("abs") from a __device__ function("abs") is not allowed. The experimental flag '--expt-relaxed-constexpr' can be used to allow this.
    解方法:添加编译选项-D CUDA_NVCC_FLAGS=--expt-relaxed-constexpr
  3. error:libopencv_imgcodecs.so.3.4.5: undefined reference to TIFFReadRGBAStrip@LIBTIFF_4.0
    解决方法:sudo apt install libtiff-dev
  4. undefined reference to cv::softdouble::operator
    解决办法:这是由于链接库顺序的问题,将libopencv_core.so放到最后
  5. undefined reference to __itt_metadata_add_ptr__3_0
    解决方法:链接上3rdparty/lib/libittnotify
  6. undefined reference to cvRemap
    undefined reference to cvInitUndistortRectifyMap
    undefined reference to cvConvertMaps
    解决办法:在cmake 时添加-DWITH_1394=OFF编译选项
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值