Cross compile and port opencv3.0.0 to arm board

Publisher:InnovateMindLatest update time:2021-08-12 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

question

Project requirements: cross-compile opencv and port it to arm.


In the compilation of opencv2.0 and above, you need to use the cmake tool to generate Makefile

Only versions below 2.0 use configure to generate Makefile

Please make sure that the host machine has installed cmake and cmake-gui tools. If so, please install them yourself.


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


Development Environment

Host machine: Fedora9.0

Cross compiler: friendly arm arm-linux-gcc4.4.3

Automatic compilation tool: cmake version 2.8.12.2


Compile

Download opencv source code

Project official website: http://opencv.org/

Download address: http://opencv.org/downloads.html

Write the picture description here

I put the source code in my own directory /opencv/opev3.0.0-src

The expected build directory is under /opencv/opencv3-build

The expected installation directory is /opt/arm/opencv/opencv3-arm


cmake configuration to generate makefile

Run cmake's graphical tool cmake-gui


sudo cmake-gui

Write the picture description here

Select the source code directory /opencv/opev3.0.0-src

Select Build directory/opencv/opencv3-build, and configure the compilation directory according to your own settings.


Click Configure or Generator

Select Unix Makefiles,

Then select Specify options for cross-compiling,

1. List content

Click Next to start configuring the cross-compilation environment information.


Fill in arm-inux for Operating System

C CompilersFill in the address of your cross compiler arm-linux-gcc command

C++ Compilers fill in the address of arm-linux-g++


The Target Root of the library is filled in with the bin directory of the cross compiler.

Write the picture description here

Then click Finish and your configuration information will be displayed.

Write the picture description here

Note that the default installation path is to modify the default configuration, and the default installation directory is /usr/local

But it is not suitable for cross-compilation, as it will replace the original library on our host machine.

So I changed the CMAKE_INSTALL_PREFIX variable to /opt/arm/opencv/opencv3-arm

Write the picture description here

Okay, finally click Configure to configure, and then click Gennerate to generate the Makefile


Make compile and install

sudo make

sudo make install 


problem appear

There must be something wrong with the configuration we just did, because a bunch of dependent libraries have no configuration link parameters, but we don’t know which libraries are needed, so we can only wait for problems to occur and solve them.


pthread

Report an error

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'


It is obviously the pthread library.


solve

Modify CMakeCache.txt in the /opt/opencv3-build directory

CMAKE_EXE_LINKER_FLAGS was originally empty, add -lpthread -lrt


dlfcn

question

undefined reference to `dlerror'

undefined reference to `dlopen'


solve

CMAKE_EXE_LINKER_FLAGS continues to add -ldl


parallel_pthreads_set_threads_num

question

undefined reference to `dlerror'

undefined reference to `dlopen'


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)'


solve

This is a problem with the compilation tool chain, which was solved in almost a day

Later, I found a solution: Fixed compilation of pthread-based parallel_for with gcc 4.4.3


Modify modules/core/src/parallel.cpp, add 7 places and delete 5 places starting from line 132 (+ indicates to add, - indicates to delete)


 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

Reference address:Cross compile and port opencv3.0.0 to arm board

Previous article:Building QT/Embedded4.8.5 development environment on s3c2410 (VI) --Configuration of QtCreate
Next article:Summary of common error messages of mount nfs

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号