예제 #1
0
        public void FindModel(string fileName, out HTuple row, out HTuple col, out HTuple angle, out HTuple score)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            HGraphics.display();
            HOperatorSet.SetColor(hWindowControl.HalconWindow, "green");

            MatchingModelParam modelParam = MatchingParameters.deserialize(fileName);

            modelParam.findModel(HGraphics.allObj["pic"], out row, out col, out angle, out score);

            HOperatorSet.DispCross(hWindowControl.HalconWindow, row, col, 100, 0);
            stopwatch.Stop();
            string s = string.Format("\n{0,15} {1,15} {2,15} {3,15}\n", "Row", "Col", "Phi", "Score");

            for (int i = 0; i < score.Length; i++)
            {
                s += string.Format("{0,15} {1,15} {2,15} {3,15}\n", Math.Round(row[i].D, 2).ToString(), Math.Round(col[i].D, 2).ToString(),
                                   Math.Round(angle[i].D, 2).ToString(), Math.Round(score[i].D, 2).ToString());
            }
            Log(s);
            Log("Instance found: " + score.Length.ToString());
            Log("Duration: " + stopwatch.Elapsed.TotalSeconds.ToString() + " s");
        }
예제 #2
0
        private void CalculateModelCenter(HObject Region, MatchingParameters Form2)
        {
            HTuple area, row, col;

            HOperatorSet.AreaCenter(Region, out area, out row, out col);
            Form2.CentroidRow    = row;
            Form2.CentroidCol    = col;
            Form2.ModelCenterRow = row;
            Form2.ModelCenterCol = col;

            DisplayCross(HGraphics, row, col);

            int x, y;

            x = Convert.ToInt16((double)row);
            y = Convert.ToInt16((double)col);
            Form2.hWindowControl1.HalconWindow.SetPart(x - 30, y - 30, x + 30, y + 30);

            //allows the window control in Form2 to display the same picture and other graphics
            Form2.HGraphics.allObj["pic"]                  = HGraphics.allObj["pic"];
            Form2.HGraphics.allObj["green_cross"]          = HGraphics.allObj["green_cross"];
            Form2.HGraphics.allObj["green_matchingRegion"] = HGraphics.allObj["green_matchingRegion"];
            Form2.HGraphics.allObj["colored_region"]       = HGraphics.allObj["colored_region"];
            Form2.HGraphics.display();
        }
예제 #3
0
 //viewModel_Click calls up open file dialog(.mod) and deserialize the file to MatchingModelParam, which contains graphics of
 //the matching model. Graphics are copied to HGraphics and displayed
 private void viewModel_Click(object sender, EventArgs e)
 {
     try
     {
         if (openShapeModel.ShowDialog() == DialogResult.OK)
         {
             MatchingModelParam param = MatchingParameters.deserialize(openShapeModel.FileName);
             HGraphics.allObj = param.allObj;
             hWindowControl.SetFullImagePart(new HImage(HGraphics.allObj["pic"]));
             HGraphics.display();
             Log("Open model " + Path.GetFileName(openShapeModel.FileName));
         }
     }
     catch (Exception ex)
     {
         Log(ex.ToString() + "\n");
     }
 }
예제 #4
0
        MatchingParameters Form2;//Remember to dispose this when finish creating model

        //This function initializes the matching parameter form
        private void MatchingInitialize()
        {
            if (HGraphics.allObj.ContainsKey("colored_region")) //check if region is empty
            {
                EndRegionSelect -= MatchingInitialize;          // once MatchingInitialize() is executed, unsubscribe from the event EndRegionSelect
                if (Form2 == null)
                {
                    Form2 = new MatchingParameters();
                }
                else
                {
                    DisposeMatchingForm();
                    Form2 = new MatchingParameters();
                }
                try
                {
                    Form2.Show();
                }
                catch
                {
                    Form2 = new MatchingParameters();
                    Form2.Show();
                }

                HGraphics.allObj["green_matchingRegion"] = CalculateShapeModel(30);
                HGraphics.display();
                Form2.contrastBar.Scroll   += InteractiveContrastSelection;
                Form2.CentroidRadio.Checked = true;//Use centroid as model center


                CalculateModelCenter(HGraphics.allObj["green_matchingRegion"], Form2);

                //Subscriptions **remember to unsubscribe**
                hWindowControl.HMouseDown          += ManualCenterSelection;
                Form2.hWindowControl1.HMouseDown   += ManualCenterSelection;
                Form2.CentroidRadio.CheckedChanged += AutoCenterSelection;
                Form2.CreateModel.Click            += CreateModelOK;
                Form2.Cancel.Click += CreateModelCancel;
            }
        }
예제 #5
0
 /*findModelToolStripMenuItem_Click creates a MatchingParameters form and let user change matching parameters and
  * find model*/
 private void findModelToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         if (openShapeModel.ShowDialog() == DialogResult.OK)
         {
             HGraphics.keepOnly(new string[] { "pic" });
             HGraphics.display();
             if (Form2 != null)
             {
                 DisposeMatchingForm();
             }
             Form2 = new MatchingParameters(MatchingParameters.deserialize(openShapeModel.FileName));
             Form2.Show();
             Form2.FindButton.Click += findModelClick;
         }
     }
     catch (Exception ex)
     {
         Log(ex.ToString() + "\n");
     }
 }