public void BackgroundSubtractor_Example() { VideoCapture capture = new VideoCapture(0); using var MOG2 = BackgroundSubtractorMOG2.Create(); using var MOG = BackgroundSubtractorMOG.Create(); using var GMG = BackgroundSubtractorGMG.Create(); using var KNN = BackgroundSubtractorKNN.Create(); using Mat frame = new Mat(); using Mat MOG2remove = new Mat(); using Mat MOGremove = new Mat(); using Mat GMG2remove = new Mat(); using Mat KNNremove = new Mat(); Window win_MOG2 = new Window("MOG2"); Window win_GMG = new Window("GMG"); Window win_MOG = new Window("MOG"); Window win_KNN = new Window("KNN"); while (Cv2.WaitKey(1) < 0) { capture.Read(frame); MOG2.Apply(frame, MOG2remove); MOG.Apply(frame, MOGremove); GMG.Apply(frame, GMG2remove); KNN.Apply(frame, KNNremove); win_MOG2.ShowImage(MOG2remove); win_GMG.ShowImage(MOGremove); win_MOG.ShowImage(GMG2remove); win_KNN.ShowImage(KNNremove); } }
public Detector() { cascade = new CascadeClassifier(@"../cascade/cars.xml"); dScaleFactor = 1.1; uMinNeighbors = 2; minSize = new Size(100, 100); this.bckSub = BackgroundSubtractorKNN.Create(); this.fgMask = new Mat(); this.kernel1 = Cv2.GetStructuringElement(MorphShapes.Rect, new Size(5, 5)); this.kernel2 = Cv2.GetStructuringElement(MorphShapes.Rect, new Size(5, 5)); }