Пример #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
        // Outlines capture
        public static OutlineParameters ConfirmCapture()
        {
            try
            {
                using (IPcLink link = HPPC.CreateLink())
                {
                    using (IPcMoment moment = link.CaptureMoment())
                    {
                        IPcPicture picture = link.ExtractPicture(moment);
                        IPcOutline outline = link.ExtractOutline(moment);

                        OutlineParameters op = PictureHandling.SavePicture(picture, outline);
                        return(op);
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine("\t\t*****An error occurred*****\n\n{0}{1}\n\nExit now, or this console will automatically exit in 15 seconds.", ToolBox.TimeStamp(), exception.Message);
                ToolBox.AppExceptionExit();
                return(null);
            }
        }
Пример #3
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);
        }
Пример #4
0
        // Object scan. This method can be called repeatedly
        private void objectShow_Button_Click(object sender, RoutedEventArgs e)
        {
            parameters = new List <int[]>();
            CaptureDetailsLabel.Content = "";

            // Acquisition of outlines to define existing objects

            MainCapture       newCapture = new MainCapture();
            OutlineParameters op         = newCapture.ConfirmCapture();

            int numberObjects = OutlineParameters.getCapacity(op);

            if ((op.getSize(op).ElementAt(0).X > 4000) && (op.getSize(op).ElementAt(0).Y > 3000))
            {
                MessageBox.Show("No objects could be found");
                return;
            }

            List <System.Windows.Shapes.Rectangle> outlineDefinitionList = new List <System.Windows.Shapes.Rectangle>();

            // Selection border holds a definition for an object and it's showing structure. (See SelectionBorder constructor definition)
            List <SelectionBorder> transparentCanvasList = new List <SelectionBorder>();

            System.Drawing.Point globalPicSize = op.getGlobalSize(op);

            ImageBorder.Visibility = Visibility.Visible;

            ImageCanvas.Children.Clear();
            ImageCanvas.Children.Add(objectShowStackPanel);

            // Definiton of objects by their outlines
            for (int i = 0; i < numberObjects; i++)
            {
                // Rectangle definition

                outlineDefinitionList.Add(new System.Windows.Shapes.Rectangle());
                outlineDefinitionList.ElementAt(i).Width  = (op.getSize(op).ElementAt(i).X *790) / globalPicSize.X; // Window/Canvas ratio
                outlineDefinitionList.ElementAt(i).Height = (op.getSize(op).ElementAt(i).Y *590) / globalPicSize.Y;

                ImageCanvas.Children.Add(outlineDefinitionList.ElementAt(i));
                outlineDefinitionList.ElementAt(i).Stroke          = System.Windows.Media.Brushes.LightGreen;
                outlineDefinitionList.ElementAt(i).StrokeThickness = 3;
                outlineDefinitionList.ElementAt(i).Margin          =
                    new Thickness((op.getLocation(op).ElementAt(i).X * 790) / globalPicSize.X, (op.getLocation(op).ElementAt(i).Y * 590) / globalPicSize.Y, 0, 0);

                // Canvas definition

                transparentCanvasList.Add(new SelectionBorder(i, new Border()));
                transparentCanvasList.ElementAt(i).Width  = (op.getSize(op).ElementAt(i).X * 790) / globalPicSize.X; // Window/Canvas ratio
                transparentCanvasList.ElementAt(i).Height = (op.getSize(op).ElementAt(i).Y * 590) / globalPicSize.Y;

                transparentCanvasList.ElementAt(i).MouseDown += new MouseButtonEventHandler(RectangleClickedHandler);
                ImageCanvas.Children.Add(transparentCanvasList.ElementAt(i));
                transparentCanvasList.ElementAt(i).Opacity     = 0;
                transparentCanvasList.ElementAt(i).Background  = System.Windows.Media.Brushes.Green;
                transparentCanvasList.ElementAt(i).MouseEnter += new MouseEventHandler(BorderMouseEnterHandlerEnter);
                transparentCanvasList.ElementAt(i).MouseLeave += new MouseEventHandler(BorderMouseEnterHandlerLeave);

                transparentCanvasList.ElementAt(i).Margin =
                    new Thickness((op.getLocation(op).ElementAt(i).X * 790) / globalPicSize.X, (op.getLocation(op).ElementAt(i).Y * 590) / globalPicSize.Y, 0, 0);
            }

            objectShowStackPanel.Visibility = Visibility.Visible;

            // Global scan of the mat screen acquisition

            System.Windows.Controls.Image globalImg = new System.Windows.Controls.Image();
            BitmapImage src = new BitmapImage();

            src.BeginInit();
            src.UriSource   = new Uri(PictureHandling.confirmPath, UriKind.Relative);
            src.CacheOption = BitmapCacheOption.OnLoad;
            src.EndInit();
            globalImg.Source  = src;
            globalImg.Stretch = Stretch.Uniform;

            objectShowStackPanel.Children.Clear();
            objectShowStackPanel.Children.Add(globalImg);

            ShowButton.Content          = "Scan new Layout";
            ParametersBorder.Visibility = Visibility.Hidden;
        }
Пример #5
0
        // Outline capture
        public OutlineParameters ConfirmCapture()
        {
            OutlineParameters op = MomentCapture.ConfirmCapture();

            return(op);
        }
Пример #6
0
 public static int getCapacity(OutlineParameters op)
 {
     return(op.size.Count());
 }
Пример #7
0
 public Point getGlobalSize(OutlineParameters op)
 {
     return(op.globalPicSize);
 }
Пример #8
0
 public List <Point> getSize(OutlineParameters op)
 {
     return(op.size);
 }
Пример #9
0
 // Getters and setters
 public List <PcPhysicalPoint> getLocation(OutlineParameters op)
 {
     return(op.location);
 }