Example #1
0
 public frmMain()
 {
     InitializeComponent();
     //myConfig = new ConfigInfo();
     //Pro.SelectedObject = myConfig;
     //Pro.PropertyValueChanged += Pro_PropertyValueChanged;
     nExpTime           = 2000;
     fCamGain           = 1.1f;
     bVideoMode         = false;
     strSavePathOK      = "";
     strSavePathNG      = "";
     strFileName        = "";
     imgOri             = null;
     detectInstanceDyn  = null;
     detectInstanceNorm = null;
 }
Example #2
0
        private void measure_2D_Click(object sender, EventArgs e)
        {

            if (Mainpicture != null)
            {
                HDevelopExport1 HD = new HDevelopExport1(Mainpicture.Clone());
                
            }
            else
                MessageBox.Show("沒有讀取到圖片喔");
        }
Example #3
0
        /// <summary>
        /// 检测函数
        /// </summary>
        private void Detect()
        {
            pbImage.Visible     = false;
            hWindowCtrl.Visible = true;
            if (imgOri != null)
            {
                Int32  nDefects = 0;
                Int32  nMode    = 0; // detection method selection
                String strFullFileName;

                if (string.IsNullOrEmpty(ParamSetting.ImageSavePath))
                {
                    ParamSetting.ImageSavePath = Application.StartupPath;
                }

                strFullFileName = ParamSetting.ImageSavePath + "\\" + strFileName;

                // save temp image
                imgOri.Save(strFullFileName);

                switch (nMode)
                {
                case 0:
                    // method 0: dynamic thresholding
                    detectInstanceDyn = new HDevelopExport();
                    detectInstanceDyn.InitHalcon();
                    if (File.Exists(strFullFileName))
                    {
                        detectInstanceDyn.RunHalcon(hWindowCtrl.HalconWindow, strFullFileName, ParamSetting.MeasureParam.MinArea, ParamSetting.MeasureParam.FilterSize, ParamSetting.MeasureParam.DynamicRange, out nDefects);
                    }
                    break;

                case 1:
                    // method 1: normal thresholding
                    detectInstanceNorm = new HDevelopExport1();
                    detectInstanceNorm.InitHalcon();
                    if (File.Exists(strFullFileName))
                    {
                        detectInstanceNorm.RunHalcon(hWindowCtrl.HalconWindow, strFullFileName, ParamSetting.MeasureParam.MinArea, ParamSetting.MeasureParam.GrayThreshold, out nDefects);
                    }
                    break;
                }

                if (nDefects > 0)
                {
                    lblResult.Text      = "NG";
                    lblResult.BackColor = Color.Red;
                    if (!string.IsNullOrEmpty(ParamSetting.ImageSavePath))
                    {
                        strSavePathNG = ParamSetting.ImageSavePath + "\\" + DateTime.Now.ToShortDateString().Replace("/", "-") + "\\NG";
                        CheckAndCreatePath(strSavePathNG);
                        if (pbImage.Image != null)
                        {
                            pbImage.Image.Save(strSavePathNG + "\\" + strFileName);
                        }
                    }
                }
                else
                {
                    lblResult.Text      = "OK";
                    lblResult.BackColor = Color.Green;
                    if (!string.IsNullOrEmpty(ParamSetting.ImageSavePath))
                    {
                        strSavePathOK = ParamSetting.ImageSavePath + "\\" + DateTime.Now.ToShortDateString().Replace("/", "-") + "\\OK";
                        CheckAndCreatePath(strSavePathOK);
                        if (pbImage.Image != null)
                        {
                            pbImage.Image.Save(strSavePathOK + "\\" + strFileName);
                        }
                    }
                }
            }

            pbImage.Image = imgOri;
        }
Example #4
0
        /* 检测按钮事件 */
        private void btnDetect_Click(object sender, EventArgs e)
        {
            pbImage.Visible     = false;
            hWindowCtrl.Visible = true;
            if (imgOri != null)
            {
                Int32  nDefects = 0;
                Int32  nMode    = 1;
                String strFullFileName;

                if (strSavePath == "")
                {
                    strSavePath = Application.StartupPath;
                }

                strFullFileName = strSavePath + strFileName;

                // save temp image

                imgOri.Save(strFullFileName);

                switch (nMode)
                {
                case 0:
                    // method 0: dynamic thresholding
                    detectInstanceDyn = new HDevelopExport();
                    detectInstanceDyn.InitHalcon();
                    if (File.Exists(strFullFileName))
                    {
                        detectInstanceDyn.RunHalcon(hWindowCtrl.HalconWindow, strFullFileName, myConfig.面积, myConfig.滤波尺寸, myConfig.动态二值化阈值, out nDefects);
                    }
                    break;

                case 1:
                    // method 1: normal thresholding
                    detectInstanceNorm = new HDevelopExport1();
                    detectInstanceNorm.InitHalcon();
                    if (File.Exists(strFullFileName))
                    {
                        detectInstanceNorm.RunHalcon(hWindowCtrl.HalconWindow, strFullFileName, myConfig.面积, myConfig.灰度值, out nDefects);
                    }
                    break;
                }

                if (nDefects > 0)
                {
                    lblResult.Text      = "NG";
                    lblResult.BackColor = Color.Red;
                    if (strSavePath != null && strSavePath.Length != 0)
                    {
                        strSavePathNG = strSavePath + "\\NG";
                        CheckAndCreatePath(strSavePathNG);
                        if (pbImage.Image != null)
                        {
                            pbImage.Image.Save(strSavePathNG + "\\" + strFileName);
                        }
                    }
                }
                else
                {
                    lblResult.Text      = "OK";
                    lblResult.BackColor = Color.Green;
                    if (strSavePath != null && strSavePath.Length != 0)
                    {
                        strSavePathOK = strSavePath + "\\OK";
                        CheckAndCreatePath(strSavePathOK);
                        if (pbImage.Image != null)
                        {
                            pbImage.Image.Save(strSavePathOK + "\\" + strFileName);
                        }
                    }
                }
            }

            pbImage.Image = imgOri;
        }