Esempio n. 1
0
        public void SetMask()
        {
            OpenFileDialog dialog = new OpenFileDialog()
            {
                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop), Multiselect = false
            };

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                IImage mask = new FormsImage(dialog.FileName);
                red.Database.SetViewMask("", mask);
            }
        }
Esempio n. 2
0
        public bool Process(Bitmap bmpImg, string strToolName, CDefine.enumVidiType eVidiType)
        {
            bool bReturn = false;

            do
            {
                try
                {
                    IImage img = new FormsImage(bmpImg);
                    m_Sample = Stream.Tools[strToolName].Process(img);
                }
                catch (System.Exception)
                {
                    break;
                }
                bReturn = true;
            } while (false);

            return(bReturn);
        }
Esempio n. 3
0
        public void GetImages()
        {
            FolderBrowserDialog dialog = new FolderBrowserDialog()
            {
                RootFolder = System.Environment.SpecialFolder.Desktop
            };

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                var ext = new System.Collections.Generic.List <string> {
                    ".jpg", ".bmp", ".png"
                };
                var myImagesFiles = Directory.GetFiles(dialog.SelectedPath, "*.*", SearchOption.AllDirectories).Where(s => ext.Any(e => s.EndsWith(e)));
                foreach (var file in myImagesFiles)
                {
                    using (var image = new FormsImage(file))
                    {
                        red.Database.AddImage(image, Path.GetFileName(file));
                    }
                }
            }
        }
Esempio n. 4
0
        public void SettingTools()
        {
            bool local = true; //changes this to false if you want to connect to a runtime service
                               //remote capabilities are only available with advanced licenses
            string remoteServerAddress = "http://*****:*****@"C:\Users\jkhong\Pictures\ZZZZ\", "*.*", SearchOption.AllDirectories).Where(s => ext.Any(e => s.EndsWith(e)));

            foreach (var file in myImagesFiles)
            {
                using (var image = new FormsImage(file))
                {
                    stream.Database.AddImage(image, Path.GetFileName(file));
                }
            }

            //---------------BLUE TOOL----------------------

            //modifying the ROI
            IManualRegionOfInterest blueROI = blue.RegionOfInterest as IManualRegionOfInterest; //gets the region of interest

            //changing the angle
            blueROI.Angle = 10.0;

            //processes all images in order to apply the ROI
            blue.Database.Process();
            //waiting fo the end of the processing
            blue.Wait();

            //get the first view in the database
            var firstView = blue.Database.List().First();

            //add some features to the first view in the database
            blue.Database.AddFeature(firstView, "0", new ViDi2.Point(firstView.Size.Width / 2, firstView.Size.Height / 2), 0.0, 1.0);
            blue.Database.AddFeature(firstView, "1", new ViDi2.Point(firstView.Size.Width / 3, firstView.Size.Height / 3), 0.0, 1.0);

            //adding a model to the blue tool
            var model = blue.Models.Add("model1") as INodeModel;
            //adding some nodes in the model
            var node = model.Nodes.Add();

            node.Fielding = new List <string> {
                "1"
            };
            node.Position = new ViDi2.Point(0.0, 0.0);
            node          = model.Nodes.Add();
            node.Fielding = new List <string> {
                "0"
            };
            node.Position = new ViDi2.Point(1.0, 0.0);

            //changing some parameters
            blue.Parameters.FeatureSize = new ViDi2.Size(30, 30);

            //saving the workspace
            workspace.Save();

            //trains and wait for the training to be finished
            blue.Train();

            try
            {
                while (!blue.Wait(1000))
                {
                    System.Console.WriteLine(blue.Progress.Description + " " + blue.Progress.ETA.ToString());
                }
            }
            catch (ViDi2.Exception e)
            {
                /* you'll likely get a "numeric instability detected" exception
                 * that will put you right here. That happens because the resources
                 * that are being used from the "images" folder are probably not
                 * well suited for the specific stream that we have set up.
                 */
                System.Console.WriteLine(e.Message);
                return;
            }

            var blueSummary = blue.Database.Summary();

            //---------------RED TOOL----------------------

            //setting the roi in the red tool. It is a IBlueRegionOfInterest because the red tool is linked to a blue tool
            var redRoi = red.RegionOfInterest as IBlueRegionOfInterest;

            //selecting the model used for the ROI
            redRoi.MatchFilter = "name='" + model.Name + "'";
            //setting the size of the ROI
            redRoi.Size = new ViDi2.Size(100, 100);

            //applying the ROI on all images
            red.Database.Process();

            //waiting for red tool to finish applying ROI
            red.Wait();

            //changing the rotation perturbation parameter
            red.Parameters.Rotation = new System.Collections.Generic.List <Interval>()
            {
                new Interval(0.0, 360.0)
            };

            //labellling images
            red.Database.LabelViews("'bad'", "bad");  //label good images
            red.Database.LabelViews("not 'bad'", ""); // label bad images
            workspace.Save();

            //training the workspace
            red.Train();
            try
            {
                while (!red.Wait(1000))
                {
                    System.Console.WriteLine(red.Progress.Description + " " + red.Progress.ETA.ToString());
                }
            }
            catch (ViDi2.Exception e)
            {
                System.Console.WriteLine(e.Message);
            }
            var redSummary = red.Database.Summary();

            //---------------GREEN TOOL----------------------

            //Applying the ROI to the green tool
            green.Database.Process();
            red.Wait();

            //tagging the images
            green.Database.Tag("'bad'", "b");
            green.Database.Tag("not 'bad'", "g");

            workspace.Save();
            green.Train();
            try
            {
                while (!green.Wait(1000))
                {
                    System.Console.WriteLine(green.Progress.Description + " " + green.Progress.ETA.ToString());
                }
            }
            catch (ViDi2.Exception e)
            {
                System.Console.WriteLine(e.Message);
            }

            var greenSummary = green.Database.Summary();

            //closing the workspaces
            foreach (var w in control.Workspaces)
            {
                w.Close();
            }
            control.Dispose();
        }