OpnCV开发经验总结

这篇博客总结了在使用OpenCV开发过程中遇到的两个主要问题:undefined reference to `TIFFXXX@LIBTIFF_4.0’和提示安装libgtk2.0-dev,并详细阐述了解决这些问题的步骤,包括检查依赖、安装缺失库和处理依赖冲突。同时,对CMakeLists.txt中的find_package作用进行了初步分析。
摘要由CSDN通过智能技术生成

常见问题分析解决

使用过程遇到的问题

(1)undefined reference to `TIFFXXX@LIBTIFF_4.0’

错误提示
/usr/local/lib/libopencv_imgcodecs.so.3.3.0: undefined reference to 'TIFFReadDirectory@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.3.0: undefined reference to 'TIFFWriteEncodedStrip@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.3.0: undefined reference to 'TIFFIsTiled@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.3.0: undefined reference to 'TIFFOpen@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.3.0: undefined reference to 'TIFFReadEncodedStrip@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.3.0: undefined reference to 'TIFFSetField@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.3.0: undefined reference to 'TIFFWriteScanline@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.3.0: undefined reference to 'TIFFGetField@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.3.0: undefined reference to 'TIFFScanlineSize@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.3.0: undefined reference to 'TIFFNumberOfStrips@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.3.0: undefined reference to 'TIFFSetWarningHandler@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.3.0: undefined reference to 'TIFFSetErrorHandler@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.3.0: undefined reference to 'TIFFReadEncodedTile@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.3.0: undefined reference to 'TIFFReadRGBATile@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.3.0: undefined reference to 'TIFFClose@LIBTIFF_4.0'

解决步骤:

1.检查是否安装libtiff4-dev
2.尝试使用sudo make
3.重装opencv,在cmake时加入参数-DBUILD_TIFF=ON

(2)提示安装libgtk2.0-dev

错误信息
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 cvNamedWindow, file /home/jellal/Downloads/opencv-3.3.0/modules/highgui/src/window.cpp, line 587
terminate called after throwing an instance of 'cv::Exception'
what(): /home/jellal/Downloads/opencv-3.3.0/modules/highgui/src/window.cpp:587: error: (-2) 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 function cvNamedWindow

解决过程:
1.直接sudo apt install libgtk2.0-dev
提示需要若干依赖, but is not going to install.
2.尝试根据安装所需的依赖,然后成功安装libgtk2.0-dev
3.尝试运行程序,提示缺少libpng16.so.16
4.安装libpng16-dev
5.运行仍然出现上述错误提示,并且可以再次安装libgtk2.0-dev
6.发现是依赖问题,用aptitude安装libgtk2.0-dev,提示需要移除libpng16
小结:libgtk2.0-dev和libpng16-dev冲突
7.利用aptitude安装libgtk2.0-dev后,去下载libpng16的rpm包,利用alien转换为deb包后安装,仍然提示缺少libpng16.so.16
8.sudo updatedb后locate libpng16.so.16,找到目录后,在/etc/ld.so.conf中或者在该文件include的conf文件中加入该目录路径,运行后仍出现最初错误提示
根据相关资料所述,需要在opencv安装前安装gtk2.0
9.故此时重新安装opencv,运行仍然出现最初错误提示
10. sudo apt install libgnomeui-dev ,然后再次重新安装opencv,问题解决

解决过程:
  1. sudo apt install libgnomeui-dev
  2. 重新安装opencv

使用过程中的现象分析

CMakeLists.txt

find_package的作用分析

1.使用过程中发现message可以输出OpenCV_VERSION、OpenCV_LIBS和OpenCV_INCLUDE_DIRS等变量
2.echo测试后发现并非环境变量
3.将message置于find_package之前无输出
小结:find_package作用,一是得到相关变量,二是确定引用的头文件和链接的库目录等,实际作用有待分析

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值