private void Form1_Load(object sender, EventArgs e) { // Setup the default path for the classifier file and load it in. classifierPath.Text = System.IO.Path.Combine(ExampleImagesFolder.GetExampleImagesFolder(), @"Classification\Parts.clf"); classifier = new ParticleClassifierSession(classifierPath.Text); // Setup the default path for images imagePath.Text = System.IO.Path.Combine(ExampleImagesFolder.GetExampleImagesFolder(), "Classification"); }
private void Form1_Load(object sender, EventArgs e) { // Get the image path imagePath = System.IO.Path.Combine(ExampleImagesFolder.GetExampleImagesFolder(), "Parts"); imageNumber = 0; // Read the classifier file classifier = new ParticleClassifierSession(System.IO.Path.Combine(imagePath, "Parts.clf")); // Enable the timer timer1.Enabled = true; timer1_Tick(timer1, EventArgs.Empty); }
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); } }