2017年2月26日 星期日

OpenCV cross compile for BBB

 I had been thinking of using OpenCV on embedded devices long time ago. OpenCV is a very powerful free image processing library, developers can use the library to process their images without writing the algorithm from scratch.
 There are 2 methods to compile and install OpenCV on BBB. The first one is to download, compile and install OpenCV directly on BBB, I won't use this method since this method is very time consuming and you need to re-compile again whenever you have a new BBB. The second method is what I am going to explain in this article; in this method, I downloaded and compiled OpenCV on my Linux host computer then install the library to my BBB.
 The host OS I used is Ubuntu Linux, this is also the system I used to cross-compiled my BBB programs.  Before we start cross-compiling OpenCV library,

 Cmake_gui is a very powerful tool to help user to generate necessary file for cross-compiling, in this article I use cmake_gui to demonstrate crsoo-compile of OpenCV.
The steps to cross compile OpenCV is shown below,
  1. Download OpenCV source code for Linux from www.opencv.com, the version I downloaded is OpenCV3.1.0 
  2. Unzip downloaded OpenCV file. 
  3. Create another directory named OpenCV_build (Fig. 1)
  4. Download cmake_gui by typing atp-get install cmake_gui from Linux console. 
  5. Click on cmake_gui, cmake_gui will pop up shown in figure 2. In "where is source code" filed, select unzipped OpenCV source folder from step 2. 
In "where to build the sources", select the new directory created in step 3.
  1. Click on "Configure" button, then select "Unix Makefiles" and "Specify options for cross-compiling" to specify cross-compile tool chain shown in figure 3 then click next. 
  2. Specify crsoo-compile tool chain shown in figure 4, c compiler is under /your-compiler-directory/bin/gcc, c++ compiler is under /your-compiler-directory/bin/g++ and target root is under /your-compiler-directory/bin, enter Linux in "Operating System" filed then click finish. 
  3. In "Install_prefix" field shown inf figure 2, select /usr/local/bin. In "config_file_include_dir", select the directory in step 3 then click "Generate". 
  4. Enter directory created in step 3, type make then make install to compile and install OpenCV library, the entire compilation time may vary from different machines, in my case, 1 hour. 
  5. After compilation is done, you will find OpenCV library in /usr/local/lib directory, this means you have done compilation. 
Fig. 1






                                     Fig. 2

                                      Fig. 3 


                                     Fig. 4

Copy all related libraries from host side to ARM. 

  1. Copy files in /usr/local/lib on host side to /usr/local/lib on ARM 
  2. Copy files in /usr/local/include on host side to /usr/local/include on ARM
  3. Copy files in /usr/local/bin on host side to /usr/local/bin on ARM
  4. Copy files in /usr/local/share on host side to /usr/local/share on ARM.
This is done for cross-compile OpenCV, in the next post, I will explain how to write an simple OpenCV application for ARM. 

















沒有留言:

張貼留言