/**
*\typedefstructvibeModel_Sequential_t
*\briefDatastructureforthebackgroundsubtractionmodel.
*
*Thisdatastructurecontainsthebackgroundmodelaswellassomeparamatersvalue.
*Thecodeisdesignedtohidealltheimplementationdetailstotheusertoeaseitsuse.
*/
typedefstructvibeModel_SequentialvibeModel_Sequential_t;
/**
*Allocationofanewdatastructurewherethebackgroundmodelwillbestored.
*Pleasenotethatthisfunctiononlycreatesthestructuretohostthedata.
*Thisdatastructureswillonlybefilledwithacallto\reflibvibeModel_Sequential_AllocInit_8u_C1R.
*
*\resultApointertoanewlyallocated\refvibeModel_Sequential_t
*structure,orNULLinthecaseofanerror.
*/
vibeModel_Sequential_t*libvibeModel_Sequential_New();
/**
*ViBeusesseveralparameters.
*Youcanprintandchangesomeofthemifyouwant.However,default
*valueshouldmeetyourneedsformostvideos.
*
*@parammodelThedatastructurewithViBe'sbackgroundsubtractionmodelandparameters.
*@return
*/
uint32_tlibvibeModel_Sequential_PrintParameters(constvibeModel_Sequential_t*model);
/**
*Setter.
*
*@parammodelThedatastructurewithViBe'sbackgroundsubtractionmodelandparameters.
*@paramnumberOfSamples
*@return
*/
int32_tlibvibeModel_Sequential_SetNumberOfSamples(
vibeModel_Sequential_t*model,
constuint32_tnumberOfSamples
);
/**
*Setter.
*
*@parammodelThedatastructurewithViBe'sbackgroundsubtractionmodelandparameters.
*@return
*/
uint32_tlibvibeModel_Sequential_GetNumberOfSamples(constvibeModel_Sequential_t*model);
/**
*Setter.
*
*@parammodelThedatastructurewithViBe'sbackgroundsubtractionmodelandparameters.
*@parammatchingThreshold
*@return
*/
int32_tlibvibeModel_Sequential_SetMatchingThreshold(
vibeModel_Sequential_t*model,
constuint32_tmatchingThreshold
);
/**
*Setter.
*
*@parammodelThedatastructurewithViBe'sbackgroundsubtractionmodelandparameters.
*@return
*/
uint32_tlibvibeModel_Sequential_GetMatchingThreshold(constvibeModel_Sequential_t*model);
/**
*Setter.
*
*@parammodelThedatastructurewithViBe'sbackgroundsubtractionmodelandparameters.
*@parammatchingNumber
*@return
*/
int32_tlibvibeModel_Sequential_SetMatchingNumber(
vibeModel_Sequential_t*model,
constuint32_tmatchingNumber
);
/**
*Setter.
*
*@parammodelThedatastructurewithViBe'sbackgroundsubtractionmodelandparameters.
*@paramupdateFactorNewvaluefortheupdatefactor.Pleasenotethattheupdatefactoristobeunderstoodasaprobabilityofupdating.Morespecifically,anupdatefactorof16meansthat1outofevery16backgroundpixelsisupdated.Likewise,anupdatefactorof1meansthateverybackgroundpixelisupdated.
*@return
*/
int32_tlibvibeModel_Sequential_SetUpdateFactor(
vibeModel_Sequential_t*model,
constuint32_tupdateFactor
);
/**
*Getter.
*
*@parammodelThedatastructurewithViBe'sbackgroundsubtractionmodelandparameters.
*@return
*/
uint32_tlibvibeModel_Sequential_GetMatchingNumber(constvibeModel_Sequential_t*model);
/**
*Getter.
*
*@parammodelThedatastructurewithViBe'sbackgroundsubtractionmodelandparameters.
*@return
*/
uint32_tlibvibeModel_Sequential_GetUpdateFactor(constvibeModel_Sequential_t*model);
/**
*\briefFreesallthememoryusedbythemodelanddeallocatesthestructure.
*
*Thisfunctionfreesallthememoryallocatedby\reflibvibeModel_SequentialNewand
*\reflibvibeModel_Sequential_AllocInit_8u_C1Ror\reflibvibeModel_Sequential_AllocInit_8u_C3R.
*@parammodelThedatastructurewithViBe'sbackgroundsubtractionmodelandparameters.
*@return
*/
int32_tlibvibeModel_Sequential_Free(vibeModel_Sequential_t*model);
/**
*Thetwofollowingfunctionsallocatetherequiredmemoryaccordingtothe
*modelparametersandthedimensionsoftheinputimages.
*Youmustusethe"C1R"functionforgrayscaleimagesandthe"C3R"forcolor
*images.
*These2functionsalsoinitializethebackgroundmodelusingthecontent
*of*image_datawhichisthepixelbufferofthefirstimageofyourstream.
*/
//-------------------------Singlechannelimages----------------------------
/**
*
*@parammodelThedatastructurewithViBe'sbackgroundsubtractionmodelandparameters.
*@paramimage_data
*@paramwidth
*@paramheight
*@return
*/
int32_tlibvibeModel_Sequential_AllocInit_8u_C1R(
vibeModel_Sequential_t*model,
constuint8_t*image_data,
constuint32_twidth,
constuint32_theight
);
/*These2functionsperform2operations:
*-theyclassifythepixels*image_datausingtheprovidedmodelandstore
*theresultsin*segmentation_map.
*-theyupdate*modelaccordingtotheseresultsandthecontentof
**image_data.
*Youmustusethe"C1R"functionforgrayscaleimagesandthe"C3R"forcolor
*images.
*/
/**
*
*@parammodelThedatastructurewithViBe'sbackgroundsubtractionmodelandparameters.
*@paramimage_data
*@paramsegmentation_map
*@return
*/
int32_tlibvibeModel_Sequential_Segmentation_8u_C1R(
vibeModel_Sequential_t*model,
constuint8_t*image_data,
uint8_t*segmentation_map
);
/**
*
*@parammodelThedatastructurewithViBe'sbackgroundsubtractionmodelandparameters.
*@paramimage_data
*@paramupdating_mask
*@return
*/
int32_tlibvibeModel_Sequential_Update_8u_C1R(
vibeModel_Sequential_t*model,
constuint8_t*image_data,
uint8_t*updating_mask
);
//-------------------------Threechannelimages-----------------------------
/**
*Thepixelvaluesofcolorimagesarearrangedinthefollowingorder
*RGBRGBRGB...(orHSVHSVHSVHSVHSVHSV...)
*
*@parammodelThedatastructurewithViBe'sbackgroundsubtractionmodelandparameters.
*@paramimage_data
*@paramwidth
*@paramheight
*@return
*/
int32_tlibvibeModel_Sequential_AllocInit_8u_C3R(
vibeModel_Sequential_t*model,
constuint8_t*image_data,
constuint32_twidth,
constuint32_theight
);
/*These2functionsperform2operations:
*-theyclassifythepixels*image_datausingtheprovidedmodelandstore
*theresultsin*segmentation_map.
*-theyupdate*modelaccordingtotheseresultsandthecontentof
**image_data.
*Youmustusethe"C1R"functionforgrayscaleimagesandthe"C3R"forcolor
*images.
*/
/**
*Thepixelvaluesofcolorimagesarearrangedinthefollowingorder
*RGBRGBRGB...(orHSVHSVHSVHSVHSVHSV...)
*
*@parammodelThedatastructurewithViBe'sbackgroundsubtractionmodelandparameters.
*@paramimage_data
*@paramsegmentation_map
*@return
*/
int32_tlibvibeModel_Sequential_Segmentation_8u_C3R(
vibeModel_Sequential_t*model,
constuint8_t*image_data,
uint8_t*segmentation_map
);
/**
*Thepixelvaluesofcolorimagesarearrangedinthefollowingorder
*RGBRGBRGB...(orHSVHSVHSVHSVHSVHSV...)
*
*@parammodelThedatastructurewithViBe'sbackgroundsubtractionmodelandparameters.
*@paramimage_data
*@paramupdating_mask
*@return
*/
int32_tlibvibeModel_Sequential_Update_8u_C3R(
vibeModel_Sequential_t*model,
constuint8_t*image_data,
uint8_t*updating_mask
);
#ifdef__cplusplus
}
#endif
#endif
vibe-background-sequential.cpp
/**
@filevibe-background-sequential.c
@briefImplementationofvibe-background-sequential.h
@authorMarcVanDroogenbroeck
@dateMay2014
*/
/*
Thereareafewimplementation"tricks"[byMarcVanDroogenbroeck].
PleasenotethatTHEYDON'TAFFECTTHEBEHAVIOROFViBebuthelpspeedinguptheimplementation;theyaredescribedhereafter.
1.Swappingvaluesinordertobringbestmatchingcandidatesinthefirstplacesofthememory
TheideaisthatViBeonlyneedstwomatchestoclassifyapixelintothebackground;tosomeextent,the18otherpixels(outofN=20pixels)arethenuseless.Inaddition,mostofthetime,therearenobigchangesbetweenpixelslocatedatthesameplacefromsuccessiveimages(90%ofthepixelsareinthebackgroundonaverage).Ther