Opencv级联分类器训练指南
Opencvsrapidobjectdetection
EE:\Temp,Opency-_objectMarkerexe
四日3-6-1453-18.bmp
Lrectx
29y=233W1dth=13B
height=98
eCtx=26区
y=186width=112
height=74
IaddsaveandloadneTexit
|口x
Fig1-1:Rawimageandaboundingrectangleonthebowlinthemiddle
Ifyouwanttotrytotrainbyoneexampleimageanyway,youmusthave"iplPXllibavailable
Alsoyouhavetouncomment#definehaveIplinfilecvhaartrainingh'sothat
iplWarpPerspectiveg0isrunningcorrectlyfor"createsamples,exe?.Otherwisewhencompiled
thestepofpatterngenerationfromyouronesampleisnotincludedintotheprogramandonlythe
negativesareputintoavecfile
Thesepositivesampleswillbestoredinafolder"bowls""C:\Temp\positives\"where
theinfofiles“train.txt”and‘testing.txt'arelocated[Fig.1-2
鬥-0b-17聊t量1211161
如一日6隐1351151061414道04314655
us20-06017份0p39114035517511179
22006-0p32341的1047101+1的3761
-聊的71m
』m---即2印5222202:20
四s一唧p。1舒巒11日
u0--05柳卿5i6237m10711171571291552181
m-00蝉58540型1智的1题191妇
452
1200-06-08-0-0聊00135856m06153067412075份1512071171559565610856
m隐—-聊最卧蘸11節3011经
IQ-6-08180-1柳p295181卵1605
u00--16bp23量111imi0m
-槨論18即加2115論1⑩a7111
u000含娜63611员惚1356175m723135511”55120513
cu2001-06081-0-34B4135
r47251112
38196396156
lu20-81-柳p227714431174911的1912劉5m1根3977711m
u/0-b0--tp1票6“1的115昌
b0-017-46即p3417念锁20113152415010
0017娜313爿常8167
us/:m-7-bp:15]2:7
Fig.1-2:Examplecontentoffiletrain.txt(fromlefttoright):BMPfilelocation,numberofrectangles,eachrectangles
X/ycoordinateoftheupperleftcornerandwidth/heightfromthispointx/y
Florianadolf
Page3of6
2003-09-02
Opencvsrapidobjectdetection
Step2-Sample/TestCreation
Assumingthatasamplesizeof20x20isagoodchoiceformostobjects,samplesarereducedto
thissize
Basicallythereshouldbefoursetsofimagesthatyouworkon
apositivesamplesetrepresentingyourobjectthatyouwanttotrain
anotherpositivesamplesetfortestingpurpose
anegativesampleset(orso-calledbackgroundsfortraining
andanothernegativesamplesetfortesting,too
Note:Thetestingsetsshouldnotcontainanyimagesthatwereusedfortraining
Ofcourse,definingthenumberofimagesincachsetdependsonhowmanyimagesyouhavein
total.Weuse5500negativesandsplittheminto5350samplesfortrainingand150samplesfor
testing.Aspositivesampleswehave1350imagesfromourbowl[Fig2-1where50aretakenfor
testing
Fig.2-1:Examplesofhowdifferentasimplebowlcanappearinarealvideoimage
Accordingtothisamountofsamplesineachsetyoumustspecifythenumberparamtersforthe
trainingutilities,too
Onceyouhaveallyoursetsarrangedtheobjectimageshavetobepacked"intoavec-fileinthe
folder"data?.Thiscanonlybedonebythecreatesamplestool,evenifyoualreadyhaveasetof
objectimagesanddontwanttogenerateartificialobjectimages.Thecallinourcasewouldbe
createsamples.exe-infopositives/train.txt-vecdata/positivesvec-num1300-w20-h20
Itshouldbecheckedifthevecfilereallycontainsthedesiredimages.Forexamplewhenyou
tookthenon-IPLversionofcreatesamplestocreateartificialobjectimages,youwillseenowthat
itcontainspartsofyournegativesetwithnoobjectonit.Inourcasecallfollowingandpress
toscrollthroughtheimagesinthis"highGUIwindow
createsamples.exe-vecdata/positivesvec-W20-h20
Florianadolf
Page4of6
2003-09-02
Opencvsrapidobjectdetection
Step3-Training
Assumingthedefaultvaluesofhitrate(0.995),maxfalsealarm(0.5),weighttrimming(0.95)and
boostingtype(GAB,GentleAdaBoost)aregoodinmostcases,onlysomeparameterswillbe
changed.Theextendedfeaturesetshouldbeusedandthenumberofstagesshouldbeatleast20
Ifthesearetoomanystagesyoucanaborttrainingatanytime.Ifthesearetoolessstagesyoucan
restartthetrainingtoolandstageswillbeaddedtoanexistingcascade(startingpointisthelast
completedstage).Iftheobjectissymmetric(likethebowlinourexample)theparameter
nonsym"isnotneeded.Thissavesfeaturecalculationtimeandmemoryusageineachstage
ThesystemyoushoulduseforhaartrainingshouldhaveafastprocessorandenoughRAM
installed.Themachineusedfortrainingherehas1.5GBofRaMandap42.4GHzwithout
HyperThreadingUsingWindows2000AdvancedServerforbettermemorymanagementand
pagingfilebehaviour,wecanuse1,300MBofRAMfor"haartraining.exe"It'simportantnotto
useallsystemRAMbecauseotherwiseitwillresultinaconsiderabletrainingslowdown
Thetrainingofourbowlwillbestartedbythefollowingcall
haartraining.exe-datadata/cascade-vecdata/positives.vec-bgnegatives/train.txt
-npos1300-nneg5350-stages30-mem1300-modeall-w20-h20
Whiletrainingisrunning,youalreadycangeta"feeling"whetheritwillbesuitableclassifieror
somethinghastobeimprovedinyourtrainingsetand/ortrainingparameters
Thelinestartingwith"POS:showsthehitrateinthesetoftrainingsamples.Thenextline
startingwith"NEGindicatesthefalsealarmrate.Therateofthepositivesshouldbeequalor
ncar1.0(asitisin"stage0).Thefalscalarmrateshouldreachatleast5*10(fivezeros)untilit
isausableclassifier[Fig3-1].Otherwisethefalsalarmisbetoohighforrealworldapplication
Ifoneofthesevaluesgetsbelowzero["Stage18,Fig3-1]there'sjustanoverflow.Thismeans
thatthefalsealarmrateissolowthatiscanbestopped,nofurthertrainingwouldmakesense
STAGETRAININGTIME:5037.31
STAGE:17
POS:129312931.000000
NEG:500013087771430.000004
BACKGROUNDPROCESSINGTIME:26671.78
PRECALCULATIONTIME:108.59
STAGETRAININGTIME:5389.59
sTAGE:18
POS:129312931.000000
NEG:5000-14651568600.000003
BACKGROUNDPROCESSINGTIME:58371.50
PRECALCULATIONTIME:108.56
Fig3-1:Exampleofbowltraining:In"STAGE17"fivezeros(redcolourednumber)indicatetopossiblybecomea
suitableclassifier.In1.3billionbackgroundsmightbe5000backgroundsinwhichanobjectisdetectedfalsly
Florianadolf
Page5of6
2003-09-02
Opencvsrapidobjectdetection
step4·Testing
Aclassifiercanbetestedwiththeperformancetoolmentionedunder"utiliesordirectlyviaa
livetestifadetailedreportisnotnecessary
Ifyouwantareporttestyoumusthaveadifferentsetofpositivesandnegativesasmentionedin
pl-Preparation”
Theinfofileforthisperformanceutilitymustnotcontainapathtotheimage.Onlythefilename
itselfisallowed.Otherwisethecvsavelmageofunctionthrowsanerrorbecauseitcannotsavethe
imagewheretherectanglesaredrawninto
Toavoidthiserroryoucanalsousetheoption"andnodetectionresultissavedtoanimage
Inourexamplethetestofhitrateandfalsealarmwillbedonebycalling
performance.exe-datadata/cascade-infopositives/testing/testing.txt-W20-h20-rs30
Itwillgothroughallimagesandtriesdetecttheobject.Ifoneobjectisfoundandoption"-ni"is
notspecified,itwillsavethecurrentimage
Theresultsofthisperformanceutilityshouldonlybeseenasonepossibleresultanddontreflect
thepossibledetectionbehaviourofyourapplication[Fig4-1]
Fig.4-1:Differentdetectionresultsforthesameclassifierbase:performancetool(leftcolumn)andexample
applicationfromOpencvdocumention(rightcolumn)
Florianadolf
Page6of6
2003-09-02
下载地址
用户评论