コード例 #1
0
        private int CreateModel()
        {
            if (this.CamCtrl.Cam == null)
            {
                return(-1);
            }

            byte[] bytes = this.CamCtrl.Cam.Executor.CurrentBytes;
            if (bytes == null)
            {
                return(-1);
            }

            byte[] roiImageData = new byte[this.prm.ModelWidth * this.prm.ModelHeight];
            int    rtn          = ModelFindThm.GetRoiImageData(bytes, this.CamCtrl.ImgWidth, this.CamCtrl.ImgHeight,
                                                               this.prm.ModelTopLeftX, this.prm.ModelTopLeftY, this.prm.ModelWidth, this.prm.ModelHeight, roiImageData);

            if (rtn != 0)
            {
                return(rtn);
            }

            int modelId = 0;

            rtn = ModelFindThm.CreateModel(roiImageData, this.prm.ModelWidth, this.prm.ModelHeight,
                                           this.prm.SearchTopLeftX, this.prm.SearchTopLeftY, this.prm.SearchWidth, this.prm.SearchHeight, ref modelId);
            this.prm.ModelId = modelId;

            return(rtn);
        }
コード例 #2
0
 private byte[] CaptureSearchImage(byte[] imgBytes, int imgWidth, int imgHeight)
 {
     byte[] searchImageData = new byte[modelFindPrm.SearchWidth * modelFindPrm.SearchHeight];
     ModelFindThm.GetRoiImageData(imgBytes, imgWidth, imgHeight, modelFindPrm.SearchTopLeftX,
                                  modelFindPrm.SearchTopLeftY, modelFindPrm.SearchWidth, modelFindPrm.SearchHeight, searchImageData);
     return(searchImageData);
 }
コード例 #3
0
        public byte[] GetROI(byte[] img, int imgWidth, int imgHeight)
        {
            byte[] roiImageData = new byte[ModelWidth * ModelHeight];
            int    rtn          = ModelFindThm.GetRoiImageData(img, imgWidth, imgHeight, ModelTopLeftX,
                                                               ModelTopLeftY, ModelWidth, ModelHeight, roiImageData);

            return(roiImageData);
        }
コード例 #4
0
        private int CreateGrayModel()
        {
            if (this.camera == null)
            {
                return(-1);
            }

            byte[] bytes = this.camera.Executor.CurrentBytes;
            if (bytes == null)
            {
                return(-1);
            }

            byte[] roiImageData = new byte[grayCheckPrm.ModelWidth * grayCheckPrm.ModelHeight];
            int    rtn          = ModelFindThm.GetRoiImageData(bytes, CamCtrl.ImgWidth, CamCtrl.ImgHeight,
                                                               grayCheckPrm.ModelTopLeftX, grayCheckPrm.ModelTopLeftY, grayCheckPrm.ModelWidth, grayCheckPrm.ModelHeight, roiImageData);

            if (rtn != 0)
            {
                return(rtn);
            }
            grayCheckPrm.ModelData = roiImageData;
            return(rtn);
        }
コード例 #5
0
        public void DoNext()
        {
            if (this.CamCtrl.Cam == null)
            {
                return;
            }

            switch (this.flag)
            {
            case 1:
                //create model
                this.CreateModel();
                break;

            case 2:
                double inc = (double)this.nudInc.Value;
                string msg = string.Format("Inc oldValue: {0} -> newValue: {1}", this.incBackUp, this.nudInc.Value);
                Logger.DEFAULT.Info(LogCategory.SETTING, this.GetType().Name, msg);
                PointD pos = new PointD(Machine.Instance.Robot.PosX, Machine.Instance.Robot.PosY);
                this.points[0] = new PointD(0, 0);
                this.points[1] = new PointD(0, inc);
                this.points[2] = new PointD(inc, inc);
                this.points[3] = new PointD(inc, 0);
                this.points[4] = new PointD(inc, -inc);
                this.points[5] = new PointD(0, -inc);
                this.points[6] = new PointD(-inc, -inc);
                this.points[7] = new PointD(-inc, 0);
                this.points[8] = new PointD(-inc, inc);
                this.calibBy9dPrm.PhyPtSet.Clear();
                this.calibBy9dPrm.ImgPtSet.Clear();
                foreach (var item in this.points)
                {
                    this.calibBy9dPrm.PhyPtSet.Add(item.X);
                    this.calibBy9dPrm.PhyPtSet.Add(item.Y);
                }

                int rtn = 0;
                //find model 9 times
                Task.Factory.StartNew(() =>
                {
                    for (int i = 0; i < 9; i++)
                    {
                        //to do move
                        if (Machine.Instance.Robot.ManualMovePosXYAndReply(pos.X + this.points[i].X, pos.Y + this.points[i].Y) == Result.FAILED)
                        {
                            this.err = true;
                            break;
                        }

                        Thread.Sleep(500);
                        byte[] bytes = this.CamCtrl.Cam.Executor.CurrentBytes;
                        if (bytes == null)
                        {
                            this.err = true;
                            break;
                        }

                        rtn = ModelFindThm.Match(bytes, this.CamCtrl.ImgWidth, this.CamCtrl.ImgHeight, this.prm.ModelId,
                                                 ref this.matchScore, ref this.matchX, ref this.matchY);
                        if (rtn != 0)
                        {
                            this.err = true;
                            break;
                        }

                        this.calibBy9dPrm.ImgPtSet.Add(this.matchX);
                        this.calibBy9dPrm.ImgPtSet.Add(this.matchY);

                        this.BeginUpdateMatchResult(i + 1, this.matchScore, this.matchX, this.matchY);
                        Thread.Sleep(500);
                    }
                    //Machine.Instance.Robot.MovePosXYAndReply(pos.X, pos.Y);
                    Machine.Instance.Robot.ManualMovePosXYAndReply(pos.X, pos.Y);

                    this.calibBy9dPrm.Num = 9;
                    rtn = this.calibBy9dPrm.Update();
                    if (rtn != 0)
                    {
                        this.err = true;
                    }

                    this.flag++;
                    this.BeginInvoke(new Action(() =>
                    {
                        this.UpdateByFlag();
                    }));
                });

                break;
            }

            this.flag++;
            this.UpdateByFlag();
        }
コード例 #6
0
        private void MatchTest()
        {
            double   matchScore = 0, matchPointX = 0, matchPointY = 0;
            DateTime beforeDT = System.DateTime.Now;

            this.modelFindPrm.PosInMachine    = new PointD(Machine.Instance.Robot.PosXY);
            this.modelFindPrm.TargetInMachine = new PointD(this.modelFindPrm.PosInMachine);
            this.tbTaughtLoc.Text             = this.modelFindPrm.PosInMachine.ToString();

            //0:found, -1:unfound, 1:found but out of tolerance
            int foundState = -1;

            this.tbConfidence.Text = string.Empty;
            this.tbTime.Text       = string.Empty;

            if (ModelFindThm.Match(this.camera.Executor.CurrentBytes, this.CamCtrl.ImgWidth, this.CamCtrl.ImgHeight, this.modelFindPrm.ModelId,
                                   ref matchScore, ref matchPointX, ref matchPointY) == 0)
            {
                DateTime afterDT = System.DateTime.Now;
                TimeSpan ts      = afterDT.Subtract(beforeDT);

                this.tbConfidence.Text = matchScore.ToString("f3");
                this.tbTime.Text       = string.Format("{0}ms", ts.TotalMilliseconds);

                if (matchScore > (double)this.nudAcceptThreshold.Value)
                {
                    this.modelFindPrm.MarkInImg        = new PointD(matchPointX, matchPointY);
                    this.modelFindPrm.TargetInMachine += Machine.Instance.Camera.ToMachine(this.modelFindPrm.MarkInImg);

                    if (this.modelFindPrm.IsOutOfTolerance())
                    {
                        foundState = 1;
                    }
                    else
                    {
                        foundState = 0;
                    }
                }
                else
                {
                    foundState = -1;
                }
            }
            else
            {
                foundState = -1;
            }

            if (foundState < 0)
            {
                this.tbStatus.Text      = "UnFound";
                this.tbStatus.BackColor = Color.Red;
                this.tbFoundLoc.Text    = string.Empty;
                this.tbDiff.Text        = string.Empty;
            }
            else
            {
                if (foundState == 0)
                {
                    this.tbStatus.BackColor = Color.Green;
                }
                else if (foundState == 1)
                {
                    this.tbStatus.BackColor = Color.Yellow;
                }
                this.tbStatus.Text   = "Found";
                this.tbFoundLoc.Text = this.modelFindPrm.TargetInMachine.ToString();
                this.tbDiff.Text     = (this.modelFindPrm.TargetInMachine - this.modelFindPrm.PosInMachine).ToString();
            }
        }