Пример #1
0
        // Gets the outlines that match a given index list

        internal static OutlineParameters getOutlines(IPcOutline parentOutline, List <int> indexes)
        {
            Point globalPicSize = new Point(Convert.ToInt32(GetOutlineWidth(parentOutline)), Convert.ToInt32(GetOutlineHeight(parentOutline)));

            List <Point>           outlineBoundaries = new List <Point>();
            List <PcPhysicalPoint> outlineLocations  = new List <PcPhysicalPoint>();

            for (int j = 0; j < indexes.Count; j++)
            {
                int i = 0;

                foreach (IPcOutline childOutline in parentOutline.Children)
                {
                    if (i == indexes[j])
                    {
                        outlineBoundaries.Add(new Point(Convert.ToInt32(GetOutlineWidth(childOutline)), Convert.ToInt32(GetOutlineHeight(childOutline))));
                        PcPhysicalPoint loc = new PcPhysicalPoint(childOutline.PhysicalBoundaries.Location.X * (childOutline.PixelDensity.X), childOutline.PhysicalBoundaries.Location.Y * (childOutline.PixelDensity.Y));
                        outlineLocations.Add(loc);
                    }

                    i++;
                }
            }

            OutlineParameters op = new OutlineParameters(outlineLocations, outlineBoundaries, globalPicSize);

            return(op);
        }
Пример #2
0
        private static int FindCloser(IPcOutline outline, PcPhysicalPoint location)
        {
            PcPhysicalPoint location2 = new PcPhysicalPoint(outline.PhysicalBoundaries.Location.X * (outline.PixelDensity.X), outline.PhysicalBoundaries.Location.Y * (outline.PixelDensity.Y));

            // Euclidean distance between the object and the target

            int dist = (int)Math.Sqrt(Math.Pow(location.X - location2.X, 2) + Math.Pow(location.Y - location2.Y, 2));

            return(dist);
        }
Пример #3
0
 // @Override Task Constructor
 public Task()
 {
     captureWindow    = null;
     numberOfCaptures = 0;
     interval         = 0;
     index            = 0;
     delay            = 0;
     name             = "";
     location         = null;
     size             = new System.Drawing.Point();
 }
Пример #4
0
 // Constructor
 public Task(CaptureWindow cw, int nOfC, int inter, int ind, int dl, List <Uri> cpt, string f, bool count, bool classAn, string n, PcPhysicalPoint loc, System.Drawing.Point s)
 {
     captureWindow    = cw;
     numberOfCaptures = nOfC;
     interval         = inter;
     index            = ind;
     captures         = cpt;
     delay            = dl;
     folder           = f;
     countAnalysis    = count;
     classAnalysis    = classAn;
     name             = n;
     location         = loc;
     size             = s;
 }
Пример #5
0
        private static bool CompareOutlines(IPcOutline childOutline, Task t)
        {
            // Size is considered to be a knockout feature

            Point size = new Point(Convert.ToInt32(GetOutlineWidth(childOutline)), Convert.ToInt32(GetOutlineHeight(childOutline)));

            if (Math.Abs(size.X - t.getSize().X) > AdvancedOptions._nSizeThreshold || Math.Abs(size.Y - t.getSize().Y) > AdvancedOptions._nSizeThreshold)
            {
                return(false);
            }

            PcPhysicalPoint location = new PcPhysicalPoint(childOutline.PhysicalBoundaries.Location.X * (childOutline.PixelDensity.X), childOutline.PhysicalBoundaries.Location.Y * (childOutline.PixelDensity.Y));

            if (Math.Abs(location.X - t.getLocation().X) > AdvancedOptions._nLocationThreshold || Math.Abs(location.Y - t.getLocation().Y) > AdvancedOptions._nLocationThreshold)
            {
                return(false);
            }

            return(true);
        }
Пример #6
0
        private static bool ConfirmMatch(PcPhysicalPoint loc, Point size, IPcOutline outline, int i)
        {
            int counter = 0;

            foreach (IPcOutline childOutline in outline.Children)
            {
                if (counter == i)
                {
                    if (CompareOutlines(childOutline, loc, size))
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                counter++;
            }

            return(false);
        }
Пример #7
0
        // Saves the outlines
        public static OutlineParameters SavePicture(IPcPicture picture, IPcOutline parentOutline)
        {
            _saveDirectory = Path.Combine(ToolBox.defaultFilePath, @"Pictures\" + "ConfirmDirectory");

            ToolBox.EnsureDirectoryExists(_saveDirectory);
            ToolBox.EnsureDirectoryExists(ToolBox.defaultFilePath);

            PcImage image = picture.Image;

            confirmPath = Path.Combine(_saveDirectory, "confirmPicture" + marker2 + ".bmp");
            ToolBox.SaveProcessedImage(image, confirmPath);
            marker2++;

            List <Point> outlineBoundaries = new List <Point>();

            Point globalPicSize = new Point(Convert.ToInt32(GetOutlineWidth(parentOutline)), Convert.ToInt32(GetOutlineHeight(parentOutline)));

            foreach (IPcOutline outline in parentOutline.Children)
            {
                if (GetOutlineHeight(outline) > 50 && GetOutlineWidth(outline) > 50)
                {
                    outlineBoundaries.Add(new Point(Convert.ToInt32(GetOutlineWidth(outline)), Convert.ToInt32(GetOutlineHeight(outline))));
                }
            }

            List <PcPhysicalPoint> pictureLocation = new List <PcPhysicalPoint>();

            foreach (IPcPicture pic in picture.Children)
            {
                PcPhysicalPoint loc = new PcPhysicalPoint(pic.PhysicalBoundaries.Location.X * (pic.PixelDensity.X), pic.PhysicalBoundaries.Location.Y * (pic.PixelDensity.Y));
                pictureLocation.Add(loc);
            }

            OutlineParameters op = new OutlineParameters(pictureLocation, outlineBoundaries, globalPicSize);

            return(op);
        }
Пример #8
0
        // -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        //      UI related functions
        // -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

        // This window is responsble for handling the captures of the object that represents, and thus
        // manages the MainCapture thread and hosts capture taking functions
        public CaptureWindow(CapturePreviews capt, Image img, int[] param, string folder, bool[] analysis, string name, PcPhysicalPoint location, System.Drawing.Point size, bool moved, string map)
        {
            InitializeComponent();

            this.Width  = 1200;
            this.Height = 900;

            this.Left = 300;
            this.Top  = 100;


            cp = capt;

            cfs = new List <captureFramework>();

            // A task holds details for a capture process (See <Task> constructior definition)
            List <Uri> u = new List <Uri>();

            t = new Task(this, param[0], param[1], param[2], param[3], u, folder, analysis[0], analysis[1], name, location, size);

            aw = new AnalysisWindow(this, t.getCountAnalysis(), t.getClassAnalysis(), map, folder);

            Directory.CreateDirectory(folder);
            file = new LogFile(t.getFolder(), t.getIndex(), t.getName(), t.getNumberOfCaptures());

            titleLabel.Content = name;

            if (!analysis[0] && !analysis[1])
            {
                generalAnalysisBut.Visibility = Visibility.Hidden;
            }

            // Thread initialization for triggering the captures

            MainCapture newCapture = new MainCapture();

            newCaptureThread = new Thread(newCapture.StartCapture);
            newCaptureThread.SetApartmentState(ApartmentState.STA);
            newCaptureThread.Start(t);
            running = true;
            playing = false;

            // UI elements initialization

            StackPanel aux   = new StackPanel();
            Rectangle  frame = new Rectangle();

            frame.Visibility = Visibility.Hidden;
            frame.Width      = 575;
            frame.Height     = 400;

            frame.Stroke          = Brushes.Black;
            frame.StrokeThickness = 4;

            aux.Children.Add(frame);
            StackPanel.SetZIndex(aux, 10);

            ImagesCanvas.Children.Add(aux);

            StackPanel aux2   = new StackPanel();
            Rectangle  frame2 = new Rectangle();

            frame2.Width  = 500;
            frame2.Height = 120;

            frame2.Stroke          = Brushes.Black;
            frame2.StrokeThickness = 4;

            aux2.Children.Add(frame2);
            StackPanel.SetZIndex(aux2, 10);

            EventsCanvas.Children.Add(aux2);

            FirstCapture(img, moved);

            Info_Init();

            Logo_Init();

            PlayNStop_Init();

            CapturesListBox.SelectionChanged += new SelectionChangedEventHandler(listBoxClicked);

            EventsListBox.SelectionChanged += new SelectionChangedEventHandler(eventClicked);

            if (analysis[0])
            {
                EventsListBox.Visibility = Visibility.Visible; CountAnalysisBut.Visibility = Visibility.Visible; frame.Visibility = Visibility.Visible;
            }

            speed = 1;
        }
Пример #9
0
 public void setLocation(PcPhysicalPoint loc)
 {
     location = loc;
 }
Пример #10
0
        // Parameters are received from MainPage listing the features of the new captures to be built
        // In this method they are built and added to the UI

        public void AddCaptures(List <int[]> parameters, List <int> ind, List <string> folders, List <bool[]> analysis, List <string> names, List <PcPhysicalPoint> locations, List <System.Drawing.Point> sizes, List <string> maps)
        {
            MainCapture       mc      = new MainCapture();
            List <Image>      samples = new List <Image>();
            List <IPcOutline> outlines;

            object[] returnable = new object[3];

            returnable = mc.Samples(folders, ind, locations, sizes);

            samples = (List <Image>)returnable[0];

            outlines = (List <IPcOutline>)returnable[1];

            List <int> moved = (List <int>)returnable[2];

            // Capture Window holds the control of a process.

            int previousCaptures = capturesList.Count;

            for (int i = 0; i < parameters.Count; i++)
            {
                if (moved[i] != 2)
                {
                    PcPhysicalPoint      location = new PcPhysicalPoint(outlines[i].PhysicalBoundaries.Location.X * (outlines[i].PixelDensity.X), outlines[i].PhysicalBoundaries.Location.Y * (outlines[i].PixelDensity.Y));
                    System.Drawing.Point size     = new System.Drawing.Point(Convert.ToInt32(PictureHandling.GetOutlineWidth(outlines[i])), Convert.ToInt32(PictureHandling.GetOutlineHeight(outlines[i])));

                    if (moved[i] == 0)
                    {
                        capturesList.Add(new CaptureWindow(this, samples.ElementAt(i), parameters.ElementAt(parameters.Count - 1 - i),
                                                           folders.ElementAt(folders.Count - 1 - i), analysis.ElementAt(analysis.Count - 1 - i), names.ElementAt(names.Count - 1 - i),
                                                           location, size, false, maps.ElementAt(maps.Count - 1 - i)));
                    }
                    else
                    {
                        capturesList.Add(new CaptureWindow(this, samples.ElementAt(i), parameters.ElementAt(parameters.Count - 1 - i),
                                                           folders.ElementAt(folders.Count - 1 - i), analysis.ElementAt(analysis.Count - 1 - i), names.ElementAt(names.Count - 1 - i),
                                                           location, size, true, maps.ElementAt(maps.Count - 1 - i)));
                    }

                    capturesList.ElementAt(i + previousCaptures).Uid = (i + previousCaptures).ToString();
                    samplesList.Add(samples.ElementAt(i));
                    samplesList.ElementAt(i + previousCaptures).Uid = (i + previousCaptures).ToString();
                    capturesNames.Add(names.ElementAt(names.Count - 1 - i));

                    numberCapturesRunning++;
                }
                else
                {
                    MessageBox.Show("Capture of process " + names.ElementAt(names.Count - 1 - i) + " could not be accomplished. Object not found.");

                    return;
                }
            }

            // UI modification according to new situation

            sampleSP.Children.Clear();
            sampleSP.Children.Add(samplesList.ElementAt(0));

            infoLabel.Content = "Process 1/" + capturesList.Count.ToString();

            if (capturesList.Count >= 2)
            {
                rightSp.Visibility = Visibility.Visible;
                leftSp.Visibility  = Visibility.Visible;
            }

            MainPage.capturesRunning = true;

            Border1.Visibility   = Visibility.Visible;
            Border2.Visibility   = Visibility.Visible;
            sampleSP.Visibility  = Visibility.Visible;
            infoLabel.Visibility = Visibility.Visible;
            nameLabel.Visibility = Visibility.Visible;

            ShowButton.IsEnabled = true;

            // If this is the first time

            if (parameters.Count == capturesList.Count)
            {
                ArtificialScroll();
            }
        }