public MatchingParameters(MatchingModelParam param)
 {
     ModelCenterRow = param.ModelCenterRow;
     ModelCenterCol = param.ModelCenterCol;
     InitializeComponent();
     HGraphics                         = new Display(hWindowControl1);
     HGraphics.allObj                  = param.allObj;
     AngleStart                        = param.AngleStart;
     AngleStartText.Text               = AngleStart.ToString();
     AngleExtent                       = param.AngleExtent;
     AngleExtentText.Text              = AngleExtent.ToString();
     NumMatches                        = param.NumMatches;
     NumMatchTextBox.Text              = NumMatches.ToString();
     NumLevels                         = param.NumLevels;
     NumLevelsTextBox.Text             = NumLevels.ToString();
     OptimizationComboBox.SelectedItem = param.Optimization.S;
     SubPixComboBox.SelectedItem       = param.SubPix.S;
     minScoreScroll.Value              = Convert.ToInt16(param.MinScore.D * 100);
     contrastBar.Value                 = param.Contrast;
     OverlapScroll.Value               = Convert.ToInt16(param.Overlap.D * 100);
     GreedinessScroll.Value            = Convert.ToInt16(param.Greediness.D * 100);
     GreedinessValue.Text              = (param.Greediness * 100.0).ToString() + "%";
     CreateModel.Visible               = false;
     groupBox1.Enabled                 = false;
     FindButton.Visible                = true;
 }
Exemplo n.º 2
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");
        }
        public static MatchingModelParam deserialize(string FileName)
        {
            IFormatter         formatter = new BinaryFormatter();
            FileStream         stream    = new FileStream(FileName, FileMode.Open);
            MatchingModelParam param     = (MatchingModelParam)formatter.Deserialize(stream);

            stream.Close();
            return(param);
        }
        public void serialize(string FileName)
        {
            MatchingModelParam param = new MatchingModelParam(ModelCenterRow, ModelCenterCol, AngleStart, AngleExtent,
                                                              minScoreScroll.Value / 100.0, OptimizationComboBox.SelectedItem.ToString().Replace(' ', '_'), contrastBar.Value, HGraphics.allObj, NumMatches,
                                                              OverlapScroll.Value / 100.0, SubPixComboBox.SelectedItem.ToString(), GreedinessScroll.Value / 100.0, NumLevels);
            IFormatter formatter = new BinaryFormatter();
            FileStream stream    = new FileStream(FileName, FileMode.Create);

            formatter.Serialize(stream, param);
            stream.Close();
        }
Exemplo n.º 5
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");
     }
 }
        public void findModel(HObject Image, out HTuple Row, out HTuple Column, out HTuple Angle, out HTuple Score)
        {
            Row    = new HTuple();
            Column = new HTuple();
            Angle  = new HTuple();
            Score  = new HTuple();

            try
            {
                MatchingModelParam param = new MatchingModelParam(ModelCenterRow, ModelCenterCol, AngleStart, AngleExtent,
                                                                  minScoreScroll.Value / 100.0, OptimizationComboBox.SelectedItem.ToString().Replace(' ', '_'), contrastBar.Value, HGraphics.allObj, NumMatches,
                                                                  OverlapScroll.Value / 100.0, SubPixComboBox.SelectedItem.ToString(), GreedinessScroll.Value / 100.0, NumLevels);
                param.findModel(Image, out Row, out Column, out Angle, out Score);
            }
            catch (Exception ex)
            {
                this.ErrorMessage.Text = ex.Message;
            }
        }