public BgSubtractorMOG() { using (CvCapture capture = new CvCapture(Const.MovieHara)) // specify your movie file using (BackgroundSubtractorMOG mog = new BackgroundSubtractorMOG()) using (CvWindow windowSrc = new CvWindow("src")) using (CvWindow windowDst = new CvWindow("dst")) { IplImage imgFrame; using (Mat imgFg = new Mat()) while ((imgFrame = capture.QueryFrame()) != null) { mog.Run(new Mat(imgFrame, false), imgFg, 0.01); windowSrc.Image = imgFrame; windowDst.Image = imgFg.ToIplImage(); Cv.WaitKey(50); } } }
public void Run() { using (var capture = new VideoCapture(FilePath.Bach)) using (var mog = new BackgroundSubtractorMOG()) using (var windowSrc = new Window("src")) using (var windowDst = new Window("dst")) { var frame = new Mat(); var fg = new Mat(); while (true) { capture.Read(frame); if(frame.Empty()) break; mog.Run(frame, fg, 0.01); windowSrc.Image = frame; windowDst.Image = fg; Cv2.WaitKey(50); } } }