Exemplo n.º 1
0
        private void btn_Draw_Click(object sender, EventArgs e)
        {
            DrawMode(true);                                                                         //绘制模式开启

            line.SetLine(Func_HalconFunction.DrawLine(hWindow_Final1.hWindowControl.HalconWindow)); //画线

            DrawMode(false);                                                                        //绘制模式关闭

            nud_xStart.Value = (decimal)line.hv_Column1.D;                                          //赋值
            nud_yStart.Value = (decimal)line.hv_Row1.D;                                             //赋值
            nud_xEnd.Value   = (decimal)line.hv_Column2.D;                                          //赋值
            nud_yEnd.Value   = (decimal)line.hv_Row2.D;                                             //赋值

            prepared = true;
            RunOnce();
        }
Exemplo n.º 2
0
        private void btn_Draw_Click(object sender, EventArgs e)
        {
            hWindow_Final1.HobjectToHimage(ho_Image);//刷新
            TabPage tabPage = tabControl1.SelectedTab;

            if (tabPage != null)
            {
                if (tabPage.Name == "tp_Threshold")
                {
                    if (!(line is GetLineUseThreshold))
                    {
                        line = new GetLineUseThreshold();
                        data = line;
                    }
                    if (chk_Angle.Checked)
                    {
                        DrawMode(true);                                                                                                                      //绘制模式开启
                        (line as GetLineUseThreshold).parameter.rectangle2 = Func_HalconFunction.DrawRectangle2(hWindow_Final1.hWindowControl.HalconWindow); //画矩形
                        DrawMode(false);                                                                                                                     //绘制模式关闭
                    }
                    else
                    {
                        DrawMode(true);                                                                                         //绘制模式开启
                        Rectangle1 rectangle1 = Func_HalconFunction.DrawRectangle1(hWindow_Final1.hWindowControl.HalconWindow); //画矩形
                        DrawMode(false);                                                                                        //绘制模式关闭
                        (line as GetLineUseThreshold).parameter.rectangle2 = Func_Mathematics.ToRectangle2(rectangle1);         //ROI矩形赋值
                    }
                    sign = LineStyle.灰度抓取;
                }
                if (tabPage.Name == "tp_Measure_Pos")
                {
                    if (!(line is GetLineUseMeasure_Pos))//?不是GetLineUseMeasure_Pos
                    {
                        line = new GetLineUseMeasure_Pos();
                        data = line;
                    }
                    DrawMode(true);                                                                                                                   //绘制模式开启
                    (line as GetLineUseMeasure_Pos).parameter.line.SetLine(Func_HalconFunction.DrawLine(hWindow_Final1.hWindowControl.HalconWindow)); //画ROI线
                    DrawMode(false);                                                                                                                  //绘制模式关闭
                    if (!chk_Angle.Checked)
                    {
                        double dx = (line as GetLineUseMeasure_Pos).parameter.line.hv_Column1 - (line as GetLineUseMeasure_Pos).parameter.line.hv_Column2;
                        double dy = (line as GetLineUseMeasure_Pos).parameter.line.hv_Row1 - (line as GetLineUseMeasure_Pos).parameter.line.hv_Row2;
                        double mx = ((line as GetLineUseMeasure_Pos).parameter.line.hv_Column1 + (line as GetLineUseMeasure_Pos).parameter.line.hv_Column2) / 2;
                        double my = ((line as GetLineUseMeasure_Pos).parameter.line.hv_Row1 + (line as GetLineUseMeasure_Pos).parameter.line.hv_Row2) / 2;
                        if (Math.Abs(dx) > Math.Abs(dy))//?横向距离长
                        {
                            (line as GetLineUseMeasure_Pos).parameter.line.hv_Row1 = (int)my;
                            (line as GetLineUseMeasure_Pos).parameter.line.hv_Row2 = (int)my;
                        }
                        else//?纵向距离长
                        {
                            (line as GetLineUseMeasure_Pos).parameter.line.hv_Column1 = (int)mx;
                            (line as GetLineUseMeasure_Pos).parameter.line.hv_Column2 = (int)mx;
                        }
                    }
                    sign = LineStyle.边缘检测;
                }
                if (tabPage.Name == "tp_Canny")
                {
                    if (!(line is GetLineUseCanny))//?不是GetLineUseMeasure_Pos
                    {
                        line = new GetLineUseCanny();
                        data = line;
                    }
                    if (chk_Angle.Checked)
                    {
                        DrawMode(true);                                                                                                                  //绘制模式开启
                        (line as GetLineUseCanny).parameter.rectangle2 = Func_HalconFunction.DrawRectangle2(hWindow_Final1.hWindowControl.HalconWindow); //画矩形
                        DrawMode(false);                                                                                                                 //绘制模式关闭
                    }
                    else
                    {
                        DrawMode(true);                                                                                         //绘制模式开启
                        Rectangle1 rectangle1 = Func_HalconFunction.DrawRectangle1(hWindow_Final1.hWindowControl.HalconWindow); //画矩形
                        DrawMode(false);                                                                                        //绘制模式关闭
                        (line as GetLineUseCanny).parameter.rectangle2 = Func_Mathematics.ToRectangle2(rectangle1);             //ROI矩形赋值
                    }
                    sign = LineStyle.边缘拟合;
                }

                if (tabPage.Name == "tp_Metrology")
                {
                    if (!(line is GetLineUseMetrology))
                    {
                        line = new GetLineUseMetrology();
                        data = line;
                    }

                    DrawMode(true);  //绘制模式开启
                    (line as GetLineUseMetrology).parameter.Line = Func_HalconFunction.DrawLine(hWindow_Final1.hWindowControl.HalconWindow);
                    DrawMode(false); //绘制模式关闭

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