예제 #1
0
        public bool CreateNccModel()
        {
            try
            {
                HImage    modelImage = ModelImg.ReduceDomain(ModelRegion);
                HNCCModel model      = new HNCCModel(modelImage, nCCParam.NumLevels, nCCParam.mStartingAngle, nCCParam.mAngleExtent, nCCParam.AngleStep, nCCParam.Metric);

                if (nCCModel != null)
                {
                    nCCModel.Dispose();
                }
                nCCModel = model;

                ModelImgRow = ModelRegion.Row[0].F;
                ModelImgCol = ModelRegion.Column[0].F;

                if (TimeOutEnable)
                {
                    model.SetNccModelParam("timeout", OutTime);
                }

                createNewModelID = false;
                return(true);
            }
            catch
            {
                return(false);
            }
        }
예제 #2
0
        public void SetModelImage()
        {
            if (ModelImg != null)
            {
                ModelImg.Dispose();
            }
            ModelImg = new HImage(InputImg);

            if (SearchRegion != null)
            {
                SearchRegion.Dispose();
                SearchRegion = null;
            }

            if (ModelRegion != null)
            {
                ModelRegion.Dispose();
                ModelRegion = null;
            }

            if (nCCModel != null)
            {
                nCCModel.Dispose();
                nCCModel = null;
            }
        }
예제 #3
0
        public void ReadHalconObj(string fileName)
        {
            if (File.Exists(fileName + ".ncm"))
            {
                if (nCCModel != null)
                {
                    nCCModel.Dispose();
                }

                nCCModel = new HNCCModel(fileName + ".ncm");
            }

            if (File.Exists(fileName + "se.tif"))
            {
                if (SearchRegion != null)
                {
                    SearchRegion.Dispose();
                }
                SearchRegion = new HRegion();
                SearchRegion.ReadRegion(fileName + "se.tif");
            }

            if (File.Exists(fileName + "md.tif"))
            {
                if (ModelRegion != null)
                {
                    ModelRegion.Dispose();
                }
                ModelRegion = new HRegion();
                ModelRegion.ReadRegion(fileName + "md.tif");
            }

            if (File.Exists(fileName + ".bmp"))
            {
                if (ModelImg != null)
                {
                    ModelImg.Dispose();
                }
                ModelImg = new HImage(fileName + ".bmp");
            }

            ModelImgRow   = Convert.ToSingle(SetParam.ReadParam(fileName, "ModelImgRow", ModelImgRow.ToString()));
            ModelImgCol   = Convert.ToSingle(SetParam.ReadParam(fileName, "ModelImgCol", ModelImgCol.ToString()));
            ModelimgAng   = Convert.ToSingle(SetParam.ReadParam(fileName, "ModelimgAng", ModelimgAng.ToString()));
            TimeOutEnable = Convert.ToBoolean(SetParam.ReadParam(fileName, "TimeOutEnable", TimeOutEnable.ToString()));
            OutTime       = Convert.ToInt32(SetParam.ReadParam(fileName, "OutTime", OutTime.ToString()));
            nCCParam.ReadParam(fileName + "par.dat");

            SetOutTime(TimeOutEnable ? 0 : OutTime);
        }
예제 #4
0
 public NCCMatchTool(IToolInfo info, DisplayControl window)
 {
     this.Info     = info;
     this.Window   = window;
     this.ToolName = info.ToolName;
     try
     {
         NCCModel = new HNCCModel();
         NCCModel = ReadModelFromFile(@".//ModelMatchFile/" + info.ToolName + ".ncm");
     }
     catch (Exception e)
     {
         NCCModel = null;
         WriteErrorLog("VisionTool", e.ToString());
     }
 }
예제 #5
0
        private HNCCModel ReadModelFromFile(string filePath)
        {
            HNCCModel model = new HNCCModel();;

            try
            {
                if (File.Exists(@".//ModelMatchFile/" + filePath + ".ncm"))
                {
                    model.ReadNccModel(@".//ModelMatchFile/" + filePath + ".ncm");
                }
                else
                {
                    return(null);
                }
            }
            catch
            {
                WriteErrorLog("VisionTool", $"{ToolName}模板读取失败");
            }
            return(model);
        }
예제 #6
0
        public bool CreateMatchTool()
        {
            HImage  modelImage  = null;
            HRegion modelRegion = null;

            if (info.ModelROIParam.GetType() == typeof(CircleParam))
            {
                CircleParam circle = info.ModelROIParam as CircleParam;
                if (circle != null)
                {
                    modelImage = GetModelImageByCircle(Image.CopyImage(), circle.CircleRow, circle.CircleColumn, circle.Radius, out modelRegion);
                }
            }
            else if (info.ModelROIParam.GetType() == typeof(Rectangle1Param))
            {
                Rectangle1Param rectangle1 = info.ModelROIParam as Rectangle1Param;
                if (rectangle1 != null)
                {
                    modelImage = GetModelImageByRectangle1(Image.CopyImage(), rectangle1.RectangleStartRow, rectangle1.RectangleStartColumn, rectangle1.RectangleEndRow, rectangle1.RectangleEndColumn, out modelRegion);
                }
            }
            else if (info.ModelROIParam.GetType() == typeof(Rectangle2Param))
            {
                Rectangle2Param rectangle2 = info.ModelROIParam as Rectangle2Param;
                if (rectangle2 != null)
                {
                    modelImage = GetModelImageByRectangle2(Image.CopyImage(), rectangle2.Rectangle2CenterRow, rectangle2.Retangle2CenterColumn, rectangle2.Retangle2Angle, rectangle2.Rectangle2Length1, rectangle2.Rectangle2Length2, out modelRegion);
                }
            }
            else if (info.ModelROIParam.GetType() == typeof(EllipseParam))
            {
                EllipseParam ellipse = info.ModelROIParam as EllipseParam;
                if (ellipse != null)
                {
                    modelImage = GetModelImageByEllipse(Image.CopyImage(), ellipse.EllipseCenterRow, ellipse.EllipseCenterColumn, ellipse.EllipseAngle, ellipse.EllipseRadius1, ellipse.EllipseRadius2, out modelRegion);
                }
            }
            else
            {
                WriteErrorLog("VisionTool", info.ToolName + "模板创建失败,原因是截取图像ROI参数类型不正确");
                return(false);
            }
            HNCCModel nccModel = new HNCCModel();
            double    modelRow, modelCol;

            if (modelImage != null)
            {
                try
                {
                    nccModel.CreateNccModel(modelImage, new HTuple(info.NumLevels), TransAngle.AngleToHu(info.AngleStart), TransAngle.AngleToHu(info.AngleExtent), new HTuple(TransAngle.AngleToHu(info.AngleStep)), info._Metric.ToString());
                    modelRegion.AreaCenter(out modelRow, out modelCol);
                    info.ModelRegionRow   = modelRow;
                    info.ModelRegionCol   = modelCol;
                    info.ModelRegionAngle = 0.0;
                    this.NCCModel         = nccModel;
                    SaveModelFile(info.ToolName);
                }
                catch
                {
                    WriteErrorLog("VisionTool", info.ToolName + "模板创建失败,原因是调用Halcon对象创建函数出错");
                    return(false);
                }
            }
            else
            {
                WriteErrorLog("VisionTool", info.ToolName + "模板创建失败,原因是模板图像对象为空");
                return(false);
            }
            return(true);
        }