Linux under cross-compilation OpenCV

Source: Internet
Author: User

Through nearly a week when finally successfully cross-compiling OPENCV success, really not easy. There is a word is truth also, everything expensive in insist. The process is always painful, because do not know a lot of problems but also need to face many problems, the biggest harvest is to patiently solve all the problems to understand these.

1. Why cross-compiling OPENCV?

Before the naïve, thought that after installing the OpenCV on Ubuntu, if GCC through the compilation, then directly arm-linux-g++ well, it turns out I was really naïve.

The reason to cross-compile OpenCV is because at compile time, GCC and ARM-LINUX-GCC need to call the library is not the same, although the name is the same. As for why, I guess the compiled executable is running in a different environment, so the library to be linked when compiling is certainly not the same.

2. Why Choose opencv2.3.1

To tell the truth is very difficult, from opencv2.4.10 to opencv2.4.9 to opencv1.0, these three versions are not successful cross-compiling, later had to continue to try, finally in the fourth version of opencv2.3.1 success. You are insisting.

First, the development environment

Homestay Host Ubuntu12.04

Cross compiler: arm-linux-gcc4.5.1 (friendly arm)

cmake-2.8.7-linux-i386.sh

Second, compiling OPENCV

1. Unzip

Decompression opencv2.3.1 to any directory, my compressed package was placed under/home/ljy-linux/, directly decompression

#tar JXVF opencv-2.3.1a.tar.bz

2. Go to the source directory and modify

Why to modify, because there will be errors in the installation, so directly modified the

Modify the source code on line 63rd of the Opencv-2.3.1/modules/flann/include/opencv2/flann/dist.h file: Change ABSL () to ABS ()

#cd opencv-2.3.1/modules/flann/include/opencv2/flann/

#vi dist.h

Save when you're done modifying

3. Running Cmake-gui

Build two directories before running

#cd/usr/local

#mkdir Arm

#mkdir Opencv-arm

Directory arm is used to install Opencv,opencv-arm as a cross-compiled working directory

#cmake-gui

Select Source Code directory:/home/ljy-linux/opencv-2.3.1

Choose the build directory:/usr/local/opencv-arm/

Click Configure, keep generator for Unix makefiles, select specify options for Cross-compiling, click Next
Operating System Fill Arm-inux
C compilers fill in/USR/LOCAL/ARM/FRIENDLYARM/4.5.1/BIN/ARM-LINUX-GCC
C + + compilers fill in/usr/local/arm/friendlyarm/4.5.1/bin/arm-linux-g++
Library target root fill in the/USR/LOCAL/ARM/FRIENDLYARM/4.5.1/and click Finish

Modify the default configuration, the default installation directory is/usr/local, change the cmake_install_prefix variable to/usr/local/arm/
Remove the With_tiff (if you don't need to, be sure to tick off)

Click Configure again

Then click Generate to generate makefile

4. Compiling and installing

Before compiling, modify the CMakeCache.txt.

#cd/usr/local/opencv-arm

#vi CMakeCache.txt

Cmake_exe_linker_flags originally empty, plus-LPTHREAD-LRT

Start compiling

#make

Install after full compilation is complete

#make Install

5. Write a simple test program, open the camera and create a window to display

Test.cpp

#include <cv.h>

#include <cxcore.h>

#include

int main ()

{

cvcapture* capture = NULL;

iplimage* frame = NULL;

if (! ( Capture = Cvcapturefromcam (-1)))

{

fprintf (stderr, "Can not open camera./n");

return-1;

}

Cvnamedwindow ("video", 1);

while (frame = cvqueryframe (capture))

{

Cvshowimage ("video", frame);

}

Cvdestroywindow ("video");

Cvreleasecapture (&capture);

return 0;

}

6. Compiling the connection test program

arm-linux-g++-i/usr/local/arm/include/opencv/-l/usr/local/arm/lib//libopencv_imgproc.so-l/usr/local/arm/lib// Libopencv_core.so-l/usr/local/arm/lib//libopencv_flann.so-l/usr/local/arm/lib//libopencv_highgui.so-l/usr/ Local/arm/lib//libopencv_ml.so-lpthread-lrt-o Test Test.cpp

There seems to be some warning, first ignored.

7. Put on arm to run

Put the previously compiled library files onto the board before you can run them on the boards.

Originally on the board to create the same path, and later found that can not run, prompted not to find the library file, and then think directly to the Lib all. so file under the root directory of the/lib, run again, succeeded.

Similarly, you should simply put the compiled library files together in the system library file on the ARM board.

8. Success is only half the

Run is successful, the compiled library has been successfully called, but the arm board hints that the lack of interface creation, it is probably the meaning, so also need some interface to open the window and so on, you can use QT and so on. Because the interface of the friendly arm arm board is written in Qt, the next step is to learn about QT programming and then add OPENCV and then open the camera on the arm board and show it.

Linux under cross-compilation OpenCV

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.