public static BoundaryBaseViewModel GetBoundaryFromModel(IBoundaryBase model) { IArtefactsBoundary artefactModel = model as IArtefactsBoundary; if (artefactModel != null) { return(new ArtefactsBoundaryViewModel(artefactModel, model.Points)); } IBoxBoundary boxModel = model as IBoxBoundary; if (model is IBoxBoundary) { return(new BoxesBoundary(boxModel, model.Points)); } ICircleBoundary circleModel = model as ICircleBoundary; if (model is ICircleBoundary) { return(new CircularBoundary(circleModel, model.Points)); } IOuterBoundary outerModel = model as IOuterBoundary; if (model is IOuterBoundary) { return(new OuterBoundaryViewModel(outerModel, model.Points)); } return(null); }
public override IBoundaryBase GetBoundary() { IArtefactsBoundary boundary = ModelResolver.Resolve <IArtefactsBoundary>(); boundary.Id = Id; boundary.Points = Points.Select(x => x.GetPoint()).ToArray(); return(boundary); }
public void Preview() { if (FrameNumber + MotionLength > MaxFrame) { //throw new Exception("Motion length too long"); //Motion length too long MessageBox.Show("Motion length extends beyond the length of the video, resetting to last possible location"); FrameNumber = MaxFrame - MotionLength; } Image <Gray, Byte> binaryBackground, extraImage; IEnumerable <IBoundaryBase> boundaries; VideoSettings.MotionLength = MotionLength; VideoSettings.MotionThreshold = LineThreshold; VideoSettings.StartFrame = FrameNumber; VideoSettings.GeneratePreview(Video, out binaryBackground, out boundaries, out extraImage); if (binaryBackground == null) { MessageBox.Show("Error, unable to find any motion, extend motion length"); return; } ExtraImage = ImageService.ToBitmapSource(extraImage); BinaryBackground = binaryBackground; //Video.SetFrame(100); ObservableCollection <BoundaryBaseViewModel> boundries = new ObservableCollection <BoundaryBaseViewModel>(); int boxId = 1; foreach (RotatedRect rect in VideoSettings.Boxes) { IBoxBoundary boxModel = ModelResolver.Resolve <IBoxBoundary>(); boxModel.Id = boxId; boxModel.Points = rect.GetVertices().Select(x => x.ToPoint()).ToArray(); BoxesBoundary box = new BoxesBoundary(boxModel, rect); box.EnabledChanged += EnabledChanged; boundries.Add(box); boxId++; } int artefactId = 1; foreach (Point[] points in VideoSettings.Artefacts) { IArtefactsBoundary artefactModel = ModelResolver.Resolve <IArtefactsBoundary>(); artefactModel.Id = artefactId; artefactModel.Points = points; ArtefactsBoundaryViewModel artefact = new ArtefactsBoundaryViewModel(artefactModel, points); artefact.EnabledChanged += EnabledChanged; boundries.Add(artefact); artefactId++; } int boundaryId = 1; foreach (Point[] points in VideoSettings.Boundries) { IOuterBoundary outerModel = ModelResolver.Resolve <IOuterBoundary>(); outerModel.Id = boundaryId; outerModel.Points = points; OuterBoundaryViewModel outerBoundary = new OuterBoundaryViewModel(outerModel, points); outerBoundary.EnabledChanged += EnabledChanged; boundries.Add(outerBoundary); boundaryId++; } Boundries = boundries; ShowBoundries = true; UpdateDisplayImage(); PreviewGenerated = true; }
public ArtefactsBoundaryViewModel(IArtefactsBoundary model, Point[] points) : base(model) { Points = points; Color = new Bgr(System.Drawing.Color.LightGreen); Name = "Artefact - " + Id; }
public void GeneratePreview(IVideo video, out Image <Gray, Byte> binaryBackground, out IEnumerable <IBoundaryBase> boundaries, int motionLength = 100, int startFrame = 0) { IMotionBackground motionBackground = ModelResolver.Resolve <IMotionBackground>(); motionBackground.SetVideo(video); motionBackground.MotionLength = motionLength; //Image<Gray, Byte> binaryMouse; motionBackground.GenerateMotionBackground(ThresholdValue, out binaryBackground, Roi, startFrame); //motionBackground.Video.Dispose(); IGenerateBoundries generateBoundries = ModelResolver.Resolve <IGenerateBoundries>(); //Point[] mousePoints; List <Point[]> boundries, artefacts; List <RotatedRect> boxes; generateBoundries.GetBoundries(binaryBackground, out boundries, out artefacts, out boxes); //MousePoints = mousePoints; Boundries = boundries; Artefacts = artefacts; Boxes = boxes; List <IBoundaryBase> boundaryList = new List <IBoundaryBase>(); int boxId = 1; foreach (RotatedRect rect in Boxes) { IBoxBoundary boxModel = ModelResolver.Resolve <IBoxBoundary>(); boxModel.Id = boxId; boxModel.Points = rect.GetVertices().Select(x => new Point((int)x.X, (int)x.Y)).ToArray(); boundaryList.Add(boxModel); boxId++; } int artefactId = 1; foreach (Point[] points in Artefacts) { IArtefactsBoundary artefactModel = ModelResolver.Resolve <IArtefactsBoundary>(); artefactModel.Id = artefactId; artefactModel.Points = points; boundaryList.Add(artefactModel); artefactId++; } int boundaryId = 1; foreach (Point[] points in Boundries) { IOuterBoundary outerModel = ModelResolver.Resolve <IOuterBoundary>(); outerModel.Id = boundaryId; outerModel.Points = points; boundaryList.Add(outerModel); boundaryId++; } boundaries = boundaryList; }
public void Preview() { if (FrameNumber + MotionLength > MaxFrame) { //Motion length too long MessageBox.Show("Motion length extends beyond the length of the video, resetting to last possible location"); FrameNumber = MaxFrame - MotionLength; } Image <Gray, Byte> binaryBackground; IEnumerable <IBoundaryBase> boundaries; VideoSettings.GeneratePreview(Video, out binaryBackground, out boundaries, MotionLength, FrameNumber); //string fileName = Path.GetFileNameWithoutExtension(Video.FilePath); //binaryBackground.Save(string.Format(@"D:\Vids\New folder\Vids\Images\{0}-Binary.png", fileName)); BinaryBackground = binaryBackground; //Video.SetFrame(100); ObservableCollection <BoundaryBaseViewModel> boundries = new ObservableCollection <BoundaryBaseViewModel>(); int boxId = 1; foreach (RotatedRect rect in VideoSettings.Boxes) { IBoxBoundary boxModel = ModelResolver.Resolve <IBoxBoundary>(); boxModel.Id = boxId; boxModel.Points = rect.GetVertices().Select(x => x.ToPoint()).ToArray(); BoxesBoundary box = new BoxesBoundary(boxModel, rect); box.EnabledChanged += EnabledChanged; boundries.Add(box); boxId++; } int artefactId = 1; foreach (Point[] points in VideoSettings.Artefacts) { IArtefactsBoundary artefactModel = ModelResolver.Resolve <IArtefactsBoundary>(); artefactModel.Id = artefactId; artefactModel.Points = points; ArtefactsBoundaryViewModel artefact = new ArtefactsBoundaryViewModel(artefactModel, points); artefact.EnabledChanged += EnabledChanged; boundries.Add(artefact); artefactId++; } int boundaryId = 1; foreach (Point[] points in VideoSettings.Boundries) { IOuterBoundary outerModel = ModelResolver.Resolve <IOuterBoundary>(); outerModel.Id = boundaryId; outerModel.Points = points; OuterBoundaryViewModel outerBoundary = new OuterBoundaryViewModel(outerModel, points); outerBoundary.EnabledChanged += EnabledChanged; boundries.Add(outerBoundary); boundaryId++; } Boundries = boundries; ShowBoundries = true; UpdateDisplayImage(); PreviewGenerated = true; }