Пример #1
0
 public St_InspectImageSetting(bool isInit = true)
 {
     LinePara          = new St_LinesParam(4);
     CirclePara        = new St_CirclesParam(true);
     VectorAngle0      = new St_VectorAngle(true);
     NowVectorAngle    = new St_VectorAngle(true);
     InspectLinePara   = new St_InsepctLinePara(2, true);
     InspectCirclePara = new St_InspectCirclePara(2, true);
     InspectRectPara   = new St_InspectRectanglePara(1, true);
 }
Пример #2
0
        public void DrawRectProcess()
        {
            ShowRoiFlag = true;
            HObject RectRegion       = new HObject();
            HTuple  RectDiv          = new HTuple();
            HObject RectImg          = new HObject();
            HObject CurBadRegion     = new HObject();
            HObject CurConnectRegion = new HObject();
            HObject CurSelectRegion  = new HObject();

            while (ShowRoiFlag)
            {
                try {
                    HOperatorSet.GenRectangle2(out RectRegion, rectRow, rectCol, rectPhi, rectWidth, rectHei);
                    HOperatorSet.Intensity(RectRegion, GrabedImg, out RectMeanGray, out RectDiv);
                    St_InspectRectanglePara RectInspPara = new St_InspectRectanglePara(1, true);
                    RectInspPara.Rows[0]       = rectRow;
                    RectInspPara.Cols[0]       = rectCol;
                    RectInspPara.Phis[0]       = rectPhi;
                    RectInspPara.Widths[0]     = rectWidth;
                    RectInspPara.Heights[0]    = rectHei;
                    RectInspPara.MeanGrays[0]  = RectMeanGray.D;
                    RectInspPara.GrayRanges[0] = DetectHeight;
                    double DarkThd = AddR;
                    RectInspPara.DarkGrayRanges[0] = DarkThd;
                    MyVisionBase.DetetctRectangles(GrabedImg, RectInspPara, out CurSelectRegion, out RectRegion);
                    //HOperatorSet.ReduceDomain(GrabedImg, RectRegion, out RectImg);
                    //double thershold=RectMeanGray.D + DetectHeight;
                    //thershold=thershold<=255?thershold:255;
                    //HOperatorSet.Threshold(RectImg, out  CurBadRegion, thershold, 255);
                    //HOperatorSet.Connection(CurBadRegion, out CurConnectRegion);  //区域连接
                    //if (Threshold < 10) Threshold = 10;
                    //HOperatorSet.SelectShape(CurConnectRegion, out CurSelectRegion, "area", "and", Threshold, 10000000);  //
                    this.myView.ResetWindow();
                    this.myView.AddImage(GrabedImg);
                    this.myView.SetDraw("green");
                    this.myView.AddViewObject(RectRegion);
                    this.myView.Repaint();
                    Thread.Sleep(100);
                    this.myView.SetDraw("red");
                    this.myView.AddViewObject(CurSelectRegion);
                    this.myView.Repaint();
                    Thread.Sleep(200);
                }
                catch (Exception e0) {
                    MessageBox.Show(e0.Message + e0.Source);
                    //StartTeachBtn1.Enabled = true;
                    break;
                }
            }
        }
Пример #3
0
        public static bool LineCircleRectInsp(HObject ImgIn, St_InspectImageSetting LineCircleRectParaIn, out HObject DetectContours, out HObject BadRegions)
        {
            bool LineIsOK = true, CircleIsOk = true, RectIsOk = true;
            St_InspectImageSetting ImgInspectPara0 = LineCircleRectParaIn;

            HOperatorSet.GenEmptyObj(out BadRegions);
            HOperatorSet.GenEmptyObj(out DetectContours);
            //3.1直线区域检测
            HObject LineBadRegions = new HObject(), DetectLineContours = new HObject();

            HOperatorSet.GenEmptyObj(out LineBadRegions);
            HOperatorSet.GenEmptyObj(out DetectLineContours);
            LineIsOK = MyVisionBase.DectectLines(ImgIn, ImgInspectPara0.InspectLinePara, out LineBadRegions, out DetectLineContours);
            HOperatorSet.ConcatObj(BadRegions, LineBadRegions, out BadRegions);
            HOperatorSet.ConcatObj(DetectLineContours, DetectContours, out DetectContours);
            //3.2圆形区域检测
            HObject CircleBadRegion = new HObject(), DetectCircleContours = new HObject();

            HOperatorSet.GenEmptyObj(out CircleBadRegion);
            HOperatorSet.GenEmptyObj(out DetectCircleContours);
            CircleIsOk = MyVisionBase.DetectCircles(ImgIn, ImgInspectPara0.InspectCirclePara, out CircleBadRegion, out DetectCircleContours);
            HOperatorSet.ConcatObj(BadRegions, CircleBadRegion, out BadRegions);
            HOperatorSet.ConcatObj(DetectCircleContours, DetectContours, out DetectContours);
            //3.3矩形区域检测
            HObject RectBadRegion = new HObject(), DetectRectContours = new HObject();

            HOperatorSet.GenEmptyObj(out RectBadRegion);
            HOperatorSet.GenEmptyObj(out DetectRectContours);
            St_InspectRectanglePara NowRectPara = new St_InspectRectanglePara(ImgInspectPara0.InspectRectPara.Cols.Count(), true);

            NowRectPara = ImgInspectPara0.InspectRectPara;
            RectIsOk    = MyVisionBase.DetetctRectangles(ImgIn, ImgInspectPara0.InspectRectPara, out RectBadRegion, out DetectRectContours);
            HOperatorSet.ConcatObj(RectBadRegion, BadRegions, out BadRegions);
            HOperatorSet.ConcatObj(DetectRectContours, DetectContours, out DetectContours);
            if (LineIsOK && CircleIsOk && RectIsOk)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }