CuuDuongThanCong.com
CuuDuongThanCong.com
OpenCVAndroidProgrammingBy
Example
CuuDuongThanCong.com
TableofContents
OpenCVAndroidProgrammingByExample
Credits
AbouttheAuthor
AbouttheReviewers
www.PacktPub.com
Supportfiles,eBooks,discountoffers,andmore
Whysubscribe?
FreeaccessforPacktaccountholders
Preface
Whatthisbookcovers
Whatyouneedforthisbook
Whothisbookisfor
Conventions
Readerfeedback
Customersupport
Downloadingtheexamplecode
Downloadingthecolorimagesofthisbook
Errata
Piracy
Questions
1.GettingYourselfReady
InstallingTegraAndroidDevelopmentPack
DownloadingandinstallingTADP
TADPpost-installationconfiguration
Installingemulatorsystemimages
ConfiguringEclipsetoworkwithNDK
NDKverification
InstallingtheOpenCVandAndroiddevelopmentenvironmentmanually
JavaSEDevelopmentKit6
CuuDuongThanCong.com
AndroidStudio
AndroidSDK
EclipseIDE
ADTandCDTpluginsforEclipse
AndroidNDK
DownloadingAndroidNDK
InstallingandconfiguringAndroidNDK
BuildingnativecodeusingEclipse
OpenCV4AndroidSDK
UnderstandinghowNDKworks
AnoverviewofNDK
AsimpleexampleofNDK
Android.mk
BuildingyourfirstAndroidprojectwithOpenCV
HelloVisionWorldAndroidapplication
CreatingaprojectinEclipse
CreatingaprojectinAndroidStudio
Summary
2.App1-BuildingYourOwnDarkroom
Digitalimages
Colorspaces
TheMatclass
BasicMatoperations
Processingtheimagesstoredonyourphone
LoadinganimagetoaMatobject
UIdefinitions
ReadinganimageusingOpenCV
Calculatinganimagehistogram
Whatarehistograms?
Understandinghistogramcomponents
UIdefinitions
CuuDuongThanCong.com
Calculatinganimagehistogram
Enhancingtheimagecontrast
Understandinghistogramequalization
Enhancinggrayscaleimages
UIdefinitions
Convertinganimagetograyscale
Equalizingahistogramforagrayscaleimage
EnhancinganHSVimage
UIdefinitions
Equalizingahistogramfortheimagesaturationandvalue
EnhancinganRGBimage
UIdefinitions
Equalizingahistogramfortheimagecolorchannels
Summary
3.App2-SoftwareScanner
Spatialfiltering
Understandingconvolutionandlinearfiltering
Removingnoise
Theaveragingfilter
TheGaussianfilter
Themedianfilter
UIdefinitions
Applyingfilterstoreduceimagenoise
Findingedges
TheSobeledgedetector
TheCannyedgedetector
UIdefinitions
ApplyingtheSobelfiltertofindedges
UsingtheCannyedgedetector
Detectingshapes
UnderstandingtheHoughlinetransform
CuuDuongThanCong.com
DetectinglinesusingHoughtransform
UIdefinitions
Detectinganddrawinglines
DetectingcirclesusingHoughtransform
UIdefinitions
Detectinganddrawingcircles
Summary
4.App2-ApplyingPerspectiveCorrection
Imagetransformationsandperspectivecorrection
Translation
Rotationandtranslation
Scaledrotation
Affine
Perspectivetransformation
Rigidperspectivecorrection
UIdefinitions
Estimatingtheperspectivetransformationusingtheobjectboundingbox
Flexibleperspectivecorrection
UIdefinitions
Applyingflexibleperspectivecorrection
Manualperspectivecorrection
UIdefinitions
Selectingthecornersmanually
Summary
5.App3-PanoramicViewer
Imagefeatures
Featuredetectors
UnderstandingtheHarriscornerdetector
UIdefinitions
UsingtheHarriscornerdetector
CallinganativeHarriscornerdetector
CuuDuongThanCong.com
UsingthenativeOpenCVlibrarywithinEclipse
UsingthenativeOpenCVlibrarywithinAndroidStudio
Workingonthenativepart
UnderstandingtheFASTcornerdetector
UIdefinitions
UsingtheFASTcornerdetector
UsingnativeFAST
UnderstandingtheORBfeaturedetector
UIdefinitions
UsingtheORBfeaturedetector
UsingnativeORB
Featuredescriptionandmatching
UnderstandingBRIEFandORBfeaturedescriptors
UnderstandingtheBRISKfeaturedescriptor
UnderstandingtheFREAKfeaturedescriptor
Matchingthefeatures
Workingwithfeaturematching
UIdefinitions
Findinganobjectinascene
Nativefeaturematching
UIdefinitions
Thenativematchingprocess
Stitchingtwoimages
UIdefinitions
Thenativestitcher
Summary
6.App4–AutomaticSelfie
Cascadeclassifiers
Haar-likefeatures
Theintegralimage
AdaptiveBoosting
CuuDuongThanCong.com
Cascading
Usingcascadeclassifierstodetectobjects
Accessingyourphone’scamerausingOpenCV
Acamerapreview
UIdefinitions
Previewingthecameraframes
Detectingclosedpalmsinthecameraframes
UsingtheJava-basedcascadeclassifier
Summary
Index
CuuDuongThanCong.com
CuuDuongThanCong.com
OpenCVAndroidProgrammingBy
Example
CuuDuongThanCong.com
CuuDuongThanCong.com
OpenCVAndroidProgrammingBy
Example
Copyright©2015PacktPublishing
Allrightsreserved.Nopartofthisbookmaybereproduced,storedinaretrievalsystem,
ortransmittedinanyformorbyanymeans,withoutthepriorwrittenpermissionofthe
publisher,exceptinthecaseofbriefquotationsembeddedincriticalarticlesorreviews.
Everyefforthasbeenmadeinthepreparationofthisbooktoensuretheaccuracyofthe
informationpresented.However,theinformationcontainedinthisbookissoldwithout
warranty,eitherexpressorimplied.Neithertheauthor,norPacktPublishing,andits
dealersanddistributorswillbeheldliableforanydamagescausedorallegedtobecaused
directlyorindirectlybythisbook.
PacktPublishinghasendeavoredtoprovidetrademarkinformationaboutallofthe
companiesandproductsmentionedinthisbookbytheappropriateuseofcapitals.
However,PacktPublishingcannotguaranteetheaccuracyofthisinformation.
Firstpublished:December2015
Productionreference:1071215
PublishedbyPacktPublishingLtd.
LiveryPlace
35LiveryStreet
BirminghamB32PB,UK.
ISBN978-1-78355-059-3
www.packtpub.com
CuuDuongThanCong.com
CuuDuongThanCong.com
Credits
Author
AmgadMuhammad
Reviewers
NoritsunaImamura
AndréMoreira
CommissioningEditor
NeilAlexander
AcquisitionEditor
MeetaRajani
ContentDevelopmentEditor
MayurPawanikar
TechnicalEditor
ManthanRaja
CopyEditor
TasneemFatehi
ProjectCoordinator
NidhiJoshi
Proofreader
SafisEditing
Indexer
MonicaAjmeraMehta
Graphics
AhmedH.Alley
KirkD’Penha
JasonMonteiro
ProductionCoordinator
ArvindkumarGupta
CoverWork
ArvindkumarGupta
CuuDuongThanCong.com
CuuDuongThanCong.com
AbouttheAuthor
AmgadMuhammadhasamaster’sdegreeincomputersciencefromtheAmerican
UniversityinCairo.Heisadatascientistpassionateaboutbuildinganddesigning
machinelearningmodelsandengineeringfeaturesincomputervisionresearch.Hestarted
workingwithcomputervisionin2011,andnowheisdevelopingstate-of-the-artmachine
learningandcomputervisionalgorithmsinthefieldofbiometricextractionand
registration,includingfaceandpersondetection,humantracking,and2D/3D-basedpose
estimation.
First,Iwouldliketothankmylovelywife,Noha,andmybeautifulkids,Zain,Hla,and
Darine,fortheircontinuouscaresothatIcouldfinishthisbook.Thebookisthefruitof
myfamily’ssupportandunderstanding,inspiteofallthetimeittookmeawayfromthem,
andalltheweekendsIspentinfrontofmycomputer.Itwasreallyachallengingandlong
journey,havingafull-timejobandmygraduatestudieswhilewritingthisbook,but,asa
lovingandcaringfamily,wewereabletopullthrough.
Iwouldalsoliketothankmybestfriend,AhmedHassanAlley,forthebeautifulgraphics
andillustrations.AndIwouldliketothankMayurPawanikar,ManthanRaja,andMeeta
Rajaniforhelpingmethroughouttheeditingprocess;theymadeitreallyeasy.
CuuDuongThanCong.com
CuuDuongThanCong.com
AbouttheReviewers
NoritsunaImamuraisaspecialistinembeddedLinux/Android-basedcomputervision,
andisoneofthemainmembersofSIProp.org(Hismainworks
areasfollows:
ITRISmartGlass,whichissimilartoGoogleGlass.Heworkedonthisusing
Android4.3andOpenCV2.4inJune2014
( />&SiteID=1&MmmID=620622510147005345&Keyword=&MSid=4858).
TreasureHuntingRobot,abrainwave-controlledrobotthathedevelopedinFebruary
2012( />OpenCVfortheAndroidNDK,whichhasbeenincludedsinceAndroid4.0.1
( />AutoChasingTurtle,ahumanfacerecognitionrobotwithKinect,whichhe
developedinFebruary2011( />product%2FAutoChasingTurtle).
FeelSketch,anARauthoringtoolandARbrowserasanAndroidapplication,which
hedevelopedinDecember2009( />Hecanbecontactedviae-mailat<>.
AndréMoreirareceivedhismaster’sdegreeincomputersciencefromPontificalCatholic
UniversityofRiodeJaneiro,Brazilin2015.CurrentlyheisPhDcandidateinthesame
university.
Hegraduatedwithabachelor’sdegreeincomputersciencefromUniversidadeFederaldo
Maranhão(UFMA)inBrazil.Duringhisundergraduatedegree,hewasamemberof
Labmint’sresearchteamandworkedwithmedicalimaging,specificallybreastcancer
detectionanddiagnosisusingimageprocessing.
Currently,heworksasaresearcherandsystemanalystatInstitutoTecgraf,oneofthe
majorresearchanddevelopmentlabsincomputergraphicsinBrazil.Hehasbeenworking
extensivelywithPHP,HTML,andCSSsince2007.Nowadays,hedevelopsprojectsin
C++11/C++14,alongwithSQLite,Qt,Boost,andOpenGL.Moreinformationabouthim
canbeacquiredonhispersonalwebsiteatwww.andredsm.com.
CuuDuongThanCong.com
CuuDuongThanCong.com
www.PacktPub.com
CuuDuongThanCong.com
Supportfiles,eBooks,discountoffers,and
more
Forsupportfilesanddownloadsrelatedtoyourbook,pleasevisitwww.PacktPub.com.
DidyouknowthatPacktofferseBookversionsofeverybookpublished,withPDFand
ePubfilesavailable?YoucanupgradetotheeBookversionatwww.PacktPub.comandas
aprintbookcustomer,youareentitledtoadiscountontheeBookcopy.Getintouchwith
usat<>formoredetails.
Atwww.PacktPub.com,youcanalsoreadacollectionoffreetechnicalarticles,signup
forarangeoffreenewslettersandreceiveexclusivediscountsandoffersonPacktbooks
andeBooks.
/>DoyouneedinstantsolutionstoyourITquestions?PacktLibisPackt’sonlinedigital
booklibrary.Here,youcansearch,access,andreadPackt’sentirelibraryofbooks.
CuuDuongThanCong.com
Whysubscribe?
FullysearchableacrosseverybookpublishedbyPackt
Copyandpaste,print,andbookmarkcontent
Ondemandandaccessibleviaawebbrowser
CuuDuongThanCong.com
FreeaccessforPacktaccountholders
IfyouhaveanaccountwithPacktatwww.PacktPub.com,youcanusethistoaccess
PacktLibtodayandview9entirelyfreebooks.Simplyuseyourlogincredentialsfor
immediateaccess.
Tomywife,Noha,andmychildren,Zain,Hla,andDarine
CuuDuongThanCong.com
CuuDuongThanCong.com