コード例 #1
0
        public MatchPosition Match(Mat sample, Mat template)
        {
            MatchPosition mp = PyramidMatch(sample, template);

            mp.ImageSize = sample.Size;

            return(mp);
        }
コード例 #2
0
        public MatchPosition LineScan(Mat sample, Rectangle virticalRect, Rectangle horizontalRect)
        {
            MatchPosition mp = new MatchPosition();
            Mat           virticalTemplate   = new Mat(sample, virticalRect); //掃描方向與圖像中的線方向相反
            Mat           horizontalTemplate = new Mat(sample, horizontalRect);

            mp.X     = VirticalScan(horizontalTemplate);
            mp.Y     = HorizontalScan(virticalTemplate);
            mp.Score = 0;
            return(mp);
        }
コード例 #3
0
        MatchPosition MatchPyrDown(Mat sample, Mat template, int level)
        {
            MatchPosition mp;

            if (level <= 0)
            {
                return(CvMatch(sample, template));
            }
            else
            {
                Mat s = new Mat();
                CvInvoke.PyrDown(sample, s, Emgu.CV.CvEnum.BorderType.Default);
                Mat t = new Mat();
                CvInvoke.PyrDown(template, t, Emgu.CV.CvEnum.BorderType.Default);
                mp = MatchPyrDown(s, t, level - 1);
                s.Dispose();
                t.Dispose();
            }

            Rectangle r = new Rectangle((int)Math.Round(mp.X * 2) - 3, (int)Math.Round(mp.Y * 2) - 3, template.Cols + 6, template.Rows + 6);

            if (r.X < 0)
            {
                r.X = 0;
            }
            if (r.Y < 0)
            {
                r.Y = 0;
            }
            if (r.X + r.Width > sample.Cols)
            {
                r.Width = sample.Cols - r.X;
            }
            if (r.Y + r.Height > sample.Rows)
            {
                r.Height = sample.Rows - r.Y;
            }
            Mat level2 = new Mat(sample, r);

            MatchPosition p2 = CvMatch(level2, template);

            p2.X += r.Left;
            p2.Y += r.Top;
            return(p2);
        }
コード例 #4
0
        public MatchPosition MatchThickEdge(Mat sample, Mat template)
        {
            Mat thr1 = new Mat();

            CvInvoke.AdaptiveThreshold(template, thr1, 255, Emgu.CV.CvEnum.AdaptiveThresholdType.MeanC, Emgu.CV.CvEnum.ThresholdType.Binary, 9, 4);
            Mat sTemplate = new Mat();

            CvInvoke.GaussianBlur(thr1, sTemplate, new Size(7, 7), 0);
            thr1.Dispose();

            Mat thr2 = new Mat();

            CvInvoke.AdaptiveThreshold(sample, thr2, 255, Emgu.CV.CvEnum.AdaptiveThresholdType.MeanC, Emgu.CV.CvEnum.ThresholdType.Binary, 9, 4);
            Mat sSample = new Mat();

            CvInvoke.GaussianBlur(thr2, sSample, new Size(7, 7), 0);
            thr2.Dispose();

            OpenCV3MatchUMat matcher = new OpenCV3MatchUMat();
            MatchPosition    mp      = matcher.Match(sSample, sTemplate);

            return(mp);
        }
コード例 #5
0
        MatchPosition PyramidMatch(Mat sample, Mat template)
        {
            int  level = 0;
            Size sz    = template.Size;

            while (true)
            {
                sz.Width  = sz.Width / 2;
                sz.Height = sz.Height / 2;
                if (sz.Width * sz.Height > MinimiumArea)
                {
                    level++;
                }
                else
                {
                    break;
                }
            }
            MatchPosition mp = MatchPyrDown(sample, template, level);

            mp.X += (template.Cols) / 2.0f;
            mp.Y += (template.Rows) / 2.0f;
            return(mp);
        }