从参考[1]中下载源码,VIBE的算法实现由vibe-background-sequential.c和vibe-background-sequential.h构成,为了mex编译方便将vibe-background-sequential.c文件的后缀改为cpp。
mex的接口文件为VIBE_.cpp:
// VIBE_.cpp
// ------------------------------------------------------------------ -
// Reference: your-main-file-sequential.c and mexopencv-master/BackgroundSubtractorMOG2_.cpp
// Authors : LSS
// Date : 26 / 04 / 2017
// Last modified : 28 / 04 / 2017
// ------------------------------------------------------------------ -
#include "mex.h"
#include "matrix.h" // for the mxArray
#include <map>
#include <cstdint>
#include <vector>
#include <string>
#include "vibe-background-sequential.h"
#include "vibe-background-sequential.cpp"
using namespace std;
class VIBE
{
private:
vibeModel_Sequential_t *model;
bool bfirstFrame;
public:
VIBE()
{
model = (vibeModel_Sequential_t*)libvibeModel_Sequential_New();
bfirstFrame = true;
};
VIBE(const VIBE & vibe)
{
model = (vibeModel_Sequential_t*)libvibeModel_Sequential_New();
/* Default parameters values. */
model->numberOfSamples = vibe.model->numberOfSamples;
model->matchingThreshold = vibe.model->matchingThreshold;
model->matchingNumber = vibe.model->matchingNumber;
model->updateFactor = vibe.model->updateFactor;
/* Storage for the history. */
model->historyImage = vibe.model->historyImage;
model->historyBuffer = vibe.model->historyBuffer;
model->lastHistoryImageSwapped = vibe.mode