Exemplo n.º 1
0
        public bool Run_transform(ExecuteBuffer _executeBuffer, 模板GVName_halcon Model_result, Dictionary <int, PointName> Point_temp_result, out Dictionary <int, PointName> Point_out_result, out string result_info)
        {
            HTuple x, y;
            HTuple modelangle = 0, modelregionangle = 0;

            result_info = "";
            HTuple output_x = 0, output_y = 0;

            Point_out_result = Point_temp_result;
            if (!_executeBuffer.imageBuffer.ContainsKey(this.cbb_image.SelectedItem.ToString() + ".img"))
            {
                MessageBox.Show("二值化处理: 输入图像1已经不存在,请重置设置输入图像");
                result_info = " 二值化处理: 输入图像1已经不存在,请重置设置输入图像";
                return(false);
            }
            if (_executeBuffer.imageBuffer[this.cbb_image.SelectedItem.ToString() + ".img"] == null)
            {
                MessageBox.Show("二值化处理: image1参数为空或者未赋值");
                result_info = " 二值化处理: 输入图像1已经不存在,请重置设置输入图像";
                return(false);
            }
            HObject EdgeAmplitude, EdgeAmplitude1, region, BinImage, ImageResult3, ImageResult4;
            HTuple  Min, Max, Range, Width, Height, Value, Deviation;

            HOperatorSet.GenEmptyObj(out EdgeAmplitude);
            HOperatorSet.GenEmptyObj(out EdgeAmplitude1);
            HOperatorSet.GenEmptyObj(out region);
            HOperatorSet.GenEmptyObj(out BinImage);
            HOperatorSet.GetImageSize(_executeBuffer.imageBuffer[this.cbb_image.SelectedItem.ToString() + ".img"], out Width, out Height);
            HOperatorSet.SobelAmp(_executeBuffer.imageBuffer[this.cbb_image.SelectedItem.ToString() + ".img"], out EdgeAmplitude, "sum_sqrt", 3);
            HOperatorSet.MinMaxGray(EdgeAmplitude, EdgeAmplitude, 0, out Min, out Max, out Range);
            HOperatorSet.Threshold(EdgeAmplitude, out region, 50, 255);
            HOperatorSet.RegionToBin(region, out BinImage, 1, 0, Width, Height);
            HOperatorSet.MultImage(BinImage, BinImage, out ImageResult3, 1, 0);
            HOperatorSet.MultImage(ImageResult3, ImageResult3, out ImageResult4, 1, 0);
            HOperatorSet.Intensity(ImageResult4, ImageResult4, out Value, out Deviation);
            x_get = Value;
            y_get = Deviation;
            int out_number_list = Convert.ToInt32(this.tb_outnumber.Text.ToString());

            if (Point_temp_result.ContainsKey(out_number_list))
            {
                Point_temp_result[out_number_list].点X = x_get;
                Point_temp_result[out_number_list].点Y = y_get;
            }
            else
            {
                Point_temp_result.Add(out_number_list, new PointName(output_x, output_y));
            }

            Point_out_result = Point_temp_result;


            this.label_show.Text = "x 偏移:" + x_get.ToString() + "\n" + "y偏移是:" + y_get.ToString();
            return(true);
        }
Exemplo n.º 2
0
        public void Run_transform(ExecuteBuffer _executeBuffer, 点GVName_halcon Point_result, 模板GVName_halcon Model_result, 圆GVName_halcon Circle_result, Dictionary <int, PointName> Point_temp_result, out Dictionary <int, PointName> Point_out_result)
        {
            int    number_source = this.cbb_Inputsource.SelectedIndex;
            int    number_get = Convert.ToInt32(this.tb_innumber.Text.ToString());
            HTuple x, y;
            HTuple modelangle = 0, modelregionangle = 0;
            HTuple x2, y2;
            int    inputlength1 = 0;

            Point_out_result = Point_temp_result;

            if (number_source == 0)
            {
                if (Point_result == null)
                {
                    MessageBox.Show("算术计算:  输入为空,其中没有点位");
                    return;
                }

                if (Point_result.点X.TupleLength() < 1)
                {
                    MessageBox.Show("算术计算:  输入阵列长度不够,达不到需求");
                    return;
                }
                else
                {
                    x            = Point_result.点X;
                    y            = Point_result.点Y;
                    inputlength1 = Point_result.点X.TupleLength();
                }
            }
            else if (number_source == 1)
            {
                if (Model_result == null)
                {
                    MessageBox.Show("算术计算:  输入为空,其中没有点位");
                    return;
                }

                if (Model_result.点X.TupleLength() < 1)
                {
                    MessageBox.Show("算术计算:  输入阵列长度不够,达不到需求");
                    return;
                }
                else
                {
                    x                = Model_result.点Y;
                    y                = Model_result.点X;
                    modelangle       = Model_result.角度Angle;
                    modelregionangle = Model_result.模板Angle;
                    inputlength1     = Model_result.点X.TupleLength();
                }
            }
            else if (number_source == 2)
            {
                if (Circle_result == null)
                {
                    MessageBox.Show("算术计算:  输入为空,其中没有点位");
                    return;
                }

                if (Circle_result.圆心X.TupleLength() < 1)
                {
                    MessageBox.Show("算术计算:  输入阵列长度不够,达不到需求");
                    return;
                }
                else
                {
                    x            = Circle_result.圆心X;
                    y            = Circle_result.圆心Y;
                    inputlength1 = Circle_result.圆心X.TupleLength();
                }
            }
            else
            {
                if (Point_temp_result == null)
                {
                    MessageBox.Show("算术计算:  输入为空,其中没有点位");
                    return;
                }

                if (Point_temp_result.ContainsKey(number_get))
                {
                    x            = Point_temp_result[number_get].点X;
                    y            = Point_temp_result[number_get].点Y;
                    inputlength1 = Point_temp_result[number_get].点X.TupleLength();
                }
                else
                {
                    MessageBox.Show("算术计算:  输入字典中没有该点位");
                    return;
                }
            }


            int number2      = this.cbb_inputsource2.SelectedIndex;
            int inputlength2 = 0;

            if (number2 == 0)
            {
                if (Point_temp_result == null)
                {
                    MessageBox.Show("算术计算:输入为空,其中没有点位");
                    return;
                }
                int number_get2 = Convert.ToInt32(this.txt_number2.Text.ToString());
                if (Point_temp_result.ContainsKey(number_get2))
                {
                    x2           = Point_temp_result[number_get2].点X;
                    y2           = Point_temp_result[number_get2].点Y;
                    inputlength2 = Point_temp_result[number_get2].点X.TupleLength();
                }
                else
                {
                    MessageBox.Show("算术计算:  输入字典中没有该点位");
                    return;
                }
            }
            else
            {
                x2           = Convert.ToDouble(this.tb_inputx.Text.ToString());
                y2           = Convert.ToDouble(this.tb_inputy.Text.ToString());
                inputlength2 = inputlength1;
            }


            HTuple output_x, output_y;
            int    Trans_type = this.cbb_CalcType.SelectedIndex;
            int    Calc_way   = this.cbb_CalcType.SelectedIndex;
            int    Calc_way1  = this.cbb_CalcType1.SelectedIndex;

            if (inputlength1 == inputlength2)
            {
                if (Calc_way == 0 && cbb_tri.SelectedIndex == 0)
                {
                    if (check_angle.Checked && number_source == 1)
                    {
                        output_y = x + x2 * Math.Cos(modelregionangle - modelangle);
                    }
                    else
                    {
                        output_y = x + x2 * Math.Cos(Convert.ToDouble(tb_angle.Text));
                    }
                }
                else if (Calc_way == 1 && cbb_tri.SelectedIndex == 0)
                {
                    if (check_angle.Checked && number_source == 1)
                    {
                        output_y = x - x2 * Math.Cos(modelregionangle - modelangle);
                    }
                    else
                    {
                        output_y = x - x2 * Math.Cos(Convert.ToDouble(tb_angle.Text));
                    }
                }
                else if (Calc_way == 2 && cbb_tri.SelectedIndex == 0)
                {
                    if (check_angle.Checked && number_source == 1)
                    {
                        output_y = x2 * Math.Cos(modelregionangle - modelangle) - x;
                    }
                    else
                    {
                        output_y = x2 * Math.Cos(Convert.ToDouble(tb_angle.Text)) - x;
                    }
                }
                else if (Calc_way == 0 && cbb_tri.SelectedIndex == 1)
                {
                    if (check_angle.Checked && number_source == 1)
                    {
                        output_y = x + x2 * Math.Sin(modelregionangle - modelangle);
                    }
                    else
                    {
                        output_y = x + x2 * Math.Sin(Convert.ToDouble(tb_angle.Text));
                    }
                }
                else if (Calc_way == 1 && cbb_tri.SelectedIndex == 1)
                {
                    if (check_angle.Checked && number_source == 1)
                    {
                        output_y = x - x2 * Math.Sin(modelregionangle - modelangle);
                    }
                    else
                    {
                        output_y = x - x2 * Math.Sin(Convert.ToDouble(tb_angle.Text));
                    }
                }
                else
                {
                    if (check_angle.Checked && number_source == 1)
                    {
                        output_y = x2 * Math.Sin(modelregionangle - modelangle) - x;
                    }
                    else
                    {
                        output_y = x2 * Math.Sin(Convert.ToDouble(tb_angle.Text)) - x;
                    }
                }



                if (Calc_way1 == 0 && cbb_tri1.SelectedIndex == 0)
                {
                    if (check_angle.Checked && number_source == 1)
                    {
                        output_x = y + y2 * Math.Cos(modelregionangle - modelangle);
                    }
                    else
                    {
                        output_x = y + y2 * Math.Cos(Convert.ToDouble(tb_angle1.Text));
                    }
                }
                else if (Calc_way1 == 1 && cbb_tri1.SelectedIndex == 0)
                {
                    if (check_angle.Checked && number_source == 1)
                    {
                        output_x = y - y2 * Math.Cos(modelregionangle - modelangle);
                    }
                    else
                    {
                        output_x = y - y2 * Math.Cos(Convert.ToDouble(tb_angle1.Text));
                    }
                }
                else if (Calc_way1 == 2 && cbb_tri1.SelectedIndex == 0)
                {
                    if (check_angle.Checked && number_source == 1)
                    {
                        output_x = y2 * Math.Cos(modelregionangle - modelangle) - y;
                    }
                    else
                    {
                        output_x = y2 * Math.Cos(Convert.ToDouble(tb_angle1.Text)) - y;
                    }
                }
                else if (Calc_way1 == 0 && cbb_tri1.SelectedIndex == 1)
                {
                    if (check_angle.Checked && number_source == 1)
                    {
                        output_x = y + y2 * Math.Sin(modelregionangle - modelangle);
                    }
                    else
                    {
                        output_x = y + y2 * Math.Sin(Convert.ToDouble(tb_angle1.Text));
                    }
                }
                else if (Calc_way1 == 1 && cbb_tri1.SelectedIndex == 1)
                {
                    if (check_angle.Checked && number_source == 1)
                    {
                        output_x = y - y2 * Math.Sin(modelregionangle - modelangle);
                    }
                    else
                    {
                        output_x = y - y2 * Math.Sin(Convert.ToDouble(tb_angle1.Text));
                    }
                }
                else
                {
                    if (check_angle.Checked && number_source == 1)
                    {
                        output_x = y2 * Math.Sin(modelregionangle - modelangle) - y;
                    }
                    else
                    {
                        output_x = y2 * Math.Sin(Convert.ToDouble(tb_angle1.Text)) - y;
                    }
                }



                int out_number_list = Convert.ToInt32(this.tb_outnumber.Text.ToString());
                if (Point_temp_result.ContainsKey(out_number_list))
                {
                    Point_temp_result[out_number_list].点X = output_x;
                    Point_temp_result[out_number_list].点Y = output_y;
                }
                else
                {
                    Point_temp_result.Add(out_number_list, new PointName(output_x, output_y));
                }

                Point_out_result = Point_temp_result;
                this.label2.Text = "x 偏移:" + output_x.ToString() + "\n" + "y偏移是:" + output_y.ToString();
            }
        }
Exemplo n.º 3
0
        public bool MatchingModel(HObject In_Image, HTuple ModelID, out List <模板GVName> pmatest_result, out 模板GVName_halcon pmatest_result_halcon, out List <HObject> object_graphic_out, out string out_info)
        {
            HTuple hv_Rowzz, hv_Columnzz, hv_Anglezz, hv_Error;

            pmatest_result        = new List <模板GVName>();
            pmatest_result_halcon = new 模板GVName_halcon();
            object_graphic_out    = new List <HObject>();
            out_info = "";
            HHomMat2D Matrix = new HHomMat2D();
            HTuple    angleStart, angleExtent;
            double    temp1 = double.Parse(txt_angleStart.Text.ToString());

            HOperatorSet.TupleRad(temp1, out angleStart);

            double temp2 = double.Parse(txt_angleExtent.Text.ToString());

            HOperatorSet.TupleRad(temp2, out angleExtent);
            if (In_Image == null)
            {
                MessageBox.Show("形状模板匹配:    请选择输入图像");
                out_info = "形状模板匹配:    请选择输入图像";
                return(false);
            }
            if (ModelID.Length == 0)
            {
                MessageBox.Show("形状模板匹配:    请选择输入模板");
                out_info = "形状模板匹配:    请选择输入模板";
                return(false);
            }
            try
            {
                HOperatorSet.BestMatchRot(In_Image, ModelID, (HTuple)Convert.ToDouble(txt_angleStart.Text.ToString()), (HTuple)Convert.ToDouble(txt_angleExtent.Text.ToString()),
                                          (HTuple)Convert.ToDouble(txt_greydis.Text.ToString()), this.model_subPixel.SelectedItem.ToString(), out hv_Rowzz, out hv_Columnzz, out hv_Anglezz, out hv_Error);
            }

            catch (Exception)
            {
                return(false);
            }
            double Error_number = Convert.ToDouble(this.txt_maxerror.Text.ToString());

            if (hv_Error < Error_number)
            {
                //   HOperatorSet.GetShapeModelContours(out ShapeModel, ModelID, 1);
                pmatest_result_halcon.点X      = hv_Columnzz;
                pmatest_result_halcon.点Y      = hv_Rowzz;
                pmatest_result_halcon.角度Angle = hv_Anglezz;
                // pmatest_result_halcon.分数Score = hv_Score;
            }
            for (int i = 0; i < hv_Rowzz.Length; i = i + 1)
            {
                if (hv_Error < Error_number)
                {
                    HOperatorSet.VectorAngleToRigid(0, 0, 0, hv_Rowzz[i], hv_Columnzz[i], hv_Anglezz[i], out hv_MovementOfObject);
                    //    HOperatorSet.AffineTransContourXld(ShapeModel, out ho_ModelAtNewPosition, hv_MovementOfObject);
                    //    object_graphic_out.Add(ho_ModelAtNewPosition);

                    pmatest_result.Add(new 模板GVName(i.ToString(), hv_Columnzz[i].D.ToString("F3"), hv_Rowzz[i].D.ToString("F3"), hv_Anglezz[i].D.ToString("F3"), "1"));
                }
            }


            return(true);
        }
Exemplo n.º 4
0
        public bool Genshape(ExecuteBuffer _executeBuffer, out ExecuteBuffer outexecutebuffer, HWndCtrl hWndCtrl, 模板GVName_halcon Model_result, Dictionary <int, PointName> Point_temp_result, List <直线GVName> newline)
        {
            outexecutebuffer = _executeBuffer;
            int    x_get = 0, y_get = 0;
            double angle_get   = 0;
            bool   Model_check = false;

            HObject new_type;

            if (!_executeBuffer.imageBuffer.ContainsKey(this.cbb_image.SelectedItem.ToString() + ".img"))
            {
                MessageBox.Show("感兴趣区域:无法找到输入图像");
                return(false);
            }
            if (this.checkBox1.Checked)
            {
                if (Button_press)
                {
                    new_type = sou_regions[0].getRegion();
                }
                else
                {
                    new_type = _executeBuffer.imageBuffer[this.cbb_image.SelectedItem.ToString() + ".img"];
                }
            }
            else
            {
                if (this.checkBox_get.Checked)
                {
                    if (this.cbb_point.SelectedIndex == 0)
                    {
                        if (Model_result == null)
                        {
                            MessageBox.Show("生成ROI:匹配列表为空,请设置");
                            return(false);
                        }
                        if (Model_result.点X.TupleLength() < 1)
                        {
                            MessageBox.Show("生成ROI:匹配列表为空,请设置");
                            // result_info = " 查找直线: 匹配列表为空,请设置";
                            return(false);
                        }
                        x_get       = Convert.ToInt32(Model_result.点Y[0].D);
                        y_get       = Convert.ToInt32(Model_result.点X[0].D);
                        Model_check = true;
                    }
                    else
                    {
                        int number1 = Convert.ToInt32(this.tb_no.Text);
                        if (!Point_temp_result.ContainsKey(number1))
                        {
                            MessageBox.Show("生成ROI:全局列表点无此点,请设置");

                            return(false);
                        }
                        else
                        {
                            x_get = Convert.ToInt32(Point_temp_result[number1].点Y.D);
                            y_get = Convert.ToInt32(Point_temp_result[number1].点X.D);
                        }
                    }



                    if (this.cbb_angle.SelectedIndex == 0)
                    {
                        if (Model_check)
                        {
                            angle_get = Model_result.模板Angle[0] - Model_result.角度Angle[0];
                        }
                        else
                        {
                            if (Model_result == null)
                            {
                                MessageBox.Show("生成ROI:匹配列表为空,请设置");
                                return(false);
                            }
                            if (Model_result.点X.TupleLength() < 1)
                            {
                                MessageBox.Show("生成ROI:匹配列表为空,请设置");
                                // result_info = " 查找直线: 匹配列表为空,请设置";
                                return(false);
                            }
                            angle_get = Model_result.模板Angle[0] - Model_result.角度Angle[0];
                        }
                    }
                    else if (this.cbb_angle.SelectedIndex == 1)
                    {
                        if (newline == null)
                        {
                            MessageBox.Show("生成ROI:直线为空,请设置");
                            return(false);
                        }
                        if (newline.Count < 1)
                        {
                            MessageBox.Show("生成ROI:直线为空,请设置");
                            return(false);
                        }
                        double xrow1 = Convert.ToDouble(newline[0].点1X);
                        double xcol1 = Convert.ToDouble(newline[0].点1Y);
                        double xrow2 = Convert.ToDouble(newline[0].点2X);
                        double xcol2 = Convert.ToDouble(newline[0].点2Y);
                        angle_get = Getangle1(xrow1, xcol1, xrow2, xcol2);
                    }
                    else
                    {
                        angle_get = Convert.ToDouble(this.txt_rec2phi.Text.ToString());
                    }
                }


                outexecutebuffer = _executeBuffer;


                if (this.comboBox1.SelectedIndex == 1)
                {
                    if (!this.checkBox_get.Checked)
                    {
                        x_get = Convert.ToInt32(this.textBox_rec2row1.Text.ToString());
                        y_get = Convert.ToInt32(this.textBox_rec2col1.Text.ToString());
                    }
                    HOperatorSet.GenRectangle2(out new_type, x_get, y_get, -angle_get, Convert.ToInt32(this.textBox_rec2len1.Text.ToString()), Convert.ToInt32(this.textBox_rec2len2.Text.ToString()));
                }
                else
                {
                    if (!this.checkBox_get.Checked)
                    {
                        x_get = Convert.ToInt32(this.textBox_circlerow.Text.ToString());
                        y_get = Convert.ToInt32(this.textBox_circlecolumn.Text.ToString());
                    }
                    HOperatorSet.GenCircle(out new_type, x_get, y_get, Convert.ToInt32(this.textBox_circleradius.Text.ToString()));
                }


                if (_executeBuffer.imageBuffer[this.shape_name.Text + ".region"] != null)
                {
                    if (_executeBuffer.imageBuffer[this.shape_name.Text + ".region"].IsInitialized())
                    {
                        _executeBuffer.imageBuffer[this.shape_name.Text + ".region"].Dispose();
                    }
                }
            }

            hWndCtrl.addIconicVar(new_type);
            hWndCtrl.repaint();
            _executeBuffer.imageBuffer[this.shape_name.Text + ".region"] = new_type;
            outexecutebuffer = _executeBuffer;

            return(true);
        }
Exemplo n.º 5
0
        public bool MatchingModel(HObject In_Image, HTuple ModelID, out List <模板GVName> pmatest_result, out 模板GVName_halcon pmatest_result_halcon, out List <HObject> object_graphic_out, out string out_info)
        {
            HTuple hv_Rowzz, hv_Columnzz, hv_Anglezz, hv_Score, hv_scalezz;

            pmatest_result        = new List <模板GVName>();
            pmatest_result_halcon = new 模板GVName_halcon();
            object_graphic_out    = new List <HObject>();
            out_info = "";
            HObject   ho_ModelAtNewPosition;
            HHomMat2D Matrix = new HHomMat2D();
            HTuple    angleStart, angleExtent;
            double    temp1 = double.Parse(txt_angleStart.Text.ToString());

            HOperatorSet.TupleRad(temp1, out angleStart);

            double temp2 = double.Parse(txt_angleExtent.Text.ToString());

            HOperatorSet.TupleRad(temp2, out angleExtent);
            if (In_Image == null)
            {
                MessageBox.Show("形状模板匹配:   请先选择图像");
                out_info = "形状模板匹配:    Please Choose Picture first";
                return(false);
            }
            if (ModelID.Length == 0)
            {
                MessageBox.Show("形状模板匹配:  请先选择模板");
                out_info = "形状模板匹配: 请先选择模板";
                return(false);
            }
            try
            {
                HOperatorSet.FindScaledShapeModel(In_Image, ModelID, (HTuple)Convert.ToDouble(txt_angleStart.Text.ToString()), (HTuple)Convert.ToDouble(txt_angleExtent.Text.ToString()), Convert.ToDouble(this.txt_scaleMin.Text.ToString()),
                                                  Convert.ToDouble(this.txt_scaleMax.Text.ToString()), Convert.ToDouble(this.txt_minScore.Text.ToString()), Convert.ToDouble(this.txt_numMatches.Text.ToString()), Convert.ToDouble(this.txt_maxOverlap.Text.ToString()), this.model_subPixel.SelectedItem.ToString(),
                                                  Convert.ToInt32(this.txt_numLevels.Text.ToString()), Convert.ToDouble(this.txt_greediness.Text.ToString()), out hv_Rowzz, out hv_Columnzz, out hv_Anglezz, out hv_scalezz, out hv_Score);


                //   HOperatorSet.FindScaledShapeModel(In_Image, ModelID, (HTuple)Convert.ToDouble(txt_angleStart.Text.ToString()), angleExtent, 1, 1, 0.6, 0, 0.5, "least_squares", 0, 0.8, out hv_Rowzz, out hv_Columnzz, out hv_Anglezz, out hv_scalezz, out hv_Score);
            }

            catch (Exception)
            {
                out_info = "形状模板匹配:匹配时报错,请检查参数是否正确";
                return(false);
            }

            HOperatorSet.GetShapeModelContours(out ShapeModel, ModelID, 1);
            pmatest_result_halcon.点X      = hv_Columnzz;
            pmatest_result_halcon.点Y      = hv_Rowzz;
            pmatest_result_halcon.角度Angle = hv_Anglezz;
            pmatest_result_halcon.分数Score = hv_Score;

            for (int i = 0; i < hv_Score.Length; i = i + 1)
            {
                HOperatorSet.VectorAngleToRigid(0, 0, 0, hv_Rowzz[i], hv_Columnzz[i], hv_Anglezz[i], out hv_MovementOfObject);
                HOperatorSet.AffineTransContourXld(ShapeModel, out ho_ModelAtNewPosition, hv_MovementOfObject);
                object_graphic_out.Add(ho_ModelAtNewPosition);

                pmatest_result.Add(new 模板GVName(i.ToString(), hv_Columnzz[i].D.ToString("F3"), hv_Rowzz[i].D.ToString("F3"), hv_Anglezz[i].D.ToString("F3"), hv_Score[i].D.ToString("F3")));
            }


            return(true);
        }
Exemplo n.º 6
0
        public bool Run_transform(ExecuteBuffer _executeBuffer, 模板GVName_halcon Model_result, 圆GVName_halcon Circle_result, Dictionary <int, PointName> Point_temp_result, out Dictionary <int, PointName> Point_out_result, List <直线GVName> newline)
        {
            int    number_source = this.cbb_Inputsource.SelectedIndex;
            int    number_get = Convert.ToInt32(this.tb_innumber.Text.ToString());
            HTuple x, y;
            HTuple modelangle = 0, modelregionangle = 0;
            int    inputlength1 = 0;
            int    number_line  = Convert.ToInt32(this.txt_number2.Text);

            Point_out_result = Point_temp_result;



            if (newline == null)
            {
                //   MessageBox.Show("线线交点:直线为空,请设置");
                return(false);
            }
            if (newline.Count < 2)
            {
                //    MessageBox.Show("线线交点:直线为空,请设置");
                return(false);
            }
            if (newline.Count <= number_line)
            {
                //MessageBox.Show("线线交点:直线编号过大,请修改");
                return(false);
            }
            if (newline.Count <= number_get)
            {
                //  MessageBox.Show("线线交点:直线编号过大,请修改");
                return(false);
            }

            double xrow1a = Convert.ToDouble(newline[number_get].点1X);
            double xcol1a = Convert.ToDouble(newline[number_get].点1Y);
            double xrow2a = Convert.ToDouble(newline[number_get].点2X);
            double xcol2a = Convert.ToDouble(newline[number_get].点2Y);
            double xrow1 = Convert.ToDouble(newline[number_line].点1X);
            double xcol1 = Convert.ToDouble(newline[number_line].点1Y);
            double xrow2 = Convert.ToDouble(newline[number_line].点2X);
            double xcol2 = Convert.ToDouble(newline[number_line].点2Y);
            HTuple output_x, output_y, distance;

            HOperatorSet.IntersectionLines(xrow1, xcol1, xrow2, xcol2, xrow1a, xcol1a, xrow2a, xcol2a, out output_x, out output_y, out distance);



            int out_number_list = Convert.ToInt32(this.tb_outnumber.Text.ToString());

            if (Point_temp_result.ContainsKey(out_number_list))
            {
                Point_temp_result[out_number_list].点X = output_x;
                Point_temp_result[out_number_list].点Y = output_y;
            }
            else
            {
                Point_temp_result.Add(out_number_list, new PointName(output_x, output_y));
            }

            Point_out_result = Point_temp_result;

            this.label_show.Text = "点线距离:" + distance.ToString() + "\n" + "焦点X:" + output_x.ToString() + "\n" + "焦点y:" + output_y.ToString();
            return(true);
        }
Exemplo n.º 7
0
        public bool Run_show(ExecuteBuffer _executeBuffer, 模板GVName_halcon Model_result, Dictionary <int, PointName> Pointlist, HWndCtrl hWndCtrl, out string out_info)
        {
            int number_source = this.cbb_Inputsource.SelectedIndex;

            out_info = "";
            if (number_source == 0)
            {
                if (Model_result == null)
                {
                    MessageBox.Show("点位显示:  输入为空,其中没有点位");
                    out_info = "点位显示:  输入为空,其中没有点位";
                    return(false);
                }
                HTuple size = 10;

                if (Model_result.点X.TupleLength() > 0)
                {
                    if (linecheck.Checked)
                    {
                        HObject line_match;
                        HOperatorSet.GenEmptyObj(out line_match);
                        // HOperatorSet.GenRegionLine(out line_match, (double)Model_result.点Y[0], (double)Model_result.点X[0], (double)Model_result.点Y[1], (double)Model_result.点X[1]);
                        HOperatorSet.GenContourPolygonXld(out line_match, Model_result.点X, Model_result.点Y);
                        hWndCtrl.changeGraphicSettings(GraphicsContext.GC_COLOR, this.comboBox1.SelectedItem.ToString());
                        hWndCtrl.addIconicVar(line_match);
                        hWndCtrl.repaint();
                        out_info = "点位显示:  完成";
                        return(true);
                    }
                    else
                    {
                        HObject cross;
                        HOperatorSet.GenEmptyObj(out cross);
                        HOperatorSet.GenCrossContourXld(out cross, Model_result.点Y, Model_result.点X, size, Model_result.角度Angle);

                        hWndCtrl.changeGraphicSettings(GraphicsContext.GC_COLOR, this.comboBox1.SelectedItem.ToString());
                        hWndCtrl.addIconicVar(cross);
                        hWndCtrl.repaint();
                        out_info = "点位显示:  完成";
                        return(true);
                    }
                }
                else
                {
                    out_info = "点位显示:  没有可以显示的点位";
                }
            }
            else
            {
                int number_check = Convert.ToInt32(this.textBox1.Text.ToString());
                if (!Pointlist.ContainsKey(number_check))
                {
                    MessageBox.Show("点位显示:  输入为空,其中没有点位");
                    out_info = "点位显示:  输入为空,其中没有点位";
                    return(false);
                }
                HTuple size1 = 20;

                if (Pointlist[number_check].点X.TupleLength() > 0)
                {
                    if (linecheck.Checked)
                    {
                        HObject line;
                        HOperatorSet.GenEmptyObj(out line);
                        // HOperatorSet.GenRegionLine(out line, (double)Pointlist[number_check].点Y[0], (double)Pointlist[number_check].点X[0], (double)Pointlist[number_check].点Y[1], (double)Pointlist[number_check].点X[1]);
                        HOperatorSet.GenContourPolygonXld(out line, Pointlist[number_check].点X, Pointlist[number_check].点Y);
                        hWndCtrl.changeGraphicSettings(GraphicsContext.GC_COLOR, this.comboBox1.SelectedItem.ToString());
                        hWndCtrl.addIconicVar(line);
                        hWndCtrl.repaint();
                        out_info = "点位显示:  完成";
                        return(true);
                    }
                    else
                    {
                        HObject cross;
                        HOperatorSet.GenEmptyObj(out cross);
                        HOperatorSet.GenCrossContourXld(out cross, Pointlist[number_check].点Y, Pointlist[number_check].点X, size1, 0);

                        hWndCtrl.changeGraphicSettings(GraphicsContext.GC_COLOR, this.comboBox1.SelectedItem.ToString());
                        hWndCtrl.addIconicVar(cross);
                        hWndCtrl.repaint();
                        out_info = "点位显示:  完成";
                        return(true);
                    }
                }
                else
                {
                    out_info = "点位显示:  没有可以显示的点位";
                }
            }



            return(false);
        }
Exemplo n.º 8
0
        public bool Find_halcon_line(ExecuteBuffer _executeBuffer, HWndCtrl hWndCtrl, 模板GVName_halcon Model_result, Dictionary <int, PointName> Point_temp_result, out string result_info, out HTuple Row1, out HTuple Column1, out HTuple Row2, out HTuple Column2, bool show_info)
        {
            HTuple MetrologyHandle;
            HTuple pic_wid, pic_height;

            Row1        = new HTuple();
            Column1     = new HTuple();
            Row2        = new HTuple();
            Column2     = new HTuple();
            result_info = "";
            HOperatorSet.CreateMetrologyModel(out MetrologyHandle);
            if (!_executeBuffer.imageBuffer.ContainsKey(this.Threshold_image.SelectedItem.ToString() + ".img"))
            {
                //     MessageBox.Show("查找直线: 输入图像已经不存在,请重置设置输入图像");
                result_info = " 查找直线: 输入图像已经不存在,请重置设置输入图像";
                return(false);
            }
            if (_executeBuffer.imageBuffer[this.Threshold_image.SelectedItem.ToString() + ".img"] == null)
            {
                //     MessageBox.Show("查找直线: image参数为空或者未赋值");
                result_info = " 查找直线: 输入图像已经不存在,请重置设置输入图像";
                return(false);
            }
            HObject imagein = _executeBuffer.imageBuffer[this.Threshold_image.SelectedItem.ToString() + ".img"];

            HOperatorSet.GetImageSize(imagein, out pic_wid, out pic_height);
            HOperatorSet.SetMetrologyModelImageSize(MetrologyHandle, pic_wid, pic_height);
            HTuple Index;
            HTuple trow1, trow2, tcol1, tcol2;

            if (checkBox_line.Checked)
            {
                if (xrow1 == null || xrow2 == null || xcol1 == null || xcol2 == null)
                {
                    //    MessageBox.Show("查找直线:未确认线位置");
                    result_info = " 查找直线: 未确认线位置";
                    return(false);
                }
                else
                {
                    trow1 = xrow1;
                    tcol1 = xcol1;
                    trow2 = xrow2;
                    tcol2 = xcol2;
                }
            }
            else
            {
                if (this.cbb_source1.SelectedIndex == 0)
                {
                    if (Model_result == null)
                    {
                        //      MessageBox.Show("查找直线:匹配列表为空,请设置");
                        result_info = " 查找直线: 匹配列表为空,请设置";
                        return(false);
                    }
                    if (Model_result.点X.TupleLength() < 1)
                    {
                        //    MessageBox.Show("查找直线:匹配列表为空,请设置");
                        result_info = " 查找直线: 匹配列表为空,请设置";
                        return(false);
                    }
                    trow1 = Model_result.点Y[0];
                    tcol1 = Model_result.点X[0];
                }
                else
                {
                    int number1 = Convert.ToInt32(this.tb_value1.Text);
                    if (!Point_temp_result.ContainsKey(number1))
                    {
                        //           MessageBox.Show("查找直线:全局列表点无此点,请设置");
                        result_info = " 查找直线: 全局列表无此点,请设置";
                        return(false);
                    }
                    else
                    {
                        trow1 = Point_temp_result[number1].点Y;
                        tcol1 = Point_temp_result[number1].点X;
                    }
                }
                int number2 = Convert.ToInt32(this.tb_value2.Text);
                if (!Point_temp_result.ContainsKey(number2))
                {
                    //      MessageBox.Show("查找直线:全局列表点无此点,请设置");
                    result_info = " 查找直线: 全局列表无此点,请设置";
                    return(false);
                }
                else
                {
                    trow2 = Point_temp_result[number2].点Y;
                    tcol2 = Point_temp_result[number2].点X;
                }
            }

            HOperatorSet.AddMetrologyObjectLineMeasure(MetrologyHandle, trow1, tcol1, trow2, tcol2, Convert.ToInt32(this.measure_length1.Text.ToString()), Convert.ToInt32(this.measure_length2.Text.ToString()),
                                                       1, Convert.ToInt32(this.measure_threshold.Text.ToString()), new HTuple(), new HTuple(), out Index);
            HOperatorSet.SetMetrologyObjectParam(MetrologyHandle, "all", "measure_transition", this.cbb_transition.SelectedItem.ToString());
            HOperatorSet.SetMetrologyObjectParam(MetrologyHandle, "all", "num_measures", Convert.ToInt32(this.num_measure.Text.ToString()));
            HOperatorSet.SetMetrologyObjectParam(MetrologyHandle, "all", "num_instances", 40);
            HOperatorSet.SetMetrologyObjectParam(MetrologyHandle, "all", "measure_sigma", 1);

            //HOperatorSet.SetMetrologyObjectParam(MetrologyHandle,"all","measure_threshold",50);
            HOperatorSet.SetMetrologyObjectParam(MetrologyHandle, "all", "measure_interpolation", "bicubic");
            HOperatorSet.SetMetrologyObjectParam(MetrologyHandle, "all", "measure_select", this.cbb_measure_select.SelectedItem.ToString());
            HOperatorSet.SetMetrologyObjectParam(MetrologyHandle, "all", "min_score", Convert.ToDouble(this.min_score.Text));
            HOperatorSet.ApplyMetrologyModel(imagein, MetrologyHandle);
            HObject Contours, Cross;
            HTuple  Rowx, Columnx;

            HOperatorSet.GetMetrologyObjectMeasures(out Contours, MetrologyHandle, "all", "all", out Rowx, out Columnx);
            HOperatorSet.GenCrossContourXld(out Cross, Rowx, Columnx, 6, 0.785398);
            HTuple hv_Parameter = null;

            //得到线的起点和终点坐标并显示出来
            HOperatorSet.GetMetrologyObjectResult(MetrologyHandle, "all", "all", "result_type",
                                                  "all_param", out hv_Parameter);
            if (hv_Parameter.TupleLength() == 0)
            {
                result_info = " 查找直线: 在指定位置,找直线失败";
                //      MessageBox.Show("未找到直线");
                return(false);
            }
            int line_count = hv_Parameter.TupleLength() / 4;

            double[] Row_1    = new double[line_count];
            double[] Column_1 = new double[line_count];
            double[] Row_2    = new double[line_count];
            double[] Column_2 = new double[line_count];

            for (int imx = 0; imx < line_count; imx++)
            {
                Row_1[imx]    = hv_Parameter[imx * 4 + 1].D;
                Column_1[imx] = hv_Parameter[imx * 4].D;
                Row_2[imx]    = hv_Parameter[imx * 4 + 3].D;
                Column_2[imx] = hv_Parameter[imx * 4 + 2].D;
            }
            Row1    = (HTuple)Row_1;
            Column1 = (HTuple)Column_1;
            Row2    = (HTuple)Row_2;
            Column2 = (HTuple)Column_2;

            HObject ho_Contour;

            HOperatorSet.GenEmptyObj(out ho_Contour);
            ho_Contour.Dispose();
            HOperatorSet.GetMetrologyObjectResultContour(out ho_Contour, MetrologyHandle,
                                                         "all", "all", 1.5);


            HOperatorSet.ClearMetrologyModel(MetrologyHandle);
            if (show_info)
            {
                hWndCtrl.changeGraphicSettings(GraphicsContext.GC_COLOR, this.comboBox1.SelectedItem.ToString());
                hWndCtrl.addIconicVar(Cross);
                hWndCtrl.addIconicVar(Contours);
            }
            hWndCtrl.changeGraphicSettings(GraphicsContext.GC_COLOR, this.comboBox1.SelectedItem.ToString());
            hWndCtrl.addIconicVar(ho_Contour);
            hWndCtrl.repaint();
            return(true);
        }
Exemplo n.º 9
0
        public void Run_transform(模板GVName_halcon Model_result, Dictionary <int, PointName> Point_temp_result, out Dictionary <int, PointName> Point_out_result)
        {
            int number_source = this.cbb_Inputsource.SelectedIndex;

            HTuple x, y;
            HTuple modelangle = 0, modelregionangle = 0;

            HTuple output_x = 0, output_y = 0;
            double middle_value = 0;
            double num_all      = 0;

            Point_out_result = Point_temp_result;

            if (this.comboBox2.SelectedIndex == 0)
            {
                if (number < 10)
                {
                    this.dataGridView1.Rows.Add(number.ToString(), Model_result.点X[0].D.ToString(), 0);
                    number++;
                }
                else if (number < 20 && number >= 10)
                {
                    this.dataGridView1.Rows[number - 10].Cells[2].Value = Model_result.点X[0].D.ToString();
                    number++;
                }
                else
                {
                    number = 0;


                    this.comboBox2.SelectedIndex = 1;
                    for (int i = 0; i < 10; i++)
                    {
                        middle_value = Math.Abs(Convert.ToDouble(dataGridView1.Rows[i].Cells[2].Value) - Convert.ToDouble(dataGridView1.Rows[i].Cells[1].Value)) / (Convert.ToDouble(textBox_xstart.Text) + i * Convert.ToDouble(textBox_xstep.Text));
                        num_all      = middle_value + num_all;
                    }
                    x_get   = num_all / 10;
                    num_all = 0;
                }
                middle_value = 0;
            }

            if (this.comboBox2.SelectedIndex == 1)
            {
                if (number < 10)
                {
                    this.dataGridView1.Rows[number].Cells[1].Value = Model_result.点Y[0].D.ToString();
                }
                else if (number < 20 && number >= 10)
                {
                    this.dataGridView1.Rows[number - 10].Cells[2].Value = Model_result.点Y[0].D.ToString();
                }
                else
                {
                    number = 0;
                    for (int i = 0; i < 10; i++)
                    {
                        middle_value = Math.Abs(Convert.ToDouble(dataGridView1.Rows[i].Cells[2].Value) - Convert.ToDouble(dataGridView1.Rows[i].Cells[1].Value)) / (Convert.ToDouble(textBox_ystart.Text) + i * Convert.ToDouble(textBox_ystep.Text));
                        num_all      = middle_value + num_all;
                    }
                    y_get = num_all / 10;
                    this.comboBox2.SelectedIndex = 2;
                }
                number++;
            }
            if (this.comboBox2.SelectedIndex == 2)
            {
                int out_number_list = Convert.ToInt32(this.tb_outnumber.Text.ToString());
                if (Point_temp_result.ContainsKey(out_number_list))
                {
                    Point_temp_result[out_number_list].点X = x_get;
                    Point_temp_result[out_number_list].点Y = y_get;
                }
                else
                {
                    Point_temp_result.Add(out_number_list, new PointName(output_x, output_y));
                }

                Point_out_result = Point_temp_result;
            }

            this.label_show.Text = "x 偏移:" + x_get.ToString() + "\n" + "y偏移是:" + y_get.ToString();
        }
Exemplo n.º 10
0
        public void Run_transform(ExecuteBuffer _executeBuffer, 模板GVName_halcon Model_result, 圆GVName_halcon Circle_result, Dictionary <int, PointName> Point_temp_result, out Dictionary <int, PointName> Point_out_result, List <直线GVName> newline)
        {
            int    number_source = this.cbb_Inputsource.SelectedIndex;
            int    number_get = Convert.ToInt32(this.tb_innumber.Text.ToString());
            HTuple x, y;
            HTuple modelangle = 0, modelregionangle = 0;
            int    inputlength1 = 0;
            int    number_line  = Convert.ToInt32(this.txt_number2.Text);

            Point_out_result = Point_temp_result;


            if (number_source == 0)
            {
                if (Model_result == null)
                {
                    MessageBox.Show("点线距离:  输入为空,其中没有点位");
                    return;
                }

                if (Model_result.点X.TupleLength() < 1)
                {
                    MessageBox.Show("点线距离:  输入阵列长度不够,达不到需求");
                    return;
                }
                else
                {
                    x                = Model_result.点Y;
                    y                = Model_result.点X;
                    modelangle       = Model_result.角度Angle;
                    modelregionangle = Model_result.模板Angle;
                    inputlength1     = Model_result.点X.TupleLength();
                }
            }
            else if (number_source == 1)
            {
                if (Circle_result == null)
                {
                    MessageBox.Show("点线距离:  输入为空,其中没有点位");
                    return;
                }

                if (Circle_result.圆心X.TupleLength() < 1)
                {
                    MessageBox.Show("点线距离:  输入阵列长度不够,达不到需求");
                    return;
                }
                else
                {
                    x            = Circle_result.圆心X;
                    y            = Circle_result.圆心Y;
                    inputlength1 = Circle_result.圆心X.TupleLength();
                }
            }
            else
            {
                if (Point_temp_result == null)
                {
                    MessageBox.Show("点线距离:  输入为空,其中没有点位");
                    return;
                }

                if (Point_temp_result.ContainsKey(number_get))
                {
                    x            = Point_temp_result[number_get].点X;
                    y            = Point_temp_result[number_get].点Y;
                    inputlength1 = Point_temp_result[number_get].点X.TupleLength();
                }
                else
                {
                    MessageBox.Show("点线距离:  输入字典中没有该点位");
                    return;
                }
            }

            if (newline == null)
            {
                MessageBox.Show("点线距离ROI:直线为空,请设置");
                return;
            }
            if (newline.Count < 1)
            {
                MessageBox.Show("点线距离ROI:直线为空,请设置");
                return;
            }
            if (newline.Count <= number_line)
            {
                MessageBox.Show("点线距离ROI:直线编号过大,请修改");
                return;
            }
            double xrow1 = Convert.ToDouble(newline[number_line].点1X);
            double xcol1 = Convert.ToDouble(newline[number_line].点1Y);
            double xrow2 = Convert.ToDouble(newline[number_line].点2X);
            double xcol2 = Convert.ToDouble(newline[number_line].点2Y);
            HTuple output_x, output_y, distance;

            HOperatorSet.ProjectionPl(x, y, xrow1, xcol1, xrow2, xcol2, out output_x, out output_y);
            HOperatorSet.DistancePl(x, y, xrow1, xcol1, xrow2, xcol2, out distance);

            int out_number_list = Convert.ToInt32(this.tb_outnumber.Text.ToString());

            if (Point_temp_result.ContainsKey(out_number_list))
            {
                Point_temp_result[out_number_list].点X = output_x;
                Point_temp_result[out_number_list].点Y = output_y;
            }
            else
            {
                Point_temp_result.Add(out_number_list, new PointName(output_x, output_y));
            }

            int out_number_list1 = Convert.ToInt32(this.tb_outnumber12.Text.ToString());

            if (Point_temp_result.ContainsKey(out_number_list1))
            {
                Point_temp_result[out_number_list].点X = distance;
                Point_temp_result[out_number_list].点Y = 0;
            }
            else
            {
                Point_temp_result.Add(out_number_list1, new PointName(distance, 0));
            }

            Point_out_result = Point_temp_result;

            this.label_show.Text = "点线距离:" + distance.ToString() + "\n" + "焦点X:" + output_x.ToString() + "\n" + "焦点y:" + output_y.ToString();
        }
Exemplo n.º 11
0
        public bool Find_halcon_circle(ExecuteBuffer _executeBuffer, HWndCtrl hWndCtrl, 模板GVName_halcon Model_result, Dictionary <int, PointName> Point_temp_result, out string result_info, out HTuple Row, out HTuple Column, out HTuple Radius, bool show_info)
        {
            HTuple MetrologyHandle;
            HTuple pic_wid, pic_height;

            Row         = new HTuple();
            Column      = new HTuple();
            Radius      = new HTuple();
            result_info = "";
            HOperatorSet.CreateMetrologyModel(out MetrologyHandle);
            if (!_executeBuffer.imageBuffer.ContainsKey(this.Threshold_image.SelectedItem.ToString() + ".img"))
            {
                MessageBox.Show("查找圆: 输入图像已经不存在,请重置设置输入图像");
                result_info = " 查找圆: 输入图像已经不存在,请重置设置输入图像";
                return(false);
            }
            if (_executeBuffer.imageBuffer[this.Threshold_image.SelectedItem.ToString() + ".img"] == null)
            {
                MessageBox.Show("查找圆: image参数为空或者未赋值");
                result_info = " 查找圆: 输入图像已经不存在,请重置设置输入图像";
                return(false);
            }

            /*
             * if (xrow == null || xcol == null || xradius == null)
             * {
             *  MessageBox.Show("查找圆: 未确定圆位置");
             *  result_info = " 查找圆: 未确定圆位置";
             *  return false;
             * }*/
            HObject imagein = _executeBuffer.imageBuffer[this.Threshold_image.SelectedItem.ToString() + ".img"];

            HOperatorSet.GetImageSize(imagein, out pic_wid, out pic_height);
            HOperatorSet.SetMetrologyModelImageSize(MetrologyHandle, pic_wid, pic_height);
            HTuple Index;

            HTuple trow, tcol, tradius;

            if (this.checkBox_circle.Checked)
            {
                if (xrow == null || xcol == null || xradius == null)
                {
                    MessageBox.Show("查找直线:未确认线位置");
                    result_info = " 查找直线: 未确认线位置";
                    return(false);
                }
                else if (xrow.D == 0 && xcol.D == 0 && xradius.D == 0)
                {
                    MessageBox.Show("查找直线:未确认线位置");
                    result_info = " 查找直线: 未确认线位置";
                    return(false);
                }
                else
                {
                    trow    = xrow;
                    tcol    = xcol;
                    tradius = xradius;
                }
            }
            else
            {
                tradius = Convert.ToDouble(this.textBox_radius.Text);
                if (this.cbb_source1.SelectedIndex == 0)
                {
                    if (Model_result == null)
                    {
                        MessageBox.Show("查找圆:匹配列表为空,请设置");
                        result_info = " 查找圆: 匹配列表为空,请设置";
                        return(false);
                    }
                    if (Model_result.点X.TupleLength() < 1)
                    {
                        MessageBox.Show("查找圆:匹配列表为空,请设置");
                        result_info = " 查找圆: 匹配列表为空,请设置";
                        return(false);
                    }
                    trow = Model_result.点Y[0];
                    tcol = Model_result.点X[0];
                }
                else
                {
                    int number1 = Convert.ToInt32(this.tb_value1.Text);
                    if (!Point_temp_result.ContainsKey(number1))
                    {
                        MessageBox.Show("查找圆:全局列表点无此点,请设置");
                        result_info = " 查找圆: 全局列表无此点,请设置";
                        return(false);
                    }
                    else
                    {
                        trow = Point_temp_result[number1].点Y;
                        tcol = Point_temp_result[number1].点X;
                    }
                }
            }



            HOperatorSet.AddMetrologyObjectCircleMeasure(MetrologyHandle, trow, tcol, tradius, Convert.ToInt32(this.measure_length1.Text.ToString()), Convert.ToInt32(this.measure_length2.Text.ToString()), 1, Convert.ToInt32(this.measure_threshold.Text.ToString()), new HTuple(), new HTuple(), out Index);
            //    HOperatorSet.SetMetrologyObjectParam(MetrologyHandle,"all","measure_transition","negative");
            HOperatorSet.SetMetrologyObjectParam(MetrologyHandle, "all", "measure_transition", this.cbb_transition.SelectedItem.ToString());
            HOperatorSet.SetMetrologyObjectParam(MetrologyHandle, "all", "measure_select", this.cbb_measure_select.SelectedItem.ToString());
            HOperatorSet.SetMetrologyObjectParam(MetrologyHandle, "all", "num_measures", Convert.ToInt32(this.num_measure.Text.ToString()));
            HOperatorSet.SetMetrologyObjectParam(MetrologyHandle, "all", "num_instances", 40);
            HOperatorSet.SetMetrologyObjectParam(MetrologyHandle, "all", "measure_sigma", 1);
            HOperatorSet.SetMetrologyObjectParam(MetrologyHandle, "all", "measure_interpolation", "bicubic");
            //HOperatorSet.SetMetrologyObjectParam(MetrologyHandle,"all","measure_select","all");
            HOperatorSet.SetMetrologyObjectParam(MetrologyHandle, "all", "min_score", 0.4);
            HOperatorSet.ApplyMetrologyModel(imagein, MetrologyHandle);
            HObject Contours, Cross;

            HOperatorSet.GetMetrologyObjectMeasures(out Contours, MetrologyHandle, "all", "all", out Row, out Column);
            HOperatorSet.GenCrossContourXld(out Cross, Row, Column, 6, 0.785398);
            HTuple hv_Parameter = null;

            //得到线的起点和终点坐标并显示出来
            HOperatorSet.GetMetrologyObjectResult(MetrologyHandle, "all", "all", "result_type",
                                                  "all_param", out hv_Parameter);
            if (hv_Parameter.TupleLength() == 0)
            {
                result_info = " 查找圆: 在指定位置,找圆失败";
                MessageBox.Show("未找到圆");
                return(false);
            }
            int Circle_number = hv_Parameter.TupleLength() / 3;

            double[] Row_out    = new double[Circle_number];
            double[] Column_out = new double[Circle_number];
            double[] Radius_out = new double[Circle_number];
            for (int i = 0; i < Circle_number; i++)
            {
                Row_out[i]    = hv_Parameter[i * 3 + 1].D;
                Column_out[i] = hv_Parameter[i * 3].D;
                Radius_out[i] = hv_Parameter[i * 3 + 2].D;
            }
            Row    = (HTuple)Row_out;
            Column = (HTuple)Column_out;
            Radius = (HTuple)Radius_out;

            HObject ho_Contour;

            HOperatorSet.GenEmptyObj(out ho_Contour);
            ho_Contour.Dispose();
            HOperatorSet.GetMetrologyObjectResultContour(out ho_Contour, MetrologyHandle,
                                                         "all", "all", 1.5);


            HOperatorSet.ClearMetrologyModel(MetrologyHandle);
            if (show_info)
            {
                hWndCtrl.changeGraphicSettings(GraphicsContext.GC_COLOR, this.comboBox1.SelectedItem.ToString());
                hWndCtrl.addIconicVar(Cross);
                hWndCtrl.addIconicVar(Contours);
            }
            hWndCtrl.changeGraphicSettings(GraphicsContext.GC_COLOR, this.comboBox1.SelectedItem.ToString());
            hWndCtrl.addIconicVar(ho_Contour);
            hWndCtrl.repaint();
            return(true);
        }
Exemplo n.º 12
0
        public void Run_transform(ExecuteBuffer _executeBuffer, 点GVName_halcon Point_result_halcon, 模板GVName_halcon Model_result_halcon, 圆GVName_halcon Circle_result_halcon, Dictionary <int, PointName> Point_temp_result, out Dictionary <int, PointName> Point_out_result)
        {
            int number_source = this.cbb_Inputsource.SelectedIndex;

            HTuple x, y;

            Point_out_result = Point_temp_result;
            if (number_source == 0)
            {
                if (Point_result_halcon == null)
                {
                    MessageBox.Show("坐标转换:  输入为空,其中没有点位");
                    return;
                }

                if (Point_result_halcon.点X.TupleLength() == 0)
                {
                    MessageBox.Show("坐标转换:  输入阵列长度不够,达不到需求");
                    return;
                }
                else
                {
                    x = Point_result_halcon.点X;
                    y = Point_result_halcon.点Y;
                }
            }
            else if (number_source == 1)
            {
                if (Model_result_halcon == null)
                {
                    MessageBox.Show("坐标转换:  输入为空,其中没有点位");
                    return;
                }

                if (Model_result_halcon.点X.TupleLength() == 0)
                {
                    MessageBox.Show("坐标转换:  输入阵列长度不够,达不到需求");
                    return;
                }
                else
                {
                    x = Model_result_halcon.点X;
                    y = Model_result_halcon.点Y;
                }
            }
            else if (number_source == 2)
            {
                if (Circle_result_halcon == null)
                {
                    MessageBox.Show("坐标转换:  输入为空,其中没有点位");
                    return;
                }

                if (Circle_result_halcon.圆心X.TupleLength() == 0)
                {
                    MessageBox.Show("坐标转换:  输入阵列长度不够,达不到需求");
                    return;
                }
                else
                {
                    x = Circle_result_halcon.圆心X;
                    y = Circle_result_halcon.圆心Y;
                }
            }
            else if (number_source == 3)
            {
                int number_get = Convert.ToInt32(this.tb_innumber.Text.ToString());
                if (Point_temp_result == null)
                {
                    MessageBox.Show("坐标转换:  输入为空,其中没有点位");
                    return;
                }

                if (Point_temp_result.ContainsKey(number_get))
                {
                    x = Point_temp_result[number_get].点X;
                    y = Point_temp_result[number_get].点Y;
                }
                else
                {
                    MessageBox.Show("坐标转换:  输入字典中没有该点位");
                    return;
                }
            }
            else
            {
                x = Convert.ToDouble(this.tb_inputx.Text.ToString());
                y = Convert.ToDouble(this.tb_inputy.Text.ToString());
            }

            if (this.cbb_HM_PTW.SelectedItem == null)
            {
                MessageBox.Show("坐标转换:  图像转世界为空,请设置");
                return;
            }
            if (this.cbb_HM_WTP.SelectedItem == null)
            {
                MessageBox.Show("坐标转换:  世界转图像为空,请设置");
                return;
            }
            HTuple output_x, output_y;
            int    Trans_type = this.cbb_TransType.SelectedIndex;

            if (Trans_type == 0)
            {
                HOperatorSet.AffineTransPoint2d((HTuple)_executeBuffer.controlBuffer[this.cbb_HM_PTW.SelectedItem.ToString() + ".tuple"], x, y, out output_x, out output_y);
            }
            else
            {
                HOperatorSet.AffineTransPoint2d((HTuple)_executeBuffer.controlBuffer[this.cbb_HM_WTP.SelectedItem.ToString() + ".tuple"], x, y, out output_x, out output_y);
            }

            int out_number_list = Convert.ToInt32(this.tb_outnumber.Text.ToString());

            //MessageBox.Show(""+_executeBuffer.controlBuffer[this.cbb_HM_WTP.SelectedItem.ToString()].GetType());
            if (Point_temp_result.ContainsKey(out_number_list))
            {
                Point_temp_result[out_number_list].点X = output_x;
                Point_temp_result[out_number_list].点Y = output_y;
            }
            else
            {
                Point_temp_result.Add(out_number_list, new PointName(output_x, output_y));
            }
            //this.tb_outputx.Text = output_x.ToString();
            // this.tb_outputy.Text = output_y.ToString();
            Point_out_result = Point_temp_result;
        }