public override VisionResult Detected(VisionImage image, Dictionary <string, VisionResult> Result = null, VisionFlow parent = null, Shape newRoi = null)
        {
            VisionResult rtn = new VisionResult();

            rtn.State = VisionResultState.WaitCal;

            try
            {
                lock (locked)
                {
                    using (VisionImage temp = new VisionImage())
                    {
                        var roi = this.ROI;
                        if (newRoi != null)
                        {
                            roi = newRoi;
                        }

                        using (HImage hImage = VisionHelper.Image(image))
                        {
                            RectangleContour rect = roi as RectangleContour;

                            using (HImage reduceImage = hImage.ReduceDomain(
                                       new HRegion(rect.Top, rect.Left,
                                                   rect.Top + rect.Height,
                                                   rect.Left + rect.Width)))
                            {
                                HTuple numLevels = new HTuple();
                                numLevels.TupleAdd(this.MaxNumLevels);
                                numLevels.TupleAdd(this.MinNumLevels);

                                HTuple row, col, scaleX, scaleY, score, angle;
                                reduceImage.FindAnisoShapeModel(this.ShapeModel,
                                                                this.StartAngle, this.EndAngle - this.StartAngle,
                                                                this.YMinScale, this.YMaxScale,
                                                                this.XMinScale, this.XMaxScale,
                                                                this.MinScore, 1, this.MaxOverlap,
                                                                this.Pixel.ToString(),
                                                                0,
                                                                this.Greediness,
                                                                out row, out col, out angle, out scaleY, out scaleX, out score);

                                if (score.Length > 0)
                                {
                                    rtn.State = VisionResultState.OK;
                                    image.Overlays.Default.AddLine
                                        (new LineContour(new PointContour(col.D - 50, row.D), new PointContour(col.D + 50, row.D)), Rgb32Value.RedColor);

                                    image.Overlays.Default.AddLine
                                        (new LineContour(new PointContour(col.D, row.D - 50), new PointContour(col.D, row.D + 50)), Rgb32Value.RedColor);
                                    rtn.Point = new PointContour(col.D, row.D);
                                    rtn.Angle = angle.TupleDeg().D;
                                    this.AddVisionResc(rtn, $"轮廓匹配成功 角度:{rtn.Angle:N3} 分数:{score[0].D:N3}");
                                }
                                else
                                {
                                    rtn.State = VisionResultState.NG;
                                    this.AddVisionResc(rtn, $"没有找到匹配模板");
                                }
                            }
                        }
                    }
                }
            }
            catch (HalconException ex)
            {
                this.AddVisionResc(rtn, $"轮廓匹配失败 {ex.GetErrorMessage()}");
            }
            return(rtn);
        }