交叉编译并移植opencv3.0.0到arm板

项目需求,交叉编译opencv,并移植到arm中。

在opencv2.0以上的版本编译都要借助于cmake工具生成Makefile
2.0一下版本才是使用configure生成Makefile
请确保宿主机已经安装cmake和cmake-gui工具,如果请自行安装

sudo apt-get install cmake cmake-qt-gui  cmake-curses-gui
  • 1

开发环境
开宿主机:Fedora9.0
交叉编译器:友善之臂arm-linux-gcc4.4.3
自动化编译工具: cmake version 2.8.12.2

编译


下载opencv源代码

项目官网:http://opencv.org/
下载地址:http://opencv.org/downloads.html
这里写图片描述
源码我放置在自己目录的/opencv/opev3.0.0-src
期望的构建目录在/opencv/opencv3-build
期望的安装目录是/opt/arm/opencv/opencv3-arm

cmake配置生成makefile


运行cmake的图形化工具cmake-gui

sudo cmake-gui
  • 1

这里写图片描述
选择源代码目录/opencv/opev3.0.0-src
选择Build目录/opencv/opencv3-build,大家根据自己设置配置编译目录

点击Configure或者Generator
选择Unix Makefiles,
接着选择Specify options for cross-compiling,

1. 列表内容
点击Next,接着开始配置交叉编译环境的信息

Operating System填写arm-inux
C Compilers填写您交叉编译器arm-linux-gcc命令的地址
C++ Compilers填写arm-linux-g++的地址

程序库的Target Root填写交叉编译器的bin目录,

这里写图片描述

然后点击Finish,您的配置信息就出来的
这里写图片描述
注意默认的安装路径为 修改默认配置,默认安装目录为/usr/local
但是我们交叉编译的来说并不合适,这样会替换我们宿主机上原有的库,
所以我把CMAKE_INSTALL_PREFIX变量改为/opt/arm/opencv/opencv3-arm

这里写图片描述

好了最后点击Configure进行配置,然后点击Gennerate就会生成Makefile

make编译并且安装

sudo make
sudo make install 
  • 1
  • 2

出现问题


我们刚才的配置其实肯定是有问题的,因为一堆依赖库没有配置链接参数,但是我们又不知道需要哪些库,所以我们只能等待出现问题进行解决。

pthread


报错

Linking CXX executable ../../bin/opencv_test_calib3d
../../lib/libopencv_core.so: undefined reference to `pthread_key_create'
../../lib/libopencv_core.so: undefined reference to `pthread_getspecific'
../../lib/libopencv_ts.so: undefined reference to `pthread_key_delete'
../../lib/libopencv_core.so: undefined reference to `pthread_once'
../../lib/libopencv_core.so: undefined reference to `clock_gettime'
../../lib/libopencv_core.so: undefined reference to `pthread_setspecific'
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

很明显是pthread的库,

解决

修改/opt/opencv3-build目录下的CMakeCache.txt
CMAKE_EXE_LINKER_FLAGS原来为空,加上-lpthread -lrt

dlfcn


问题

undefined reference to `dlerror'
undefined reference to `dlopen'
  • 1
  • 2

解决

CMAKE_EXE_LINKER_FLAGS继续加上-ldl

parallel_pthreads_set_threads_num

问题

undefined reference to `dlerror'
undefined reference to `dlopen'
  • 1
  • 2
Linking CXX executable ../../bin/opencv_perf_core
../../lib/libopencv_core.so: undefined reference to `parallel_pthreads_set_threads_num(int)'
../../lib/libopencv_core.so: undefined reference to `parallel_pthreads_get_threads_num()'
../../lib/libopencv_core.so: undefined reference to `parallel_for_pthreads(cv::Range const&, cv::ParallelLoopBody const&, double)'
  • 1
  • 2
  • 3
  • 4
  • 5

解决

这个是编译工具链的问题,解决了快一天
后来重要找到了解决方案Fixed compilation of pthread-based parallel_for with gcc 4.4.3

修改modules/core/src/parallel.cpp,自132行开始添加7处删除5处(+表示要添加,-表示要删除)

 namespace cv
 {
     ParallelLoopBody::~ParallelLoopBody() {}
+#if defined HAVE_PTHREADS && HAVE_PTHREADS
+    void parallel_for_pthreads(const cv::Range& range, const cv::ParallelLoopBody& body, double nstripes);
+    size_t parallel_pthreads_get_threads_num();
+    void parallel_pthreads_set_threads_num(int num);
+#endif
 }

+
 namespace
 {
 #ifdef CV_PARALLEL_FRAMEWORK
 @@ -301,7 +307,7 @@ void cv::parallel_for_(const cv::Range& range, const cv::ParallelLoopBody& body,
         }

 #elif defined HAVE_PTHREADS
-        void parallel_for_pthreads(const Range& range, const ParallelLoopBody& body, double nstripes);
+
         parallel_for_pthreads(range, body, nstripes);

 #else
 @@ -361,8 +367,6 @@ int cv::getNumThreads(void)

 #elif defined HAVE_PTHREADS

-        size_t parallel_pthreads_get_threads_num();
-
         return parallel_pthreads_get_threads_num();

 #else
 @@ -424,8 +428,6 @@ void cv::setNumThreads( int threads )

 #elif defined HAVE_PTHREADS

-    void parallel_pthreads_set_threads_num(int num);
-
     parallel_pthreads_set_threads_num(threads);

 #endif
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
同时也可以参考:http://blog.csdn.net/luotuo44/article/details/8958990
                             http://blog.csdn.net/luotuo44/article/details/8909258
                             http://blog.csdn.net/guet_kite/article/details/78667175
展开阅读全文

没有更多推荐了,返回首页