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);
            }
        }
Ejemplo n.º 2
0
        private void browseButton_Click(object sender, EventArgs e)
        {
            openFileDialog1.InitialDirectory = classifierPath.Text;
            openFileDialog1.FileName         = "";
            openFileDialog1.Title            = "Select a classifier file";
            openFileDialog1.DefaultExt       = "*.clf";
            openFileDialog1.Filter           = "*.clf|*.clf";

            // Select the file
            DialogResult result = openFileDialog1.ShowDialog();

            // Don't set the path if the user cancelled.
            if (result == DialogResult.OK)
            {
                classifierPath.Text = openFileDialog1.FileName;
                // Read the classifier file.
                classifier.ReadFile(classifierPath.Text);
            }
        }