Rhonda Software

Highest quality full cycle software development.

Expert in areas of Computer Vision, Multimedia, Messaging, Networking and others. Focused on embedded software development. Competent in building cross-platform solutions and distributed SW systems.

Offer standalone custom solutions as well as integration of existing products. Opened for outsourcing services.

Visit us at: http://www.rhondasoftware.com

ARM-wrestling with OpenCV

Posted on : 12-03-2009 | By : Igor Stepura | In : OpenCV

122

I played with two ARM9-based single board computers (SBC) recently to investigate how OpenCV would operate on embedded platforms. The SBCs are – TS-7800 and SBC2440-III.

OpenCV uses floating point operations a lot, but not all of the ARM processors have FP coprocessor, so developers should use either some FP library, or as in my case – use Linux kernel FP emulation. There are two types of such emulation OABI and EABI. More details can be found here and here. Kernel release 2.6.16 was the first one to include ARM EABI support.

Unfortunately, CPUs of both SBCs do not support floating point in hardware, but luckily enough, TS-7800 has Debian Linux with 2.6.21 kernel. So I had a chance to compare OpenCV performance for OABI and EABI.

Both SBCs have necessary tool-chains in package – TS-7800 has Linux and Windows(Cygwin) tool-chains, SBC-2440 – only Linux one.  In addition to these I downloaded newer release of Codesourcery ARM tool-chain for Windows, because the one from TS-7800 SW package didn’t work properly with Cygwin.

I wrote a pretty simple script to ease OpenCV (version 1.1pre1 from here) configuration for various toolchains. Here it is:

#!/bin/bash
##======== TS-7800 environment settings======
#### Linux host. EABI complier
#export DEVROOT=/opt/crosstool/arm-none-linux-gnueabi
#export APP_PREFIX=arm-none-linux-gnueabi
#export GCC_HOST=i686-pc-linux-gnu
##-O3 kills gcc : cvpyrsegmentation.cpp:1021: internal compiler error: in verify_local_live_at_start, at flow.c:546
#export OFLAGS=-O2

### Linux host. OABI compiler
#export DEVROOT=/opt/crosstool/arm-linux/gcc-3.3.4-glibc-2.3.2
#export APP_PREFIX=arm-linux
#export GCC_HOST=i686-pc-linux-gnu
##Any optimization causes SEGFAULTS during face detection application execution
#export OFLAGS=-O0

### Windows (Cygwin) host. EABI compiler (Codesourcery 2008q3-72)
export APP_PREFIX=arm-none-linux-gnueabi
export DEVROOT=/opt/crosstool/codesourcery
export CYGPATH=d:/cygwin/bin/cygpath
export GCC_HOST=i686-pc-cygwin

###Windows (Cygwin) host. OABI compiler
#export APP_PREFIX=arm-unknown-linux-gnu
#export DEVROOT=/opt/crosstool/gcc-3.3.4-glibc-2.3.2
#export CYGPATH=d:/cygwin/bin/cygpath
#export GCC_HOST=i686-pc-cygwin
##Any optimization causes SEGFAULTS during face detection application execution
#export OFLAGS=-O0

##======== SBC2440-III environment settings======
####Linux host only. OABI compiler only. (Out of the box kernel does not support EABI)
#export DEVROOT=/usr/local/arm/3.4.1
#export APP_PREFIX=arm-linux
#export GCC_HOST=i686-pc-linux-gnu
##Any optimization causes SEGFAULTS during face detection application execution
#export OFLAGS=-O0
##===============================================

export PATH=$DEVROOT/$APP_PREFIX/bin:$PATH

./configure \
 --target=$APP_PREFIX \
 --host==$APP_PREFIX \
 --build=$GCC_HOST \
 --disable-shared \
 --enable-static \
 --without-imageio  --without-carbon \
 --without-quicktime --without-python \
 --without-gtk --without-swig \
 --without-v4l \
 --disable-apps \
 --prefix=$DEVROOT/$APP_PREFIX \
 CC=$DEVROOT/bin/$APP_PREFIX-gcc \
 CXXFLAGS="-fsigned-char $OFLAGS -pipe" \
 LD=$DEVROOT/bin/$APP_PREFIX-ld \
 CPP=$DEVROOT/bin/$APP_PREFIX-cpp \
 CXXCPP=$DEVROOT/bin/$APP_PREFIX-cpp \
 CXX=$DEVROOT/bin/$APP_PREFIX-g++ \
 AR=$DEVROOT/bin/$APP_PREFIX-ar \
 RANLIB=$DEVROOT/bin/$APP_PREFIX-ranlib \
 NM=$DEVROOT/bin/$APP_PREFIX-nm \
 STRIP=$DEVROOT/bin/$APP_PREFIX-strip \
 AS=$DEVROOT/bin/$APP_PREFIX-as

Just uncomment setting you need, and comment all the others and you’re all set. -fsigned-char in CXXFLAGS is a must. OpenCV will (somehow) work even without this flag, but some functionality will be broken – JPEG parser for example (to say the truth, it will still be broken event with -fsigned-char, but at least it will correctly parse JPEG headers).
After script finished run make and then make install . Libraries and headers will be placed in directory, specified with --prefix= parameter.

Now when OpenCV is built and ready it’s time to “feel the power in your ARMs”.

I used facedetect sample application (/samples/c/) to test OpenCV on SBCs. I had to remove UILib -related code and add ome more parameter to application, named --extension, which allows specifying of input file type (BMP, YML, JPG). Changes I made to file can be observed here
The makefile I sued to build the application is written in a way similar to the previous configure script:

# TS-7800 environment settings
#DEVROOT=/opt/crosstool/arm-none-linux-gnueabi
#APP_PREFIX=arm-none-linux-gnueabi
#SBC2440-III environment settings
#DEVROOT=/usr/local/arm/3.4.1
#APP_PREFIX=arm-linux
#CodeSourcery setup
DEVROOT=/opt/crosstool/codesourcery
APP_PREFIX=arm-none-linux-gnueabi

CC = $(DEVROOT)/bin/$(APP_PREFIX)-g++
CPP = $(DEVROOT)/bin/$(APP_PREFIX)-cpp
LD=$(DEVROOT)/bin/$(APP_PREFIX)-ld

CXXFLAGS = -I"$(DEVROOT)/$(APP_PREFIX)/include" -I"$(DEVROOT)/$(APP_PREFIX)/include/opencv"
CXXFLAGS+= -fsigned-char
LDFLAGS = -static -L"$(DEVROOT)/$(APP_PREFIX)/lib" -lcv -lhighgui -lcxcore -lml -lcvaux -lpthread -ldl

all: facedetect.o
$(CC) facedetect.o $(LDFLAGS) -o facedetect

facedetect.o:
$(CC) $(CXXFLAGS) -c facedetect.c

clean:
rm -f facedetect facedetect.o

Copy and paste this text to a file, say makefile_facedetect, and then use it: make -f makefile_facedetect. It will build statically linked executable – I didn’t want to bother with shared OpenCV libraries.
The file used to detect face was lena.jpg (512×512) from OpenCV samples/c/ directory. I also converted it to BMP and YML, since JPEG parser does not work properly on ARM.
Execution results
TS-7800
EABI build: detection time = 31 512.1ms

SBC-2440-III
OABI build: detection time = 448 151 ms

Conclusions:
1) EABI is MUCH better than OABI
2) Even with EABI FP support, there is still much needed to be improved in OpenCV to make it usable on ARM processors.

Comments (122)

hi igor!
i need to know how to run opencv in arm . i am not using linux i working on windows 32-bit.

Please help me ..
I can’t compile opencv1.1pre

make all-recursive
make[1]: Entering directory `/home/kowunnako/build/opencv-1.1.0′
Making all in cxcore
make[2]: Entering directory `/home/kowunnako/build/opencv-1.1.0/cxcore’
Making all in src
make[3]: Entering directory `/home/kowunnako/build/opencv-1.1.0/cxcore/src’
/bin/sh ../../libtool –tag=CXX –mode=compile arm-none-linux-gnueabi-g++ -DHAVE_CONFIG_H -I. -I../.. -I. -I../../cxcore/include -I../.. -DNDEBUG -I/opt/4.4.3/include -Wall -fno-rtti -pipe -O3 -fomit-frame-pointer -O0 -MT cxalloc.lo -MD -MP -MF .deps/cxalloc.Tpo -c -o cxalloc.lo cxalloc.cpp
arm-none-linux-gnueabi-g++ -DHAVE_CONFIG_H -I. -I../.. -I. -I../../cxcore/include -I../.. -DNDEBUG -I/opt/4.4.3/include -Wall -fno-rtti -pipe -O3 -fomit-frame-pointer -O0 -MT cxalloc.lo -MD -MP -MF .deps/cxalloc.Tpo -c cxalloc.cpp -o cxalloc.o
In file included from _cxcore.h:60:0,
from cxalloc.cpp:42:
../../cxcore/include/cxmisc.h:133:6: error: #elif with no expression
make[3]: *** [cxalloc.lo] Error 1
make[3]: Leaving directory `/home/kowunnako/build/opencv-1.1.0/cxcore/src’
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/home/kowunnako/build/opencv-1.1.0/cxcore’
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/kowunnako/build/opencv-1.1.0′
make: *** [all] Error 2

thank

Hi ,
I’m a novice at embedded software & want to build an application for my AT91SAM9261-EK ARM board.
Its an image processing application which I intend to write using OpenCV. I’m not very sure how do I build & run it on the embedded board. I have flashed Angstrom linux-2.6.30 onto the board.
please suggest the way ahead ..:)

Igor ,,thx a lot .
your answer for these question help me a lot

Hello Igor
I want to compile and openCV in my ARM9 board and to send the captured frames to the network
Is the openCV that compiled on the ARM is doing a compression on the data ?

Hello Igor
I want to compile openCV in my ARM9 board and to send the captured frames to the network
Is the openCV that compiled on the ARM is doing a compression on the data ?

Hi Igor
Is the openCV that compiled on the ARM is doing a data compression ?
Thanks

Hi
Igor
we are configuring open cv 2.0.0 with arm-linux-gcc 4.4.3v for mini 2440 we are getting following errors.pls help me to rectify the errors.

/arm-none-linux-gnueabi/lib -Wl,-rpath -Wl,/usr/local/arm/opt/FriendlyARM/toolschain/4.4.3/bin/../lib/gcc/arm-none-linux-gnueabi/4.4.3/../../../../arm-none-linux-gnueabi/lib
/usr/local/arm/opt/FriendlyARM/toolschain/4.4.3/bin/../lib/gcc/arm-none-linux-gnueabi/4.4.3/../../../../arm-none-linux-gnueabi/bin/ld: cannot find -lgtk-x11-2.0
collect2: ld returned 1 exit status
make[2]: *** [opencv-haartraining] Error 1
make[2]: Leaving directory `/OpenCV-2.0.0/apps’
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/OpenCV-2.0.0′
make: *** [all] Error 2

Hi
Igor
we are configuring open cv 2.0.0 with arm-linux-gcc 4.4.3v for mini 2440 we are getting following errors.pls help me to rectify the errors.

/arm-none-linux-gnueabi/lib -Wl,-rpath -Wl,/usr/local/arm/opt/FriendlyARM/toolschain/4.4.3/bin/../lib/gcc/arm-none-linux-gnueabi/4.4.3/../../../../arm-none-linux-gnueabi/lib
/usr/local/arm/opt/FriendlyARM/toolschain/4.4.3/bin/../lib/gcc/arm-none-linux-gnueabi/4.4.3/../../../../arm-none-linux-gnueabi/bin/ld: cannot find -lgtk-x11-2.0
collect2: ld returned 1 exit status
make[2]: *** [opencv-haartraining] Error 1
make[2]: Leaving directory `/OpenCV-2.0.0/apps’
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/OpenCV-2.0.0′
make: *** [all] Error 2

Hii Igor
I am trying to port opencv on DM355 using montavista crosscompiler toolchain. Can you guide me , how to configure and link the compiler.Iam using Opensuse11.1 linux platform.
Thank you in advance

Hi, I am new in hardware field, please tell me whether opencv files are compatible with Embest AT91SAM9G45, ARM9 board or not?

For those of you trying to build OpenCV for arm platform may find this useful :https://github.com/praveenofpersia/OpenCV-2.4.9-for-arm

Write a comment