示例#1
0
 public ShapeModle()
 {
     InitializeComponent();
     cmB_TrainOptimization.DataSource = Enum.GetValues(typeof(EnumOptimization));
     cmB_TrainMetric.DataSource       = Enum.GetValues(typeof(EnumMetric));
     cmB_TrainContrast.DataSource     = Enum.GetValues(typeof(EnumContrast));
     cmB_FindSubpixel.DataSource      = Enum.GetValues(typeof(EnumSubpixel));
     m_paramTrain = new ShapeModleParameterTrain();
     m_paramFind  = new ShapeModelParameterFind();
     AddEvent();
 }
示例#2
0
        /// <summary>
        /// 加载模板及模板参数
        /// </summary>
        /// <param name="directoryPath">保存相关内容的文件夹路径</param>
        public void LoadModle(string directoryPath)
        {
            if (!Directory.Exists(directoryPath))
            {
                throw new Exception("未能找到指定路径");
            }
            var  files     = Directory.GetFiles(directoryPath, ".");
            bool _findFile = false;

            foreach (var member in files)
            {
                string extension = Path.GetExtension(member);
                if (extension == ".shm")
                {
                    HOperatorSet.ReadShapeModel(member, out m_modleHandle);
                    _findFile = true;
                    break;
                }
            }
            if (!_findFile)
            {
                throw new Exception("指定路径中未能找到模板文件(.shm)");
            }
            foreach (var member in files)
            {
                string extension = Path.GetExtension(member);
                if (extension == ".MP")
                {
                    try
                    {
                        using (Stream stream = new FileStream(member, FileMode.Open, FileAccess.Read))
                        {
                            //XmlSerializer xmlSerializer = new XmlSerializer(typeof(List<object>));
                            //List<object> datas = xmlSerializer.Deserialize(stream) as List<object>;
                            BinaryFormatter bf    = new BinaryFormatter();
                            List <object>   datas = bf.Deserialize(stream) as List <object>;

                            m_paramTrain = (ShapeModleParameterTrain)datas[0];
                            m_paramFind  = (ShapeModelParameterFind)datas[1];
                            hDisplay1.SetROIList(datas[2] as System.Collections.ArrayList);
                            RemoveRvent();

                            nmUD_TrainAngleStart.Value  = m_paramTrain.AngleStart;
                            nmUD_TrainAngleExtent.Value = m_paramTrain.AngleExtent;
                            nmUD_FindAngleStep.Value    = (decimal)m_paramTrain.AngleStep;
                            nmUD_TrainNumLevels.Value   = m_paramTrain.NumLevels;
                            cmB_TrainOptimization.Text  = m_paramTrain.Optimization;
                            cmB_TrainMetric.Text        = m_paramTrain.Metric;


                            if (m_paramTrain.Contrast.Type == HTupleType.STRING)
                            {
                                cmB_TrainContrast.Text = m_paramTrain.Contrast;
                            }
                            else
                            {
                                cmB_TrainContrast.Text = m_paramTrain.Contrast.ToString();
                            }
                            if (m_paramTrain.MinContrast.Type == HTupleType.STRING)
                            {
                                cmB_TrainMinContrast.Text = m_paramTrain.MinContrast;
                            }
                            else
                            {
                                cmB_TrainMinContrast.Text = m_paramTrain.MinContrast.ToString();
                            }

                            nmUD_FindAngleStart.Value  = m_paramFind.AngleStart;
                            nmUD_FindAngleExtent.Value = m_paramFind.AngleExtent;
                            nmUD_FindAngleStep.Value   = (decimal)m_paramFind.AngleStep;
                            nmUD_FindMinScore.Value    = (decimal)m_paramFind.MinScore;
                            nmUD_FindNumMachs.Value    = m_paramFind.NumMatch;
                            nmUD_FindMaxOverLap.Value  = (decimal)m_paramFind.MaxOverLap;
                            nmUD_FindNumLevels.Value   = m_paramFind.NumLevels;
                            nmUD_FindGreediness.Value  = (decimal)m_paramFind.Greediness;
                            cmB_FindSubpixel.Text      = m_paramFind.SubPixel;

                            AddEvent();
                        }
                        _findFile = true;
                        break;
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }
            if (!_findFile)
            {
                throw new Exception("指定路径中未能找到模板参数文件(.MP)");
            }
        }
示例#3
0
        private void btn_LoadModleIInfo_Click(object sender, EventArgs e)
        {
            using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog())
            {
                folderBrowserDialog.Description = "请选择模板文件夹";

                folderBrowserDialog.ShowNewFolderButton = false;
                if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
                {
                    var files = Directory.GetFiles(folderBrowserDialog.SelectedPath, ".");
                    foreach (var file in files)
                    {
                        string extension = Path.GetExtension(file);
                        if (Path.GetExtension(file) == ".shm")
                        {
                            HOperatorSet.ReadShapeModel(file, out m_modleHandle);
                        }
                        else if (Path.GetExtension(file) == ".MP")
                        {
                            try
                            {
                                using (Stream stream = new FileStream(file, FileMode.Open, FileAccess.Read))
                                {
                                    //XmlSerializer xmlSerializer = new XmlSerializer(typeof(List<object>));
                                    //List<object> datas = xmlSerializer.Deserialize(stream) as List<object>;
                                    BinaryFormatter bf    = new BinaryFormatter();
                                    List <object>   datas = bf.Deserialize(stream) as List <object>;

                                    m_paramTrain = (ShapeModleParameterTrain)datas[0];
                                    m_paramFind  = (ShapeModelParameterFind)datas[1];
                                    // System.Collections.ArrayList regionXes = datas[2] as System.Collections.ArrayList;
                                    hDisplay1.SetROIList(datas[2] as System.Collections.ArrayList);


                                    RemoveRvent();

                                    nmUD_TrainAngleStart.Value  = m_paramTrain.AngleStart;
                                    nmUD_TrainAngleExtent.Value = m_paramTrain.AngleExtent;
                                    nmUD_FindAngleStep.Value    = (decimal)m_paramTrain.AngleStep;
                                    nmUD_TrainNumLevels.Value   = m_paramTrain.NumLevels;
                                    cmB_TrainOptimization.Text  = m_paramTrain.Optimization;
                                    cmB_TrainMetric.Text        = m_paramTrain.Metric;
                                    if (m_paramTrain.Contrast.Type == HTupleType.STRING)
                                    {
                                        cmB_TrainContrast.Text = m_paramTrain.Contrast;
                                    }
                                    else
                                    {
                                        cmB_TrainContrast.Text = m_paramTrain.Contrast.ToString();
                                    }
                                    if (m_paramTrain.MinContrast.Type == HTupleType.STRING)
                                    {
                                        cmB_TrainMinContrast.Text = m_paramTrain.MinContrast;
                                    }
                                    else
                                    {
                                        cmB_TrainMinContrast.Text = m_paramTrain.MinContrast.ToString();
                                    }


                                    nmUD_FindAngleStart.Value  = m_paramFind.AngleStart;
                                    nmUD_FindAngleExtent.Value = m_paramFind.AngleExtent;
                                    nmUD_FindAngleStep.Value   = (decimal)m_paramFind.AngleStep;
                                    nmUD_FindMinScore.Value    = (decimal)m_paramFind.MinScore;
                                    nmUD_FindNumMachs.Value    = m_paramFind.NumMatch;
                                    nmUD_FindMaxOverLap.Value  = (decimal)m_paramFind.MaxOverLap;
                                    nmUD_FindNumLevels.Value   = m_paramFind.NumLevels;
                                    nmUD_FindGreediness.Value  = (decimal)m_paramFind.Greediness;
                                    cmB_FindSubpixel.Text      = m_paramFind.SubPixel;

                                    AddEvent();
                                }
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message, "异常");
                            }
                        }
                    }
                }
            }
        }