Beispiel #1
0
        private HImage GetModelImageByRectangle2(HImage inputImage, double centerRow, double centerCol, double angle, double length1, double length2, out HRegion modelregion)
        {
            HImage rtnImage = null;

            try
            {
                HRegion rectangleRegion = GenRegionHelper.GenRectangle2Region(centerRow, centerCol, angle, length1, length2);
                rtnImage    = inputImage.ReduceDomain(rectangleRegion);
                modelregion = rectangleRegion;
                return(rtnImage);
            }
            catch (Exception)
            {
                modelregion = null;
                return(rtnImage);
            }
        }
Beispiel #2
0
        public ToolResult GetResult()
        {
            string  str;
            int     width, height;
            HRegion findRegion = null;

            IsSuccess = false;
            HiPerfTimer timer = new HiPerfTimer();

            timer.Start();
            if (Image == null)
            {
                return(new ToolResult()
                {
                    ResultName = info.ToolName, Errormessage = "图像采集失败", IsSuccess = false, GetResultTime = DateTime.Now
                });
            }
            else if (NCCModel == null)
            {
                return(new ToolResult()
                {
                    ResultName = info.ToolName, Errormessage = "模板文件没有找到", IsSuccess = false, GetResultTime = DateTime.Now
                });
            }
            Image.GetImagePointer1(out str, out width, out height);
            HImage image2 = new HImage(str, width, height);

            image2 = Image.CopyImage();
            try
            {
                if (info.FindModelROIParam != null)
                {
                    if (info.FindModelROIParam.GetType() == typeof(CircleParam))
                    {
                        CircleParam circle = info.ModelROIParam as CircleParam;
                        if (circle != null)
                        {
                            findRegion = GenRegionHelper.GenCircleRegion(circle.CircleRow, circle.CircleColumn, circle.Radius);
                        }
                    }
                    else if (info.FindModelROIParam.GetType() == typeof(Rectangle1Param))
                    {
                        Rectangle1Param rectangle1 = info.ModelROIParam as Rectangle1Param;
                        if (rectangle1 != null)
                        {
                            findRegion = GenRegionHelper.GenRectangle1Region(rectangle1.RectangleStartRow, rectangle1.RectangleStartColumn, rectangle1.RectangleEndRow, rectangle1.RectangleEndColumn);
                        }
                    }
                    else if (info.FindModelROIParam.GetType() == typeof(Rectangle2Param))
                    {
                        Rectangle2Param rectangle2 = info.ModelROIParam as Rectangle2Param;
                        if (rectangle2 != null)
                        {
                            findRegion = GenRegionHelper.GenRectangle2Region(rectangle2.Rectangle2CenterRow, rectangle2.Retangle2CenterColumn, rectangle2.Retangle2Angle, rectangle2.Rectangle2Length1, rectangle2.Rectangle2Length2);
                        }
                    }
                    else if (info.FindModelROIParam.GetType() == typeof(EllipseParam))
                    {
                        EllipseParam ellipse = info.ModelROIParam as EllipseParam;
                        if (ellipse != null)
                        {
                            findRegion = GenRegionHelper.GenEllipseRegion(ellipse.EllipseCenterRow, ellipse.EllipseCenterColumn, ellipse.EllipseAngle, ellipse.EllipseRadius1, ellipse.EllipseRadius2);
                        }
                    }
                }
                if (findRegion != null)
                {
                    image2 = image2.ReduceDomain(findRegion);
                }
                HTuple modelRow, modelCol, modelAngle, modelScore;
                if (this.NCCModel != null)
                {
                    this.NCCModel.FindNccModel(image2, TransAngle.AngleToHu(info.AngleStart), TransAngle.AngleToHu(info.AngleExtent), info.MinScore, info.NumberMacths, info.MaxOverlap, info.SubPixel, info.NumLevels, out modelRow, out modelCol, out modelAngle, out modelScore
                                               );
                    if (modelScore.Length > info.NumberMacths)
                    {
                        IsSuccess = true;
                        ToolResult result = new ToolResult();
                        result.ImageModelX     = modelCol.D;
                        result.ImageModelY     = modelRow.D;
                        result.ImageModelAngle = modelAngle.D;
                        result.ResultScore     = modelScore.D;
                        result.IsSuccess       = true;
                        result.GetResultTime   = DateTime.Now;
                        this.info.ResultX      = result.ImageModelX;
                        this.info.ResultY      = result.ImageModelY;
                        this.info.ResultAngle  = result.ImageAngle;
                        result.ElapsedTime     = timer.Duration;
                        return(result);
                    }
                    else
                    {
                        return(new ToolResult()
                        {
                            Errormessage = "模板查找失败", IsSuccess = false, GetResultTime = DateTime.Now
                        });
                    }
                }
                else
                {
                    return(new ToolResult()
                    {
                        Errormessage = "模板尚未创建", IsSuccess = false, GetResultTime = DateTime.Now
                    });
                }
            }
            catch (Exception e)
            {
                WriteErrorLog("VisionTool", e.ToString());
                return(new ToolResult()
                {
                    Errormessage = "模板查找出现错误", IsSuccess = false, GetResultTime = DateTime.Now
                });
            }
        }