TIEVisionBackgroundSubtractor.selectMethodGMG
Declaration
procedure selectMethodGMG(initializationFrames: int32_t = 120; decisionThreshold: double = 0.8); safecall;
Description
Select the GMG Background Subtractor algorithm.
Parameter | Description |
initializationFrames | Number of frames used to initialize the background models |
decisionThreshold | Threshold value, above which it is marked foreground, else background |
| Demos\IEVision\BackgroundSubtract\BackgroundSubtract.dpr |
// Demo TImageEnViews:
// ImageEnView1: Captured video
// ImageEnView4: Image to use as background
// ImageEnView2: Foreground Mask
// ImageEnView3: Output with replaced background
// Capture button
procedure TMainForm.CaptureButtonClick(Sender: TObject);
var
w, h: integer;
f: AnsiString;
begin
VideoInputForm.Connect;
// start capture
ImageEnView1.IO.DShowParams.Run;
// set up background subtractor
m_backgroundSubtractor.selectMethodGMG();
end;
// We have a new frame
procedure TMainForm.ImageEnView1DShowNewFrame(Sender: TObject);
var
fgmask: TIEVisionImage;
learningRate: double;
begin
// copy current sample to ImageEnView bitmap
ImageEnView1.IO.DShowParams.GetSample(ImageEnView1.IEBitmap);
// get foreground mask
if CheckBoxLearning.Checked then
learningRate := -1
else
learningRate := 0;
fgmask := m_backgroundSubtractor.apply(ImageEnView1.IEBitmap.GetIEVisionImage(), learningRate);
ImageEnView2.IEBitmap.AssignIEVisionImage(fgmask);
// replace background using foreground mask
ImageEnView4.Proc.ResampleTo(ImageEnView3.IEBitmap, ImageEnView1.IEBitmap.Width, ImageEnView1.IEBitmap.Height, rfNone);
ImageEnView3.Proc.Merge(ImageEnView1.IEBitmap, ImageEnView2.IEBitmap);
// refresh viewers
ImageEnView1.Update();
ImageEnView2.Update();
ImageEnView3.Update();
end;