示例#1
0
 private void btn_loadImg_Click(object sender, EventArgs e)
 {
     if (mPicBox1.LoadImg())
     {
         roi.Attach(mPicBox1.Image);
         btn_action.Visible     = true;
         btn_learn.Visible      = true;
         btn_loadMoudle.Visible = true;
         btn_save.Visible       = true;
         btn_process.Visible    = true;
         ckbox_inRoi.Visible    = true;
         copyImg = new EImageBW8();
         copyImg.SetSize(mPicBox1.Image);
         EasyImage.Copy(mPicBox1.Image, copyImg);
     }
 }
        public override bool Run(bool isTaskRun = false)
        {
            int index = config.SelectImgIndex - 1;

            if (index < 0 || index >= ParentTask.Imgs.Count)
            {
                OutputImg = InputImg = null;
                ParentTask.Imgs.Add(new ImgDictionary(Config, OutputImg, ParentTask.Events.IndexOf(this)));
                return(false);
            }
            InputImg = ParentTask.Imgs[index].Img;
            if (InputImg == null || InputImg.IsVoid)
            {
                OutputImg = null;
                ParentTask.Imgs.Add(new ImgDictionary(Config, OutputImg, ParentTask.Events.IndexOf(this)));
                return(false);
            }
            OutputImg = new EImageBW8();
            OutputImg.SetSize(InputImg);
            EasyImage.Copy(InputImg, OutputImg);
            foreach (var item in config.CfgGroup)
            {
                OutputImg = item.Run(OutputImg);
            }

            if (isTaskRun)
            {
                ParentTask.Imgs.Add(new ImgDictionary(Config, OutputImg, ParentTask.Events.IndexOf(this)));
            }
            else
            {
                ImgDictionary imgdic = ParentTask.Imgs.Find(s => { return(s.Config == Config); });
                if (imgdic != null)
                {
                    imgdic.Img = OutputImg;
                }
            }
            return(true);
        }
示例#3
0
        public override bool Run(bool isTaskRun = false)
        {
            OutputImg = new EImageBW8();
            switch (config.SelectMode)
            {
            case 0:
                if (ParentTask.SourceImg != null)
                {
                    OutputImg.SetSize(ParentTask.SourceImg);
                    EasyImage.Copy(ParentTask.SourceImg, OutputImg);
                }
                else
                {
                    OutputImg = null;
                }

                if (isTaskRun)
                {
                    ParentTask.Imgs.Add(new ImgDictionary(Config, OutputImg, ParentTask.Imgs.Count));
                }
                break;

            case 1:
                if (!File.Exists(config.ImgPath))
                {
                    return(false);
                }

                OutputImg.Load(config.ImgPath);
                if (isTaskRun)
                {
                    ParentTask.Imgs.Add(new ImgDictionary(Config, OutputImg, ParentTask.Imgs.Count));
                }
                break;

            case 2:
                if (!Directory.Exists(config.FolderPath))
                {
                    return(false);
                }
                DirectoryInfo dir = new DirectoryInfo(config.FolderPath);
                FileInfo[]    fil = dir.GetFiles("*.bmp", SearchOption.TopDirectoryOnly);
                if (fil.Length == 0)
                {
                    return(false);
                }
                if (selectImg >= fil.Length)
                {
                    selectImg = 0;
                }
                OutputImg.Load(fil[selectImg++].FullName);
                if (isTaskRun)
                {
                    ParentTask.Imgs.Add(new ImgDictionary(Config, OutputImg, ParentTask.Imgs.Count));
                }
                break;

            case 3:
                if (config.SelectCCD > 0)
                {
                    int select = config.SelectCCD - 1;
                    if (ParentTask.Cameras[select].IsConnect)
                    {
                        ImgAtt att = ParentTask.Cameras[select].Grab();
                        OutputImg = new EImageBW8();
                        OutputImg.SetImagePtr(att.ImgWidth, att.ImgHeight, att.ImgPointer);

                        if (isTaskRun)
                        {
                            ParentTask.Imgs.Add(new ImgDictionary(Config, OutputImg, ParentTask.Imgs.Count));
                        }
                    }
                    else
                    {
                        OutputImg = null;
                        return(false);
                    }
                }
                else
                {
                    OutputImg = null;
                    return(false);
                }

                break;

            default:
                return(false);
            }
            return(true);
        }
示例#4
0
        static void Main(string[] args)
        {
            int roiWidth1  = 58;
            int roiHeight1 = 39;
            int roiWidth2  = 22;
            int roiHeight2 = 130;

            imageSource = new EImageC24();
            imageSource.SetSize(768, 576);//測試其他圖之前先修改圖這邊的影像尺寸,影像尺寸須與原圖相同

            //EPatternFinder1.MaxInstances = 40;
            //EPatternFinder1.MinScore = 0.8f;

            imageSourceGray = new EImageBW8(imageSource.Width, imageSource.Height);
            EImageBW8 imgBrushed = new EImageBW8(imageSourceGray);

            //載入樣板
            //EPatternFinder1.Load(Path.Combine(di.FullName, "EasyFindTemplate1.FND"));
            EMatcher1.Load(Path.Combine(di.FullName, "EMatcherTemplate1.MCH"));
            EMatcher2.Load(Path.Combine(di.FullName, "EMatcherTemplate2.MCH"));

            FileInfo[] files = di.GetFiles("*.jpg");
            foreach (var file in files)
            {
                imageSource.Load(Path.Combine(di.FullName, file.Name));
                EasyColor.C24ToBayer(imageSource, imageSourceGray);
                EasyImage.Copy(imageSourceGray, imgBrushed);

                //Find
                //EFoundPattern[] founds = EPatternFinder1.Find(imageSourceGray);
                EMatcher1.Match(imageSourceGray);
                EMatcher2.Match(imageSourceGray);

                IntPtr   gintptr = Easy.OpenImageGraphicContext(imgBrushed);
                Graphics g       = Graphics.FromHdc(gintptr);
                //foreach (var item in founds)
                //{
                //    EPoint center = item.Center;

                //    //g.FillRectangle(new SolidBrush(Color.White)
                //    //            , (int)center.X - ((int)roiWidth / 2), (int)center.Y - ((int)roiHeight / 2)
                //    //            , roiWidth, roiHeight);

                //    item.Draw(g, new ERGBColor(255, 255, 255), 1.0f, 1.0f, 0, 0);
                //}

                foreach (var item in EMatcher1.Positions)
                {
                    EPoint center = new EPoint(item.CenterX, item.CenterY);
                    g.FillRectangle(new SolidBrush(Color.White)
                                    , (int)center.X - ((int)roiWidth1 / 2), (int)center.Y - ((int)roiHeight1 / 2)
                                    , roiWidth1, roiHeight1);
                }

                foreach (var item in EMatcher2.Positions)
                {
                    EPoint center = new EPoint(item.CenterX, item.CenterY);
                    g.FillRectangle(new SolidBrush(Color.White)
                                    , (int)center.X - ((int)roiWidth2 / 2), (int)center.Y - ((int)roiHeight2 / 2)
                                    , roiWidth2, roiHeight2);
                }

                Easy.CloseImageGraphicContext(imgBrushed, gintptr);

                imgBrushed.SaveJpeg(@"D:\" + file.Name);
            }
        }