예제 #1
0
        private void tsmi_Next_Click(object sender, EventArgs e)
        {
            DrawMode(true);                                                                                         //绘制模式开启
            Rectangle1 rectangle1 = Func_HalconFunction.DrawRectangle1(hWindow_Final1.hWindowControl.HalconWindow); //画矩形

            DrawMode(false);                                                                                        //绘制模式关闭
            HObject ho_Rectangle = Func_HalconFunction.GenRectangle1(rectangle1);                                   //创建矩形

            hWindow_Final1.DispObj(ho_Rectangle, "blue");                                                           //显示矩形

            GetLineUseThreshold line = new GetLineUseThreshold(new Threshold(Func_Mathematics.ToRectangle2(rectangle1)));

            getSetOfLines.AddLine(line);
        }
예제 #2
0
 private void cmb_slg_SelectItem_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (cmb_slg_SelectItem.SelectedItem == null)
     {
         btn_slg_ReDrowROI.Enabled = false;
         nud_slg_b_pex.Enabled     = false;
         return;
     }
     slgLine = getSetOfLines.GetLine(cmb_slg_SelectItem.SelectedIndex) as GetLineUseThreshold;//获取选择的项
     trb_slg_MaxGray.Value     = slgLine.parameter.hv_MaxGray.I;
     trb_slg_MinGray.Value     = slgLine.parameter.hv_MinGray.I;
     nud_slg_MaxGray.Value     = slgLine.parameter.hv_MaxGray.I;
     nud_slg_MinGray.Value     = slgLine.parameter.hv_MinGray.I;
     nud_slg_b_pex.Value       = (decimal)slgLine.b.D;
     btn_slg_ReDrowROI.Enabled = true;
     nud_slg_b_pex.Enabled     = true;
 }
예제 #3
0
        private void btn_DrawROIs_Click(object sender, EventArgs e)
        {
            getSetOfLines.RemoveAll();                                                                              //删除所有项
            hWindow_Final1.HobjectToHimage(ho_Image);                                                               //刷新图片
            hWindow_Final1.ContextMenuStrip = contextMenuStrip1;                                                    //启用右键菜单
            DrawMode(true);                                                                                         //绘制模式开启
            Rectangle1 rectangle1 = Func_HalconFunction.DrawRectangle1(hWindow_Final1.hWindowControl.HalconWindow); //画矩形

            DrawMode(false);                                                                                        //绘制模式关闭
            HObject ho_Rectangle = Func_HalconFunction.GenRectangle1(rectangle1);                                   //创建矩形

            hWindow_Final1.DispObj(ho_Rectangle, "blue");                                                           //显示矩形
            //创建该项
            GetLineUseThreshold line = new GetLineUseThreshold(new Threshold(Func_Mathematics.ToRectangle2(rectangle1)));

            getSetOfLines.AddLine(line);            //添加该项
            cmb_slg_SelectItem.SelectedItem = null; //
            slgLine = null;
        }
예제 #4
0
        private void Ufrm_Line_Load(object sender, EventArgs e)
        {
            hWindow_Final1.HobjectToHimage(ho_Image);
            if (measureManager == null)
            {
                measureManager = form.measureManager;
            }

            #region 跟踪
            List <MeasuringUnit> translations = measureManager.ListAllTranslation();//所有平移跟踪

            verticalPositions   = new List <MeasuringUnit>();
            horizontalPositions = new List <MeasuringUnit>();
            for (int i = translations.Count - 1; i >= 0; i--)
            {
                if ((translations[i] as TranslationTracking).line.AxByC0.k == null)
                {
                    horizontalPositions.Add(translations[i]);
                    cmb_HorizontalTracking.Items.Add(translations[i].name);
                }

                else if ((translations[i] as TranslationTracking).line.AxByC0.k.D == 0) //?是水平线
                {
                    verticalPositions.Add(translations[i]);                             //添加垂直定位
                    cmb_VerticalTracking_L.Items.Add(translations[i].name);             //添加垂直跟踪
                }
            }
            #endregion

            cmb_Transition.SelectedIndex = 0;
            cmb_Select.SelectedIndex     = 0;


            //判断是否编辑模式进入
            if (EditMode)
            {
                line          = data as Line;
                txt_Name.Text = data.name;
                //  txt_Name.Enabled = false;//编辑模式下不能编辑名字
                if (data is GetLineUseThreshold)
                {
                    GetLineUseThreshold getLine = data as GetLineUseThreshold;

                    nud_MaxGray.Value   = trb_MaxGray.Value = getLine.parameter.hv_MaxGray;
                    nud_MinGray.Value   = trb_MinGray.Value = getLine.parameter.hv_MinGray;
                    nud_slg_b_pex.Value = (decimal)getLine.b.D;
                    if (2 == getLine.TPLR)
                    {
                        rdo_DownEdge.Checked = true;
                    }
                    if (3 == getLine.TPLR)
                    {
                        rdo_LeftEdge.Checked = true;
                    }
                    if (4 == getLine.TPLR)
                    {
                        rdo_RightEdge.Checked = true;
                    }
                    if (true == getLine.AngularPoint)
                    {
                        checkBox1.Checked = true;
                    }

                    if (getLine.position_Horizontal != null)
                    {
                        cmb_HorizontalTracking.SelectedItem = getLine.position_Horizontal.name;
                    }

                    if (getLine.position_Vertical_L != null)
                    {
                        cmb_VerticalTracking_L.SelectedItem = getLine.position_Vertical_L.name;
                    }


                    tabControl1.SelectedTab = tp_Threshold;
                    tabControl1.TabPages.Remove(tp_Metrology);

                    tabControl1.TabPages.Remove(tp_Measure_Pos);

                    sign = LineStyle.灰度抓取;
                }
                else if (data is GetLineUseMeasure_Pos)
                {
                    GetLineUseMeasure_Pos getLine = data as GetLineUseMeasure_Pos;
                    trb_AmplitudeThreshold.Value = getLine.parameter.hv_AmplitudeThreshold;
                    nud_AmplitudeThreshold.Value = (decimal)getLine.parameter.hv_AmplitudeThreshold.D;
                    trb_Sigma.Value       = getLine.parameter.hv_Sigma;
                    nud_Sigma.Value       = (decimal)getLine.parameter.hv_Sigma.D;
                    trb_RoiWidthLen.Value = getLine.parameter.hv_RoiWidthLen2;
                    nud_RoiWidthLen.Value = (decimal)getLine.parameter.hv_RoiWidthLen2.D;
                    if (getLine.parameter.hv_Transition == "positive")
                    {
                        rdo_TranslationPositive.Checked = true;
                        rdo_TranslationNegative.Checked = false;
                    }
                    else
                    {
                        rdo_TranslationPositive.Checked = false;
                        rdo_TranslationNegative.Checked = true;
                    }
                    tabControl1.SelectedTab = tp_Measure_Pos;

                    tabControl1.TabPages.Remove(tp_Threshold);
                    tabControl1.TabPages.Remove(tp_Metrology);

                    sign = LineStyle.边缘检测;
                }

                /* else if (data is GetLineUseCanny)
                 * {
                 *   GetLineUseCanny getLine = data as GetLineUseCanny;
                 *   nud_Alpha.Value = (decimal)getLine.parameter.hv_Alpha.D;
                 *   nud_High.Value = (decimal)getLine.parameter.hv_High.D;
                 *   nud_Low.Value = (decimal)getLine.parameter.hv_Low.D;
                 *   trb_High.Value = getLine.parameter.hv_High.I;
                 *   trb_Low.Value = getLine.parameter.hv_Low.I;
                 *   tabControl1.SelectedTab = tp_Canny;
                 *
                 *
                 *   if (getLine.position_Horizontal != null)
                 *   {
                 *       cmb_HorizontalTracking.SelectedItem = getLine.position_Horizontal.name;
                 *   }
                 *
                 *   if (getLine.position_Vertical_L != null)
                 *   {
                 *       cmb_VerticalTracking_L.SelectedItem = getLine.position_Vertical_L.name;
                 *   }
                 *
                 *
                 *   tabControl1.TabPages.Remove(tp_Threshold);
                 *   tabControl1.TabPages.Remove(tp_Measure_Pos);
                 *
                 *   sign = LineStyle.边缘拟合;
                 * }*/
                else if (data is GetLineUseMetrology)
                {
                    GetLineUseMetrology getLine = data as GetLineUseMetrology;
                    nud_Length1.Value   = (decimal)getLine.parameter.measureLength1.D;
                    nud_Length2.Value   = (decimal)getLine.parameter.measureLength2.D;
                    nud_Distance.Value  = (decimal)getLine.parameter.measureDistance.D;
                    nud_Threshold.Value = (decimal)getLine.parameter.measureThreshold.D;
                    if (getLine.parameter.measureTransition == "positive")
                    {
                        cmb_Transition.SelectedIndex = 0;
                    }
                    if (getLine.parameter.measureTransition == "negative")
                    {
                        cmb_Transition.SelectedIndex = 1;
                    }
                    if (getLine.parameter.measureTransition == "all")
                    {
                        cmb_Transition.SelectedIndex = 2;
                    }
                    if (getLine.parameter.measureSelect == "first")
                    {
                        cmb_Select.SelectedIndex = 0;
                    }
                    if (getLine.parameter.measureSelect == "last")
                    {
                        cmb_Select.SelectedIndex = 1;
                    }
                    if (getLine.parameter.measureSelect == "all")
                    {
                        cmb_Select.SelectedIndex = 2;
                    }

                    tabControl1.SelectedTab = tp_Metrology;

                    tabControl1.TabPages.Remove(tp_Threshold);
                    tabControl1.TabPages.Remove(tp_Measure_Pos);

                    sign = LineStyle.直线拟合;
                }
                prepared = true;
            }

            else
            {
                line = new GetLineUseThreshold();
                data = line;
                sign = LineStyle.灰度抓取;
            }
            RunOnce();
        }