Example #1
0
        public VisGrainDataCollection(Collection <ClassifierReport> reportType, Collection <ClassifierReport> reportSize, List <VisRectangleContour> listRect)
        {
            Items = new List <VisGrainData>();
            int countSize = reportSize.Count;
            int countType = reportType.Count;
            int count     = 0;

            if (countSize > countType)
            {
                count = countSize;
            }
            else
            {
                count = countType;
            }

            for (int i = 0; i < count; i++)
            {
                ClassifierReport rSize     = reportSize[i];
                ClassifierReport rType     = reportType[i];
                VisGrainSize     grainSize = new VisGrainSize {
                    Name = rSize.BestClassName, ScoreClassification = rSize.ClassificationScore, ScoreIdentification = rSize.IdentificationScore
                };
                VisGrainType grainType = new VisGrainType {
                    Name = rType.BestClassName, ScoreClassification = rType.ClassificationScore, ScoreIdentification = rType.IdentificationScore
                };
                VisGrainData grainData = new VisGrainData(grainType, grainSize, listRect[i]);
                Items.Add(grainData);
            }

            Message = "";
        }
Example #2
0
 // classifyButton_Click is called when the Classify button is pressed. The
 // classify file is read in and the currently-loaded image is classified. The
 // class name and score are then displayed to the user.
 private void classifyButton_Click(object sender, EventArgs e)
 {
     // Classify the image.
     try
     {
         ClassifierReport report = classifier.Classify(imageViewer1.Image, imageViewer1.Roi);
         classBox.Text = report.BestClassName;
         scoreBox.Text = report.ClassificationScore.ToString();
     }
     catch (VisionException)
     {
         // Unable to classify image
         classBox.Text = "Unknown";
         scoreBox.Text = "0";
     }
 }
        private Collection <ClassifierReport> IVA_Classify(VisionImage image, Roi roi, string classifierFilePath)
        {
            //retval = new VisGrainTypeCollection();
            // Create a binary image that will contain the segmented image.
            using (VisionImage binaryImage = new VisionImage(ImageType.U8, 7))
            {
                ParticleClassifierSession vaClassifier = new ParticleClassifierSession();
                bool fileExists = System.IO.File.Exists(classifierFilePath);
                vaClassifier.ReadFile(classifierFilePath);

                // Segments the image.
                Functions.IVA_Classification_Segmentation(image, binaryImage, roi, vaClassifier.PreprocessingOptions);

                // Get the ROIs of all individual particles.
                Collection <Roi> rois = Functions.IVA_Classification_Extract_Particles(image, binaryImage);

                //  Allocates the classifier reports for all objects in the image.
                Collection <ClassifierReport> classifierReports = new Collection <ClassifierReport>();

                List <VisGrainType> listGrainType = new List <VisGrainType>();
                ListShape = new List <VisRectangleContour>();
                // Classifies the object located in the given ROIs.
                for (int i = 0; i < rois.Count; ++i)
                {
                    //RectangleContour rect = binaryImage=new VisionImage()
                    object              obj1      = rois[i][0].Shape;
                    RectangleContour    rc        = (RectangleContour)rois[i][0].Shape;
                    VisRectangleContour rect      = new VisRectangleContour(rc);
                    ClassifierReport    report    = vaClassifier.Classify(image, rois[i]);
                    VisGrainType        grainType = new VisGrainType {
                        Name = report.BestClassName, ScoreClassification = report.ClassificationScore, ScoreIdentification = report.IdentificationScore
                    };
                    listGrainType.Add(grainType);
                    classifierReports.Add(report);

                    ListShape.Add(rect);
                }

                GrainResultsType       = new VisGrainTypeCollection();
                GrainResultsType.Items = listGrainType;

                return(classifierReports);
            }
        }
Example #4
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            double[]           classCount  = new double[8];
            OverlayTextOptions textOptions = new OverlayTextOptions("Arial", 14);

            textOptions.HorizontalAlignment = HorizontalTextAlignment.Center;

            // Get the next image
            GetNextImage(imageViewer1.Image);

            // Process the image
            VisionImage binaryImage = new VisionImage();

            Algorithms.Threshold(imageViewer1.Image, binaryImage, new Range(0, 200));
            Algorithms.RejectBorder(binaryImage, binaryImage);
            Collection <ParticleReport> reports = Algorithms.ParticleReport(binaryImage);

            foreach (ParticleReport report in reports)
            {
                RectangleContour contour = report.BoundingRect;
                contour.Left   -= 10;
                contour.Top    -= 10;
                contour.Height += 20;
                contour.Width  += 20;

                // Classify the part
                ClassifierReport classifierReport = classifier.Classify(binaryImage, new Roi(new Shape[] { contour }));

                // Display the result
                if (classifierReport.ClassificationScore > 500)
                {
                    textOptions.BackgroundColor = Rgb32Value.TransparentColor;
                    int        classIndex = 0;
                    Rgb32Value textColor  = Rgb32Value.BlackColor;
                    switch (classifierReport.BestClassName)
                    {
                    case "Motor":
                        textColor  = Rgb32Value.WhiteColor;
                        classIndex = 0;
                        break;

                    case "Bolt":
                        textColor  = new Rgb32Value(Color.Cyan);
                        classIndex = 1;
                        break;

                    case "Screw":
                        textColor  = Rgb32Value.RedColor;
                        classIndex = 2;
                        break;

                    case "Gear":
                        textColor  = Rgb32Value.BlackColor;
                        classIndex = 3;
                        break;

                    case "Washer":
                        textColor  = new Rgb32Value(Color.Magenta);
                        classIndex = 4;
                        break;

                    case "Worm Gear":
                        textColor  = Rgb32Value.GreenColor;
                        classIndex = 5;
                        break;

                    case "Bracket":
                        textColor  = new Rgb32Value(0x80, 0x80, 0);
                        classIndex = 6;
                        break;
                    }
                    classCount[classIndex]++;
                    imageViewer1.Image.Overlays.Default.AddText(classifierReport.BestClassName, report.CenterOfMass, textColor, textOptions);
                }
                else
                {
                    textOptions.BackgroundColor = Rgb32Value.BlackColor;
                    imageViewer1.Image.Overlays.Default.AddText("Unknown!", report.CenterOfMass, Rgb32Value.RedColor, textOptions);
                }
            }
            classificationGraph1.PlotClassifier(classCount);
        }