【Linux开发】OpenCV在ARM-linux上的移植过程遇到的问题4---共享库中嵌套库带路径【已解决】

【Linux开发】OpenCV在ARM-linux上的移植过程遇到的问题4—共享库中嵌套库带路径【已解决】

标签:【Linux开发】


紧接着上一篇,我居然又尝试了一下编译opencv,主要是因为由于交叉编译ARM-Linux,opencv,好像刚开始make install路径的问题,让我宿主机Ubuntu14.04上的opencv链接库被交叉编译库给冲掉,然后在宿主机上运行本机的Opencv程序时候居然报错了,imread似乎运行不正确。后来重新编译OpenCv,结果原来的可以运行namedWindow的程序已经不能运行了,爆出的错误就是GTK没有移植上去,所以highgui的imshow等不能用了,不过还好,这样就保持跟ARM板卡上的opencv一样的配置。


接着就是解决交叉编译后的共享库嵌套包含../../lib/路径的问题,其实真的是无话可说,查看了这么多的技术博文,最后就找到了一个能够解决问题的,而且他也是犯了一大堆的错误,最后发现问题就是在设置configure CMake的时候,操作系统不要跟着网上的走填写什么arm-linux,直接填写Linux就好,仍然使用交叉编译工具,然后configure之后就不会出现CMake不识别系统的问题。这样将信将疑的配置了下去,中间也是出现了一堆的问题,当然主要是有些东西没有屏蔽掉,比如1394的,cuda的,tiff的,ocl的,opencl的等,同时为了保证opencv移植后能够进行capture.read(frame),选中了WITH_V4L。具体的配置如下:

这里写图片描述

这里写图片描述

当然这里参考了《ARM + OpenCV 抓取摄像头图像 && 一点感想
中的内容,同时把他的内容粘贴过来如下:

使用前一篇中所述的配置方法,搭建出的基于arm-linux 的 OpenCV 对USB摄像头进行图像抓取,后面进一步会抓取视频。一开始抓取不了视频,VideoCapture 对象无法获取 /dev/video0 的设备。解决问题的思路贴下来,无耐心可跳过直接看最后:

VideoCapture打不开 isOpened 返回 false。
查看开发板的系统是否支持V4L2, multimedia -- > 内核配置
查看OpenCV编译的时候是否勾选了V4L2选项
初步定位到 OpenCV编译 cmake时选择 WITH_V4L 
OpenCV 2.4.9 + Ubuntu 12.04 : cmake-gui 中没有 WITH_V4L 或者 WITH_LIBV4L 这个选项
/usr/include/linux/ videodev.h videdev2.h 这个貌似没问题(待定)

OpenCV 2.4.3 在我的机器上试验,cmake-gui中依然没有 WITH_V4L选项,但是室友的机器上是有的,排除OpenCV安装包版本的问题,可能存在机器配置差异的问题。
安装libv4l-dev试试 —— 重新配置cmake-gui中的Cache,找不到V4L相关的值
安装 libv4l* —— 重新配置cmake-gui中的Cache,找不到V4L相关的值

opencv-2.4.9/cmake/OpenCVCmakeFindLibsVideo.cmake :
ocv_clear_vars(HAVE_LIBV4L HAVE_CAMV4L HAVE_CAMV4L2 HAVE_VIDEOIO)
if(WITH_V4L)
    if(WITH_LIBV4L)
        CHECK_MUDULE(libv4l1 HAVE_LIBV4L)
    endif()
    CHECK_INCLUDE_FILE(linux/videodev.h HAVE_CAMV4L)
    CHECK_INCLUDE_FILE(linux/videodev2.h HAVE_CAMV4L2)
    CHECK_INCLUDE_FILE(sys/videoio.h HAVE_VIDEOIO)
endif(WITH_V4L)

opencv-2.4.9/modules/highgui/src/ 下有 cap_v4l.cpp:
#ifdef HAVE_CAMV4L2
#include<asm/types.h>
#include<linux/videodev2.h>
#endif

配置PC机端OpenCV的cmake-gui,具有WITH_LIBV4L和WITH_V4L选项,推测和指定的交叉编译器有关。
换了交叉编译器 arm-2011.03 依然无效。
cmake-gui 进行 configure 的时候,选择第三项 Specify toolchain file for cross-compiling 时,出现了 V4L 选项。但编译生成出来的是PC端的文件。

拷贝一个videodev.h到交叉工具链中的/lib,然后删除并重新建立编译目录,重新配置即可 ——不通过
v4l-utils 可能还需要在开发板上配置该 lib

配置MX53,menuconfig 发现缺少 V4L2 的支持,只有V4L 的支持


cmake-gui 配置,target-system :Linux version:2.6.35

最后,配置target-system 时,以前受网上文章误导,写的是 arm-linux,这就导致 cmake 无法识别目标系统的类型,只有写 Linux 时,cmake 才识别出目标系统的类型,使得cmake-gui出现和PC端相同的选项,带有WITH_V4L和WITH_LIBV4L 。这里只需要勾选WITH_V4L 即可。勾选WITH_LIBV4L 后面交叉编译时可能会出现错误,暂时还未解决。在仅勾选WITH_V4L 的情况下,交叉编译时可能会出现缺少头文件的错误,将本机的 libv4l1.h libv4l1-videodev.h libv4l2,h libv4lconvert,h 四个文件拷贝到交叉编译工具的include 文件目录下即可。

感想:包括CSDN在内的网上有很多技术文章都具有很好的学习和参考价值,但是大部分人在写技术文章的同时可能只是记录一下整个过程,对于一些技术细节不能全部掌握,这样读者在看文章的时候跟着照做就可能出现文章中未指出或作者未遇到的问题。比如cmake的一些东西不太懂,导致摄像头采集图像的实验拖了很久,非常浪费时间。所以更需要看一些讲述原理性的文章,有利于举一反三,想想在实际做的时候是否涉及到,对于少遇到问题,解决问题都有很大的好处。

我是从我的宿主机的/usr/include路径把这几个文件copy到了我的交叉编译工具链中的include文件夹中:

root@huty-virtual-machine:~# cd /usr/include/
root@huty-virtual-machine:/usr/include# ls
af_vfs.h       complex.h     dlg_config.h      fstab.h             highgui.h       ldap_features.h     libyasm-stdint.h  netax25         pcrecpp.h           sched.h        tar.h         wait.h
aio.h          cpio.h        dlg_keys.h        fts.h               ibus-1.0        ldap.h              limits.h          netdb.h         pcre.h              scsi           tbb           wchar.h
aliases.h      crypt.h       drm               ftw.h               ibus-anthy-1.0  ldap_schema.h       link.h            neteconet       pcreposix.h         SDL            termcap.h     wctype.h
alloca.h       ctype.h       elf.h             _G_config.h         ibus-qt         ldap_utf8.h         linux             netinet         pcre_scanner.h      search.h       term_entry.h  wordexp.h
alsa           cucul.h       endian.h          gconv.h             iconv.h         ldif.h              locale.h          netipx          pcre_stringpiece.h  semaphore.h    term.h        X11
argp.h         curl          envz.h            gcrypt.h            idna.h          libavcodec          ltdl.h            netiucv         php5                setjmp.h       termio.h      x264-10bit
argz.h         cursesapp.h   err.h             gcrypt-module.h     idn-free.h      libavformat         lzma              netpacket       pixman-1            sgtty.h        termios.h     x264_config.h
ar.h           cursesf.h     errno.h           gdk-pixbuf-2.0      idn-int.h       libavutil           lzma.h            netrom          pngconf.h           shadow.h       tgmath.h      x264.h
arpa           curses.h      error.h           getopt.h            ifaddrs.h       libdrm              malloc.h          netrose         png.h               signal.h       theora        x86_64-linux-gnu
asm-generic    cursesm.h     esd.h             gettext-po.h        inttypes.h      libgen.h            math.h            nfs             poll.h              slang.h        thread_db.h   xcb
assert.h       cursesp.h     et                gio-unix-2.0        jasper          libintl.h           mcheck.h          nl_types.h      pr29.h              slcurses.h     tic.h         xen
atk-1.0        cursesw.h     eti.h             GL                  jbig85.h        libio.h             memory.h          nss.h           printf.h            sound          time.h        xf86drm.h
audiofile.h    cursslk.h     etip.h            glib-2.0            jbig_ar.h       libltdl             menu.h            numpy           profile.h           spawn.h        tld.h         xf86drmMode.h
aupvlist.h     cvaux.h       execinfo.h        glob.h              jbig.h          libpng              mirclient         obstack.h       protocols           stab.h         ttyent.h      xine
autosprintf.h  cvaux.hpp     expat_external.h  gnu                 jerror.h        libpng12            mircommon         ogg             pthread.h           stdc-predef.h  turbojpeg.h   xine.h
avahi-client   cv.h          expat.h           gnutls              jmorecfg.h      libraw1394          mit-krb5          opencore-amrnb  pty.h               stdint.h       uapi          xlocale.h
avahi-common   cv.hpp        faaccfg.h         gnu-versions.h      jpegint.h       librtmp             ml.h              opencore-amrwb  pulse               stdio_ext.h    uchar.h       xorg
bits           cvwimage.h    faac.h            google              jpeglib.h       libswscale          mntent.h          opencv          punycode.h          stdio.h        ucontext.h    xvid.h
byteswap.h     cxcore.h      fcntl.h           gpg-error.h         kadm5           libtasn1.h          monetary.h        opencv2         pwd.h               stdlib.h       ulimit.h      zlib.h
c++            cxcore.hpp    features.h        grp.h               kdb.h           libv4l1.h           mqueue.h          opencv.hpp      python2.7           string.h       unctrl.h
caca0.h        cxeigen.hpp   fenv.h            gshadow.h           krb5            libv4l1-videodev.h  mtd               OpenEXR         qt4                 stringprep.h   unistd.h
caca_conio.h   cxmisc.h      FlexLexer.h       gssapi              krb5.h          libv4l2.h           nautilus-sendto   openssl         rdma                strings.h      ustat.h
caca.h         dbus-1.0      fmtmsg.h          gssapi.h            lame            libv4l2rds.h        nc_tparm.h        p11-kit-1       re_comp.h           stropts.h      utime.h
caca++.h       dc1394        fnmatch.h         gssrpc              langinfo.h      libv4lconvert.h     ncurses_dll.h     panel.h         regex.h             sudo_plugin.h  utmp.h
caca_types.h   dialog.h      fontconfig        gstreamer-0.10      lastlog.h       libv4l-plugin.h     ncurses.h         pango-1.0       regexp.h            sys            utmpx.h
cairo          dirent.h      form.h            gtk-2.0             lber.h          libxml2             net               paths.h         resolv.h            syscall.h      values.h
cifsidmap.h    dlfcn.h       fpu_control.h     gtk-unix-print-2.0  lber_types.h    libyasm             netash            pciaccess.h     rpc                 sysexits.h     video
com_err.h      dlg_colors.h  freetype2         harfbuzz            ldap_cdefs.h    libyasm.h           netatalk          pcrecpparg.h    rpcsvc              syslog.h       vorbis

具体的路径是:

root@huty-virtual-machine:/opt/Ti-Am4378/Toolchain/gcc-linaro-arm-linux-gnueabihf-4.7-2013.03-20130313_linux/arm-linux-gnueabihf/include/c++/4.7.3# ls
algorithm            cassert   cinttypes  condition_variable  cstdint  cwctype    fenv.h            ios                 libv4l2.h        mutex     random            stdexcept     tr2            utility
arm-linux-gnueabihf  ccomplex  ciso646    csetjmp             cstdio   cxxabi.h   forward_list      iosfwd              libv4lconvert.h  new       ratio             streambuf     tuple          valarray
array                cctype    climits    csignal             cstdlib  debug      fstream           iostream            limits           numeric   regex             string        typeindex      vector
atomic               cerrno    clocale    cstdalign           cstring  decimal    functional        istream             list             ostream   scoped_allocator  system_error  typeinfo
backward             cfenv     cmath      cstdarg             ctgmath  deque      future            iterator            locale           parallel  set               tgmath.h      type_traits
bits                 cfloat    complex    cstdbool            ctime    exception  initializer_list  libv4l1.h           map              profile   sstream           thread        unordered_map
bitset               chrono    complex.h  cstddef             cwchar   ext        iomanip           libv4l1-videodev.h  memory           queue     stack             tr1           unordered_set
root@huty-virtual-machine:/opt/Ti-Am4378/Toolchain/gcc-linaro-arm-linux-gnueabihf-4.7-2013.03-20130313_linux/arm-linux-gnueabihf/include/c++/4.7.3# 

不管怎样,通过上面的方法,真的解决了libopencv_highgui.so中的../../lib/路径的问题。


下面是我的Ubuntu14.04宿主机自己的opencv CMake时候的配置。做一下备份,回头在不同的宿主机上上编译源码时可以作为参考。不然就得一个一个的试着来,每次发现一个错误,编译了一半,然后重新ccmake .,导致浪费时间。

这里写图片描述

这里写图片描述

这里写图片描述


2016-8-30 0:17
张朋艺 pyZhangBIT2010@126.com

原文地址:https://www.cnblogs.com/huty/p/8518217.html