Anda di halaman 1dari 3

Pleasechoose'ViewSource'inyourbrowsertoviewtheHTML,orFile|Savetosavethisfileto

yourharddriveforediting.
Introduction
ThisarticledescribesmethodtocompileC/C++libraryformobiledeviceswhichuseAndroidOS.
InstallationandCodeCompilation
BeforeProceedingmakesurethatyouhaveallthebelowsoftwarecomponentsinstalledandconfiguredin
Eclipse
EclipseIDE
AndroidSDK
Eclipse>Window>Preferences>Android>setpathtoSDK
AndroidNDK
Eclipse>Window>Preferences>Android>NDK>setpathtotheNDK
ADTandNDKpluginforEclipse
InstallAndroidSDK+NDKPluginsfromEclipseupdatesitehttps://dl
ssl.google.com/android/eclipse/
EclipseCDTforC/C++support
InstallCDTfromEclipseupdatesitehttp://download.eclipse.org/tools/cdt/releases/indigo.
DevelopethecodeonDesktopComputerandcheckifyouareabletocompileitproperlywithouterrors.
Thepresentexampleconsistsoffilescontainingfollowingclasses
UniStrokeGestureRecognizer
UniStrokeGesture
GesturePoint
ThelibrarylibOpenVision.sohasbeensuccessfullycompiledontheUbuntuOSandnowweproceedwith
crosscompilationofthelibraryforARMbasedmobiledeviceswhichusetheAndroidOS.
CrossCompilation
ThesimplestapproachtodothisistousetheEclipseIDE.TheEclipseIDEprovidesfeaturesforadding
nativeC/C++supporttoanexistingAndroidbasedproject.
TheprojectnameisAndroidGesture.RightclickonanAndroidprojectand
selectAndroidTools>Addnativesupport.
AndenterthedesiredlibrarynameasOpenVision
ThiswillconfiguretheAndroidProjectforthenativebuild.CreateajnifolderwithOpenVision.cppfileand
associatedAndroid.mkmakefile
CopythealltheC/C++projectfilesinthejnifolderandthenproceedtomodifytheAndroid.mkfileto
configurefornativebuild.
CreateadirectorycalledOpenVisioninthejnidirectory
CopyallofthefollowingfilesintheImageAppsubdirectory
UniStrokeGestureRecognizer.cpp
UniStrokeGestureRecognizer.hpp
UniStrokeGesture.cpp
UniStrokeGesture.hpp
GesturePoint.cpp
GesturePoint.hpp
CopythefileOpenCVCommon.hppintheCommonSubdirectory
ThepresetcodeusesOpenCVlibraries.CopytheattachedOpenCVprecompiledlibrariesforARMinthe
libs/armeabiandlibs/armeabi2directories.
MakeFiles
belowarethecontentsofAndroid.mkfile.Thisfileislikeastandardmakefilecontainingtheinclude
paths,sourcefiles,librarydependenciesetc.Fewofthesyntaxesarespecifictoandroidbuildand
explainationisprovidedinthecomments
Android.mkfile
LOCAL_PATH:=$(callmydir)
include$(CLEAR_VARS)
#nameofthelibrarytobebuilt
LOCAL_MODULE:=OpenVision
#listofsourcefilestobebuildaspartofthelibrary
LOCAL_SRC_FILES:=ImgApp/GesturePoint.cppImgApp/UniStrokeGesture.cppImgApp/UniStrokeGestureRecognizer.cpp
#listofdependent3rdpartyorexternallibrariesareincludedintheLOCAL_SHARED_LIBRARYvariable
LOCAL_SHARED_LIBRARIES:=$(foreachmodule,$(OPENCV_LIBS3),opencv_$(module))
OPENCV_MODULES3:=coreimgprocflanncontribfeatures2dvideohighguilegacymlobjdetect
OPENCV_LIBS3:=$(OPENCV_MODULES3)
#listofdependentsystemlibraries
LOCAL_LDLIBS+=fPICllogldllmlzlmlclgccWl,rpath,'libs/armeabiv7a'
LOCAL_LDLIBS+=L$(LOCAL_PATH)/../libs/armeabillogLlibs/armeabiv7a/
#includepathforheaderfilesforCandC++applications
LOCAL_C_INCLUDES+=/usr/local/include/usr/local/include/opencv2/home/pi19404/repository/OpenVision/OpenVision
LOCAL_CPP_INCLUDES+=/usr/local/include/usr/local/include/opencv2/home/pi19404/repository/OpenVision/OpenVision
#ThecompilationflagsforC/C++applications
LOCAL_CPPFLAGS+=DHAVE_NEONfPICDANDROIDI/usr/local/include/opencvI/usr/local/includeI/OpenVisionI/home/pi19404/repository/OpenVision/OpenVisionfPIC
LOCAL_CFLAGS+=DHAVE_NEONfPICDANDROIDI/usr/local/include/opencvI/usr/local/includeI/OpenVisionI/home/pi19404/repository/OpenVision/OpenVisionfPIC
LOCAL_CPP_FEATURES+=exceptions
#statementspecifiesbuildofasharedlibrary
include$(BUILD_SHARED_LIBRARY)
#filesinthelibs/armeabiaredeletedduringeachbuild
#weneedtohave3rdpartyopencvlibrariesinthisdirectory
#thefilesareplacedinthearmeabi2directory
#wheneveranativebuildistriggedtheopencvlibraryfilesspecifiedintheOPENCV_MODULES2
#variablearecopiedfromthearmeabi2directorytothearmeabiorarmeabiv7adirectory
#asperthespecificationofAPP_ABIintheApplication.mkfile
include$(CLEAR_VARS)
OPENCV_MODULES2:=calib3dcontribcorefeatures2dflannhighguiimgproclegacymlnonfreeobjdetectphotostitchingvideovideostab
OPENCV_LIBS2:=$(OPENCV_MODULES2)
OPENCV_LIB_SUFFIX:=so
OPENCV_LIB_TYPE:=SHARED
defineadd_opencv_module1
include$(CLEAR_VARS)
LOCAL_PATH:=libs/armeabi2
LOCAL_MODULE:=aaaopencv_$1
LOCAL_SRC_FILES:=libopencv_$1.$(OPENCV_LIB_SUFFIX)
include$(PREBUILT_$(OPENCV_LIB_TYPE)_LIBRARY)
endef
$(foreachmodule,$(OPENCV_LIBS2),$(eval$(calladd_opencv_module1,$(module))))
Application.mkmakefile
APP_ABI:=armeabiv7aarmeabi
APP_STL:=gnustl_static
APP_PLATFORM:=android8
APP_CPPFLAGS:=frttifexceptionsftreevectorizemfpu=neonO3mfloatabi=softfpffastmath
AfterbuildingtheprojectthelibOpenVision.sofilescanbefoundinthelibs/armeabiandlibs/armeabiv7a
directories.Thesehavebeencrosscompiledforuseonandroidbaseddevices.
ThesecannowbeloadedandcalledfromjavaapplicationusingJNIInterface
Files
TheprecompiledopencvlibrariesforAndroidcanbefoundatwww.github.com/pi19404/OpenCVAndroid
ThesourceandmakefilesusedabovecamebefoundintheOpenVisionrepositoryat
www.github.com/pi19404/OpenVision
TheAndroid.mkandApplication.mkfilesandcontentsofjnidirectorycanbefoundbelow
DownloadSource5.6KB