示例#1
0
        private void btnFindLine_Click(object sender, EventArgs e)
        {
            int selectSearchDir = 0;

            if (this.rBtn_L2R.Checked)
            {
                selectSearchDir = 0;
            }
            else if (this.rBtn_R2L.Checked)
            {
                selectSearchDir = 1;
            }
            else if (this.rBtn_U2D.Checked)
            {
                selectSearchDir = 2;
            }
            else
            {
                selectSearchDir = 3;
            }

            int selectMode = 0;

            if (this.rBtn_B2W.Checked)
            {
                selectMode = 0;
            }
            else
            {
                selectMode = 1;
            }

            RectangleContour roi = (RectangleContour)Form_Main.Instance.imageSet.Roi[0].Shape;

            VisionImage image = Form_Main.Instance.imageSet.Image;

            PointContour line_Start = new PointContour();
            PointContour line_End   = new PointContour();

            short rtn = CPKTools.FitLine(image, roi, 40.0, selectSearchDir, selectMode, ref line_Start, ref line_End);

            if (rtn == 0)
            {
                string header     = string.Format("vision{0}", this.cbxCorner.SelectedIndex);
                int    selectLine = 0;

                if (this.rBtn_HLine1.Checked)
                {
                    selectLine = 0;
                }
                else if (this.rBtn_VLine1.Checked)
                {
                    selectLine = 1;
                }

                this.cpkIni.IniWriteValue(header, string.Format("SearchDirection{0}", selectLine), selectSearchDir.ToString());
                this.cpkIni.IniWriteValue(header, string.Format("EdgePolaritySearchMode{0}", selectLine), selectMode.ToString());

                string strRoi = string.Format("{0},{1},{2},{3}", roi.Left, roi.Top, roi.Width, roi.Height);
                this.cpkIni.IniWriteValue(header, string.Format("LineROI{0}", selectLine), strRoi);
            }
            else
            {
                MessageBox.Show("直线检测失败");
            }
        }