Anda di halaman 1dari 7

OpenCV4AndroidSDK

ThistutorialwasdesignedtohelpyouwithinstallationandconfigurationofOpenCV4AndroidSDK. ThisguidewaswrittenwithMSWindows7inmind,thoughitshouldworkwithGNULinuxandAppleMacOSaswell. Thistutorialassumesyouhavethefollowingsoftwareinstalledandconfigured: JDK AndroidSDKandNDK EclipseIDE ADTandCDTpluginsforEclipse Ifyouneedhelpwithanythingoftheabove,youmayrefertoourIntroductionintoAndroidDevelopmentguide. Ifyouencounteranyerrorafterthoroughlyfollowingthesesteps,feelfreetocontactusviaOpenCV4AndroiddiscussiongrouporOpenCVQ&Aforum. Welldoourbesttohelpyouout.

TegraAndroidDevelopmentPackusers
YoumayhaveusedTegraAndroidDevelopmentPack(TADP)releasedbyNVIDIAforAndroiddevelopmentenvironmentsetup. BesideAndroiddevelopmenttoolstheTADP2.0includesOpenCV4AndroidSDK,soitcanbealreadyinstalledinyoursystemandyoucanskipto RunningOpenCVSamplessectionofthistutorial. MoredetailsregardingTADPcanbefoundintheIntroductionintoAndroidDevelopmentguide.

Generalinfo
OpenCV4AndroidSDKpackageenablesdevelopmentofAndroidapplicationswithuseofOpenCVlibrary. Thestructureofpackagecontentslooksasfollows:
O p e n C V 2 . 4 . 5 a n d r o i d s d k | _a p k | | _O p e n C V _ 2 . 4 . 5 _ b i n a r y _ p a c k _ a r m v 7 a . a p k | | _O p e n C V _ 2 . 4 . 5 _ M a n a g e r _ 2 . 7 _ X X X . a p k | | _d o c | _s a m p l e s | _s d k | | _e t c | | _j a v a | | _n a t i v e | | _3 r d p a r t y | | _j n i | | _l i b s | | _a r m e a b i | | _a r m e a b i v 7 a | | _x 8 6 | | _l i c e n s e . t x t | _R E A D M E . a n d r o i d

s d k foldercontainsOpenCVAPIandlibrariesforAndroid: s d k / j a v a foldercontainsanAndroidlibraryEclipseprojectprovidingOpenCVJavaAPIthatcanbeimportedintodevelopersworkspace s d k / n a t i v e foldercontainsOpenCVC++headers(forJNIcode)andnativeAndroidlibraries(*.soand*.a)forARMv5,ARMv7aandx86 architectures s d k / e t c foldercontainsHaarandLBPcascadesdistributedwithOpenCV. a p k folder contains Android packages that should be installed on the target Android device to enable OpenCV library access via OpenCV ManagerAPI(seedetailsbelow).

OnproductiondevicesthathaveaccesstoGooglePlayMarket(andInternet)thesepackageswillbeinstalledfromMarketonthefirststartofan applicationusingOpenCVManagerAPI.ButdevkitswithoutMarketorInternetconnectionrequirethispackagestobeinstalledmanually.Install theManager.apkandoptionalbinary_pack.apkifitneeded.SeeHowtoselecttheproperversionofOpenCVManagerfordetails. Note: InstallationfromInternetisthepreferablewaysinceOpenCVteammaypublishupdatedversionsofthispackagesontheMarket.


s a m p l e s foldercontainssampleapplicationsprojectsandtheirprebuiltpackages(APK).ImportthemintoEclipseworkspace(likedescribed below)andbrowsethecodetolearnpossiblewaysofOpenCVuseonAndroid. d o c foldercontainsvariousOpenCVdocumentationinPDFformat.Itsalsoavailableonlineathttp://docs.opencv.org.

Note: The most recent docs (nightly build) are at http://docs.opencv.org/trunk/. Generally, its more uptodate, but can refer to notyet releasedfunctionality.

Starting from version 2.4.3 OpenCV4AndroidSDK uses OpenCVManager API for library initialization. OpenCVManager is an Android service basedsolutionprovidingthefollowingbenefitsforOpenCVapplicationsdevelopers: Compactapksize,sinceallapplicationsusethesamebinariesfromManageranddonotstorenativelibswithinthemselves Hardwarespecificoptimizationsareautomaticallyenabledonallsupportedplatforms Automaticupdatesandbugfixes TrustedOpenCVlibrarysource.AllpackageswithOpenCVarepublishedonGooglePlay ForadditionalinformationonOpenCVManagerseethe: Slides ReferenceManual

ManualOpenCV4AndroidSDKsetup
GettheOpenCV4AndroidSDK
1. Go to the OpenCV download page on SourceForge and download the latest available version. Currently its O p e n C V 2 . 4 . 5 a n d r o i d s d k . z i p . 2. Create a new folder for Android with OpenCV development. For this tutorial we have unpacked OpenCV SDK to the C : \ W o r k \ O p e n C V 4 A n d r o i d \ directory. Note: Bettertouseapathwithoutspacesinit.Otherwiseyoumayhaveproblemswithndkbuild. 3. UnpacktheSDKarchiveintothechosendirectory. Youcanunpackitusinganypopulararchiver(e.gwith7Zip):

OnUnixyoucanusethefollowingcommand:
u n z i p~ / D o w n l o a d s / O p e n C V 2 . 4 . 5 a n d r o i d s d k . z i p

ImportOpenCVlibraryandsamplestotheEclipse
1. StartEclipseandchooseyourworkspacelocation. WerecommendtostartworkingwithOpenCVforAndroidfromanewcleanworkspace.AnewEclipseworkspacecanforexamplebecreatedin thefolderwhereyouhaveunpackedOpenCV4AndroidSDKpackage:

2. ImportOpenCVlibraryandsamplesintoworkspace. OpenCVlibraryispackedasareadyforuseAndroidLibraryProject.Youcansimplyreferenceitinyourprojects. Each sample included into the O p e n C V 2 . 4 . 5 a n d r o i d s d k . z i p is a regular Android project that already references OpenCV library. FollowthestepsbelowtoimportOpenCVandsamplesintotheworkspace: Note: OpenCVsamplesareindeeddependentonOpenCVlibraryprojectsodontforgettoimportittoyourworkspaceaswell. RightclickonthePackageExplorerwindowandchooseImport...optionfromthecontextmenu:

InthemainpanelselectGeneralExistingProjectsintoWorkspaceandpressNextbutton:

IntheSelectrootdirectoryfieldlocateyourOpenCVpackagefolder.EclipseshouldautomaticallylocateOpenCVlibraryandsamples:

ClickFinishbuttontocompletetheimportoperation. Afterclicking FinishbuttonEclipsewillloadallselectedprojectsintoworkspace,andyouhavetowaitsometimewhileitisbuildingOpenCV samples.JustgiveaminutetoEclipsetocompleteinitialization. Warning: Aftertheinitialimport,onanonWindows(LinuxandMacOS)operatingsystemEclipsewillstillshowbuilderrorsforapplications withnativeC++code.Toresolvetheissues,pleasedothefollowing: OpenProjectProperties>C/C++Build,andreplaceBuildcommandtextto " $ { N D K R O O T } / n d k b u i l d " (remove.cmdattheend).

Note: Insomecasesthebuilderrorsdontdisappear,thentrythefollowingactions: rightclickon O p e n C VL i b r a r y project>AndroidTools>FixProjectProperties,thenmenuProject>Clean...>Cleanall rightclickontheprojectwitherrors>Properties>Android,makesurethe T a r g e t isselectedandis A n d r o i d3 . 0 orhigher checkthebuilderrorsintheProblemsviewwindowandtrytoresolvethembyyourselves

OnceEclipsecompletesbuildyouwillhavethecleanworkspacewithoutanybuilderrors:

RunningOpenCVSamples
Atthispointyoushouldbeabletobuildandrunthesamples.Keepinmind,that f a c e d e t e c t i o n and T u t o r i a l2-M i x e dP r o c e s s i n g includesomenativecodeandrequireAndroidNDKandNDK/CDTpluginforEclipsetobuildworkingapplications.Ifyouhaventinstalledthesetools, seethecorrespondingsectionofIntroductionintoAndroidDevelopment. Warning: PleaseconsiderthatsomesamplesuseAndroidJavaCameraAPI,whichisaccessiblewithanAVD.Butmostofsamplesuse OpenCVNativeCamerawhichmaynotworkwithanemulator. Note: RecentAndroidSDKtools,revision19+canrunARMv7aOSimagesbuttheyavailablenotforallAndroidversions. Well,runningsamplesfromEclipseisverysimple: ConnectyourdevicewithadbtoolfromAndroidSDKorcreateanemulatorwithcamerasupport. SeeManagingVirtualDevicesdocumentforhelpwithAndroidEmulator. SeeUsingHardwareDevicesforhelpwithrealdevices(notemulators). SelectprojectyouwanttostartinPackageExplorerandjustpress C t r l+F 1 1 orselectoptionRunRunfromthemainmenu,orclickRun buttononthetoolbar. Note: AndroidEmulatorcantakeseveralminutestostart.So,please,bepatient. OnthefirstrunEclipsewillaskyouabouttherunningmodeforyourapplication:

SelecttheAndroidApplicationoptionandclickOKbutton.Eclipsewillinstallandrunthesample. ChancesarethatonthefirstlaunchyouwillnothavetheOpenCVManagerpackageinstalled.Inthiscaseyouwillseethefollowingmessage:

To get rid of the message you will need to install OpenCVManagerandtheappropriate OpenCVbinarypack. Simply tap Yes if you have GooglePlayMarketinstalledonyourdevice/emulator.ItwillredirectyoutothecorrespondingpageonGooglePlayMarket. Ifyouhavenoaccesstothe Market,whichisoftenthecasewithemulatorsyouwillneedtoinstallthepackagesfromOpenCV4AndroidSDK foldermanually.SeeHowtoselecttheproperversionofOpenCVManagerfordetails.
1 < A n d r o i dS D Kp a t h > / p l a t f o r m t o o l s / a d bi n s t a l l< O p e n C V 4 A n d r o i dS D Kp a t h > / a p k / O p e n C V _ 2 . 4 . 5 _ M a n a g e r _ 2 . 7 _ a r m v 7 a n e o n . a p k

Note: a r m e a b i , a r m v 7 a n e o n , a r m 7 a n e o n a n d r o i d 8 , m i p s and x 8 6 standforplatformtargets: a r m e a b i isforARMv5andARMv6architectureswithAndroidAPI8+, a r m v 7 a n e o n isforNEONoptimizedARMv7withAndroidAPI9+, a r m 7 a n e o n a n d r o i d 8 isforNEONoptimizedARMv7withAndroidAPI8, m i p s isforMIPSarchitecturewithAndroidAPI9+, x 8 6 isforIntelx86CPUswithAndroidAPI9+. Ifusinghardwaredevicefortesting/debugging,runthefollowingcommandtolearnitsCPUarchitecture:


a d bs h e l lg e t p r o pr o . p r o d u c t . c p u . a b i

IfyoureusinganAVDemulator,goWindow>AVDManagertoseethelistofavailibledevices.ClickEditinthecontextmenuoftheselected device.Inthewindow,whichthenpopups,findtheCPUfield. YoumayalsoseesectionHowtoselecttheproperversionofOpenCVManagerfordetails.

Whendone,youwillbeabletorunOpenCVsamplesonyourdevice/emulatorseamlessly. Hereis S a m p l e-i m a g e m a n i p u l a t i o n s sample,runningontopofstockcamerapreviewoftheemulator.

Whatsnext
Now,whenyouhaveyourinstanceofOpenCV4AdroidSDKsetupandconfigured,youmaywanttoproceedtousingOpenCVinyourownapplication. YoucanlearnhowtodothatinaseparateAndroidDevelopmentwithOpenCVtutorial.

HelpandFeedback

Youdidnotfindwhatyouwerelookingfor? AskaquestionontheQ&Aforum. Ifyouthinksomethingismissingorwronginthedocumentation,pleasefileabugreport.

Anda mungkin juga menyukai