Porting opencv to Ti cortex A8

Source: Internet
Author: User
I have personally tried this, it can be transplanted, and image processing is performed in the embedded Linux system, which is done using opencv.
Building opencv for ARM Cortex-A8Translate this page to building opencv for ARM Cortex-A8

Introduction:

This wiki provides instructions that specify how to build opencv for ARM Cortex-A8 platform using cmake in a Linux environment. the instructions below have been tested for opencv 2.2 by cross compiling it on a Ubuntu 10.04 machine. the toolchain is codesourcery
2010.12.

Build instructions

Opencv 2.2 uses cmake to build. cmake is a meta-makefile system that generates makefiles. We need to install this first.

  • Update Ubuntu to install and setup cmake
  $ sudo apt-get install cmake cmake-curses-gui
  • Download and install codesourcery 2010.12 from
    Http://www.codesourcery.com/sgpp/lite/arm/portal/release1600. Assuming you have installed it in/opt/ARM-2010.12, add/opt/ARM-2010.12/bin to your path
  $ export PATH=$PATH:/opt/arm-2010.12/bin
  • Now download opencv 2.2 from
    Http://opencv.willowgarage.com/wiki/. untar it into your home directory.
  $ tar -jxf OpenCV-2.2.0.tar.bz2
  • Cmake supports building outside the source tree. We will use this method to build opencv. So, create a directory in $ home as build
  $ mkdir ~/build && cd ~/build
  • We need to now create a toolchain. cmake file that we will pass to cmake so that it knows how to cross-compile.
  $ vi toolchain.cmake
  • Add the following to toolchain. cmake and save it. This assumes that your NFS targetfs is ~ /Targetfs
  set( CMAKE_SYSTEM_NAME Linux )  set( CMAKE_SYSTEM_PROCESSOR arm )  set( CMAKE_C_COMPILER arm-none-linux-gnueabi-gcc )  set( CMAKE_CXX_COMPILER arm-none-linux-gnueabi-g++ )  set( CMAKE_FIND_ROOT_PATH ~/targetfs )

Important: The cmake build setup in opencv 2.2 and earlier does not have neon enable flag to take advantage of neon accelearation. hence please make the following modifications to the file cmakelists.txt in opencv 2.2 to enable neon acceleration.

         # Other optimizations          if(USE_O2)                    set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -O2 -mfpu=neon")         endif()

This may not be required in later versions of opencv since opencv 2.3 has the option to enable neon in the cmake build process.

  • Now we run cmake to process and generate makefile
$ Cmake-dcmake_toolchain_file = toolchain. cmake ../OpenCV-2.2.0/cmake-D cmake_build_type = release you can select release
  • When cross compiling for arm, I found that some items do not build. so, we need to use the cmake curses GUI to customize cmake output and re-generate the makefile before we can build. now launch the cmake curses GUI to customize the make file generation
  $ ccmake .
  • This will bring up a screen full of options that can be edited. Make sure that the following items are off. If it is on, You can toggle it by scrolling to the option and hitting Enter

    • Build_new_python_support
    • Build_tests
    • With_1394
    • With_cuda
    • With_eigen2
    • With_ffmpeg
    • With_gstreamer
    • With_gtk
    • With_jasper
    • With_jpeg
    • With_openexr
    • With_png
    • With_pvapi
    • With_qt
    • With_qt_opengl
    • With_tbb
    • With_tiff
    • With_unicap
    • With_v4l
    • With_xine

Note: Do not forget to keep the use_o2 option on in the configuration to take adavntage of neon acceleration that you added to this option

  • Now, press 'C' to configure and 'G' to generate the makefiles again.
  • Now you are ready to build opencv. run make from the command line and it shoshould generate the opencv libraries. you can try to customize the build by turning on the varous options that we disabled earlier and see if it builds for you.

Then make

Make install

Encountered error:

Refer to the following articles

Environment: the ARM development board is ok6410, and the host is ubuntu10.04.

1. Preparation: Use the optical disc arm-linux-4.4.1.tar.gz tool to decompress the tool to the/usr/local/ARM directory (Add/usr/local/ARM/bin to the environment variable). Download The opencv2.2 source code; install cmake build-essential; install necessary libraries: libgtk2.0-dev libavcodec-dev libavformat-dev libswscale-dev libjpeg62-dev libtiff4-dev libjasper-Dev

2. Description of the main directories used:
Cross-compilation tool chain/usr/local/ARM
Location of the compiled opencv Library/usr/local/opencv-arm
Install opencv directory/usr/local/ARM-Linux
Opencv source code ~ /Tiaozhansai/OpenCV-2.2.0

3. Run sudo cmake-Gui on the terminal
Select the source code Directory:/home/Xin/tiaozhansai/OpenCV-2.2.0
Select the build Directory:/usr/local/opencv-arm/
Click Configure, keep generator as UNIX makefiles, select specify options for cross-compiling, and click Next,
Operating System fill in arm-Linux
C compilers fill in/usr/local/ARM/4.4.1/bin/ARM-Linux-gcc
C ++ compilers fill in/usr/local/ARM/4.4.1/bin/ARM-Linux-G ++
Enter/usr/local/ARM/4.4.1/as the target root of the library/
Click Finish.
Modify the default configuration. The default installation directory is/usr/local. To find the generated library file, change the cmake_install_prefix variable to/usr/local/ARM-Linux and click Generate to generate the makefile.

4. In the/usr/local/opencv-arm directory, $ sudo make
(1), 80% error:
.... /Home/Xin/tiaozhansai/OpenCV-2.2.0/modules/ml/src/Gbt. cpp: 474: Error: 'expl' was not declared in this scope

Modify 14 rows in Gbt. cpp, 16 rows: Comment out

// # If android

# Define expl (x) exp (X)
// # Endif
Eliminate errors.

(2) Error 83%:
Linking cxx executable.../../bin/opencv_createsamples
.../../Lib/libopencv_core.so: Undefined reference to 'clock _ gettime'
.../../Lib/libopencv_highgui.so: Undefined reference to '_ assumerrorhandler'
.../../Lib/libopencv_highgui.so: Undefined reference to '_ {realloc'
.../../Lib/libopencv_core.so: Undefined reference to 'pthread _ key_create
Solution: Modify cmakecache.txt, cmake_exe_linker_flags, and add-lpthread-LRT to re-compile and eliminate errors.

(3) Error 83%:
Linking cxx executable.../../bin/opencv_createsamples
.../../Lib/libopencv_highgui.so: Undefined reference to '_ assumerrorhandler'
.../../Lib/libopencv_highgui.so: Undefined reference to '_ {realloc'
.../../Lib/libopencv_highgui.so: Undefined reference to '_ Your malloc'
.../../Lib/libopencv_highgui.so: Undefined reference to '_ Your memcpy'
.../../Lib/libopencv_highgui.so: Undefined reference to 'too open'
.../../Lib/libopencv_highgui.so: Undefined reference to '_ blank free'
.../../Lib/libopencv_highgui.so: Undefined reference to '_ warninghandler'
.../../Lib/libopencv_highgui.so: Undefined reference to '_ too memcmp'
.../../Lib/libopencv_highgui.so: Undefined reference to '_ blank memset'
Solution: Modify cmakecache.txt, with_tiff: bool = on, and change it to off (the TIFF image format is no longer supported. Here I have installed libtiff4-dev before, but the compilation error, I don't understand why), re-compile, error elimination.

(4) Error 96%:
Cmakefiles/opencv_test.dir/src/highguitest. OBJ: In function 'cv _ highguitest: Run (INT )':
Highguitest. cpp :(. Text. _ zn14cv_highguitest3runei + 0x18): warning: the use of 'tmpnam 'is dangerous, better use 'mkstemp'
.../../Lib/libopencv_features2d.so: Undefined reference to 'cv: sift (double, bool, bool, Int, INT )'
Solution: Under opencv2.2.0/modules/features2d/src/sift. cpp
# Ifdef _ arm __
# Define arm_no_sift
# Endif
Comment out # define arm_no_sift. error elimination,
Successful!

$ Sudo make install

5. Copy the opencv library to ok6410 and Test
(1) borrow a test program from a blog to test whether the compilation is successful.
Create test. cpp:
// 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;
}

Compile test. CPP: $ arm-Linux-G ++-I/usr/local/ARM-Linux/include/opencv/-L/usr/local/ARM-Linux/lib/-LCV-lcxcore -lhighgui-lpthread-LRT-O test. CPP
Error:/usr/local/ARM/4.4.1/bin /.. /lib/GCC/ARM-None-Linux-gnueabi/4.4.1 /.. /.. /.. /.. /ARM-None-Linux-gnueabi/bin/ld: cannot find-LCV

Google found that the dynamic library libcv. So was not found.
The find Command finds that this library does not exist in the/usr/local/ARM-Linux/lib/directory, and the libraries under this directory are in the form of libopencv, I guess opencv2.2 has made a lot of changes compared with 2.1. According to the online research, opencv2.2 re-organizes the database structure and replaces cxcore, CV, and cvaux with more detailed and smaller modules, highgui and ML library.
So, try to change the command: $ arm-Linux-G ++-I/usr/local/ARM-Linux/include/opencv/-L/usr/local/ARM-Linux/lib/-lopencv_core-lopencv_highgui -lpthread-LRT-O test. CPP
The result is still a report error. This time I noticed that it is... /ARM-None-Linux-gnueabi /.. Find the dynamic library in this directory. That is to say, although I have specified the header file and the search path of the library file, it does not go to the path I specified. So I copied all the header files under/usr/local/opencv-arm/include/opencv/and the dynamic libraries under/usr/local/opencv-arm/lib to/usr/ local/ARM/4.4.1/ARM-None-Linux-gnueabi directory, then compile:
$ Arm-Linux-G ++-lopencv_core-lopencv_highgui-lpthread-LRT-O test. cpp

Successful!

(2) copy the Library File S and the compiled test program to the Development Board for testing.
An error occurred while copying data with an SD card:
CP: cannot create '.../../lib/libopencv_calib3d.so': Read-Only File System
CP: cannot create '.../../lib/libopencv_contrib.so': Read-Only File System
CP: cannot create '.../../lib/libopencv_core.so': Read-Only File System

This is related to the cramfs file system, which is a read-only file system. You can solve this problem by burning the yaffs file system.

Library Problems

Export LD_LIBRARY_PATH =/opt/opencv8148: $ ld_libr
Ary_path

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.