Ejemplo n.º 1
0
        private void OpenVideo()
        {
            string fileLocation;

            if (string.IsNullOrWhiteSpace(FileLocation))
            {
                fileLocation = FileBrowser.BroseForVideoFiles();
            }
            else
            {
                fileLocation = FileLocation;
            }

            if (string.IsNullOrWhiteSpace(fileLocation))
            {
                return;
            }

            Video.SetVideo(fileLocation);
            VideoSettings.FileName       = fileLocation;
            VideoSettings.ThresholdValue = ThresholdValue;
            //VideoSettings.
            SliderMaximum = Video.FrameCount;

            Image <Gray, Byte>          binaryBackground;
            IEnumerable <IBoundaryBase> boundaries;

            VideoSettings.GeneratePreview(Video, out binaryBackground, out boundaries);

            BinaryBackground = binaryBackground;

            Image2 = ImageService.ToBitmapSource(BinaryBackground);

            SliderValue = 0;
        }
Ejemplo n.º 2
0
        private void GeneratePreview(IVideo video)
        {
            Image <Gray, Byte>          binaryBackground;
            IEnumerable <IBoundaryBase> boundaries;

            VideoSettings.MotionLength = 100;
            VideoSettings.StartFrame   = 0;
            VideoSettings.GeneratePreview(video, out binaryBackground, out boundaries);
            BinaryBackground = binaryBackground;
        }
Ejemplo n.º 3
0
        private void Test()
        {
            OriginalImage.Save(@"C:\Users\10488835\Desktop\PhD\Papers\Software Practise and Experience\Latex\images\BackgroundSub\1-Original.png");
            using (Image <Gray, Byte> displayImage = OriginalImage.Convert <Gray, Byte>())
                using (Image <Gray, Byte> binaryimage = displayImage.ThresholdBinary(new Gray(ThresholdValue), new Gray(255)))
                {
                    binaryimage.Save(@"C:\Users\10488835\Desktop\PhD\Papers\Software Practise and Experience\Latex\images\BackgroundSub\2-BinaryImage.png");

                    Image <Gray, Byte>          binaryBackground;
                    IEnumerable <IBoundaryBase> boundaries;
                    VideoSettings.GeneratePreview(Video, out binaryBackground, out boundaries);

                    binaryBackground.Save(@"C:\Users\10488835\Desktop\PhD\Papers\Software Practise and Experience\Latex\images\BackgroundSub\3-BinaryBackground.png");

                    using (Image <Gray, Byte> subbed = binaryBackground.AbsDiff(binaryimage))
                        using (Image <Gray, Byte> not = binaryBackground.Not())
                            using (Image <Gray, Byte> added = binaryimage.Add(not))
                            {
                                added.Save(@"C:\Users\10488835\Desktop\PhD\Papers\Software Practise and Experience\Latex\images\BackgroundSub\4-BinaryAdded.png");
                            }
                }
        }
Ejemplo n.º 4
0
        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;
        }
Ejemplo n.º 5
0
        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;
        }