Пример #1
0
        public List <EMatchPosition> MatchPattern(EROIBW8 ROIforMatching)
        {
            if (ROIforMatching == null)
            {
                throw new ArgumentNullException("ROIforMatching");
            }
            if (!isPatternLearned_)
            {
                throw new Exception("Pattern is not learned");
            }
            if (!isParametersSet_)
            {
                throw new Exception("Pattern Matching paramters is not set");
            }

            EMatcher_.Match(ROIforMatching);

            List <EMatchPosition> matchedPositions = new List <EMatchPosition>();

            for (int i = 0; i < EMatcher_.NumPositions; i++)
            {
                matchedPositions.Add(EMatcher_.GetPosition(i));
            }
            return(matchedPositions);
        }
Пример #2
0
        public Tuple <List <EMatchPosition>, List <EMatchPosition> > MatchPatterns(
            EROIBW8 EROI_forMatching)
        {
            if (EROI_forMatching == null)
            {
                throw new ArgumentNullException("ROI1forMatching");
            }
            if (!isPatternReady)
            {
                throw new Exception("Pattern is not learned");
            }
            if (!isParametersSet)
            {
                throw new Exception("Pattern Matching paramters is not set");
            }

            EMatcher1_.Match(EROI_forMatching);
            EMatcher2_.Match(EROI_forMatching);

            List <EMatchPosition> matchedPositions_1 = new List <EMatchPosition>();
            List <EMatchPosition> matchedPositions_2 = new List <EMatchPosition>();

            for (int i = 0; i < EMatcher1_.NumPositions; i++)
            {
                matchedPositions_1.Add(EMatcher1_.GetPosition(i));
            }
            for (int i = 0; i < EMatcher2_.NumPositions; i++)
            {
                matchedPositions_2.Add(EMatcher2.GetPosition(i));
            }

            isPatternMatched_ = true;
            return(new Tuple <List <EMatchPosition>, List <EMatchPosition> >(matchedPositions_1, matchedPositions_2));
        }
Пример #3
0
 private void _ShapeMatch(EROIBW8 bw8, ref List <PositionInfo> _Resultlist)
 {
     try
     {
         m_match.Match(bw8);
         for (int i = 0; i < m_match.NumPositions; i++)
         {
             PositionInfo   info = new PositionInfo();
             EMatchPosition pos  = m_match.GetPosition(i);
             info.CenterX = pos.CenterX;
             info.CenterY = pos.CenterY;
             info.angle   = pos.Angle;
             info.scaleX  = pos.ScaleX;
             info.scaleY  = pos.ScaleY;
             info.score   = pos.Score;
             _Resultlist.Add(info);
         }
     }
     catch (EException)
     {
         // Insert exception handling code here
     }
 }
Пример #4
0
        public List <PositionInfo> ShapeMatch(Bitmap bmp)
        {
            List <PositionInfo> _Resultlist = new List <PositionInfo>();

            try
            {
                string   MCH_matchFile = GlobalVar.gl_matchFileName;
                EMatcher EMatch1       = new EMatcher();
                //單反相機需要用ec24
                EImageBW8 bw8image = ConvertBitmapToEImageBW8(bmp);
                EMatch1.Load(MCH_matchFile);

                EMatch1.MaxPositions = 10;
                EMatch1.MinScore     = GlobalVar.gl_MinMatchScore * 1.00f / 100;
                EMatch1.Match(bw8image);
                for (int i = 0; i < EMatch1.NumPositions; i++)
                {
                    PositionInfo   info = new PositionInfo();
                    EMatchPosition pos  = EMatch1.GetPosition(i);
                    info.CenterX         = pos.CenterX;
                    info.CenterY         = pos.CenterY;
                    info.angle           = pos.Angle;
                    info.scaleX          = pos.ScaleX;
                    info.scaleY          = pos.ScaleY;
                    info.score           = pos.Score;
                    info.MCHPatterWidth  = EMatch1.PatternWidth;
                    info.MCHPatterHeight = EMatch1.PatternHeight;
                    _Resultlist.Add(info);
                }
                return(_Resultlist);
            }
            catch (EException)
            {
                return(new List <PositionInfo>());
            }
        }
Пример #5
0
        private void btn_action_Click(object sender, EventArgs e)
        {
            if (mPicBox1.Image == null)
            {
                return;
            }
            mPicBox1.MMatchers.Clear();
            mPicBox1.FinderPatterns.Clear();
            mPicBox1.strs.Clear();
            if (ckbox_inRoi.Checked)
            {
                switch (modleType)
                {
                case Type.None: MessageBox.Show("请先选择模板类型!");
                    break;

                case Type.Match:
                    if (match.PatternLearnt)
                    {
                        match.Match(roi);
                        mPicBox1.MMatchers.Add(match);

                        lstview_match.Items.Clear();
                        for (int i = 0; i < match.NumPositions; i++)
                        {
                            float score, centerX, centerY;
                            score   = match.GetPosition(i).Score;
                            centerX = match.GetPosition(i).CenterX + roi.OrgX;
                            centerY = match.GetPosition(i).CenterY + roi.OrgY;
                            ListViewItem item = new ListViewItem();
                            item.SubItems[0].Text = (i + 1).ToString();
                            item.SubItems.Add(score.ToString("#0.00"));
                            item.SubItems.Add((centerX).ToString("#0.00"));
                            item.SubItems.Add((centerY).ToString("#0.00"));
                            item.SubItems.Add(match.GetPosition(i).Angle.ToString("#0.00"));
                            lstview_match.Items.Add(item);

                            mPicBox1.strs.Add(new StrAttribute(score.ToString("#0.00"), Color.Coral, new Point((int)centerX, (int)centerY)));
                        }
                    }
                    else
                    {
                        MessageBox.Show("请先学习模板或者导入模板!");
                    }
                    break;

                case Type.Find:
                    if (find.LearningDone)
                    {
                        finderPatterns = find.Find(roi);
                        mPicBox1.FinderPatterns.Add(finderPatterns);

                        lstview_find.Items.Clear();
                        for (int i = 0; i < finderPatterns.Length; i++)
                        {
                            float score, centerX, centerY;
                            score   = finderPatterns[i].Score;
                            centerX = finderPatterns[i].Center.X + roi.OrgX;
                            centerY = finderPatterns[i].Center.Y + roi.OrgY;
                            ListViewItem item = new ListViewItem();
                            item.SubItems[0].Text = (i + 1).ToString();
                            item.SubItems.Add(score.ToString("#0.00"));
                            item.SubItems.Add(centerX.ToString("#0.00"));
                            item.SubItems.Add(centerY.ToString("#0.00"));
                            item.SubItems.Add(finderPatterns[i].Angle.ToString("#0.00"));
                            lstview_find.Items.Add(item);

                            mPicBox1.strs.Add(new StrAttribute(score.ToString("#0.00"), Color.Coral, new Point((int)centerX, (int)centerY)));
                        }
                    }
                    else
                    {
                        MessageBox.Show("请先学习模板或者导入模板!");
                    }
                    break;

                case Type.Ocr:
                    try
                    {
                        CodeChars      = ocr.Recognize(roi, 200, (int)EOCRClass.AllClasses);
                        lb_result.Text = CodeChars;
                    }
                    catch
                    {
                        CodeChars = "";
                    }
                    break;

                default:
                    break;
                }
            }
            else
            {
                switch (modleType)
                {
                case Type.None: MessageBox.Show("请先选择模板类型!");
                    break;

                case Type.Match:
                    if (match.PatternLearnt)
                    {
                        match.Match(mPicBox1.Image);
                        mPicBox1.MMatchers.Add(match);

                        lstview_match.Items.Clear();
                        for (int i = 0; i < match.NumPositions; i++)
                        {
                            float score, centerX, centerY;
                            score   = match.GetPosition(i).Score;
                            centerX = match.GetPosition(i).CenterX;
                            centerY = match.GetPosition(i).CenterY;
                            ListViewItem item = new ListViewItem();
                            item.SubItems[0].Text = (i + 1).ToString();
                            item.SubItems.Add(score.ToString("#0.00"));
                            item.SubItems.Add((centerX).ToString("#0.00"));
                            item.SubItems.Add((centerY).ToString("#0.00"));
                            item.SubItems.Add(match.GetPosition(i).Angle.ToString("#0.00"));
                            lstview_match.Items.Add(item);

                            mPicBox1.strs.Add(new StrAttribute(score.ToString("#0.00"), Color.Coral, new Point((int)centerX, (int)centerY)));
                        }
                    }
                    else
                    {
                        MessageBox.Show("请先学习模板或者导入模板!");
                    }
                    break;

                case Type.Find:
                    if (find.LearningDone)
                    {
                        finderPatterns = find.Find(mPicBox1.Image);
                        mPicBox1.FinderPatterns.Add(finderPatterns);

                        lstview_find.Items.Clear();
                        for (int i = 0; i < finderPatterns.Length; i++)
                        {
                            float score, centerX, centerY;
                            score   = finderPatterns[i].Score;
                            centerX = finderPatterns[i].Center.X;
                            centerY = finderPatterns[i].Center.Y;
                            ListViewItem item = new ListViewItem();
                            item.SubItems[0].Text = (i + 1).ToString();
                            item.SubItems.Add(score.ToString("#0.00"));
                            item.SubItems.Add(centerX.ToString("#0.00"));
                            item.SubItems.Add(centerY.ToString("#0.00"));
                            item.SubItems.Add(finderPatterns[i].Angle.ToString("#0.00"));
                            lstview_find.Items.Add(item);

                            mPicBox1.strs.Add(new StrAttribute(score.ToString("#0.00"), Color.Coral, new Point((int)centerX, (int)centerY)));
                        }
                    }
                    else
                    {
                        MessageBox.Show("请先学习模板或者导入模板!");
                    }
                    break;

                case Type.Ocr:
                    try
                    {
                        lb_result.Text = ocr.Recognize(mPicBox1.Image, 100, (int)EOCRClass.AllClasses);
                    }
                    catch
                    {
                        lb_result.Text = "";
                    }
                    break;

                default:
                    break;
                }
            }


            mPicBox1.Refresh();
        }
        public static bool TeachTeacherROI(
            string RecipeName,
            EuresysDoublePatternMatcher PatternMatcher_,
            PatternMatcherParameters PatternMatcherParameters_,
            EROIBW8 eROIForPatternTeaching1_,
            EROIBW8 eROIForPatternTeaching2_,
            iEuresysROI MatcherEROI,
            PointF WaferCenterPoint,
            WaferOrientation patternOrientation)
        {
            string PatternFilePath_One      = PatternMatcherParameterHelper.GetLeftPatternFilePath(RecipeName);
            string PatternFilePath_Two      = PatternMatcherParameterHelper.GetRightPatternFilePath(RecipeName);
            string PatternImageFilePath_One = PatternMatcherParameterHelper.GetLeftPatternImageFilePath(RecipeName);
            string PatternImageFilePath_Two = PatternMatcherParameterHelper.GetRightPatternImageFilePath(RecipeName);

            PatternMatcher_.TeachAndSaveEMatcher(
                PatternMatcherParameters_,
                eROIForPatternTeaching1_,
                eROIForPatternTeaching2_,
                PatternFilePath_One,
                PatternFilePath_Two,
                PatternImageFilePath_One,
                PatternImageFilePath_Two);

            if (PatternMatcher_.Pattern1.IsVoid)
            {
                goto Fail;
            }
            if (PatternMatcher_.Pattern2.IsVoid)
            {
                goto Fail;
            }

            // Match
            EROIBW8 matcherROI = MatcherEROI.GetROI(0);

            PatternMatcher_.MatchPatterns(matcherROI);

            EMatcher eMatcher1 = PatternMatcher_.EMatcher1;
            EMatcher eMatcher2 = PatternMatcher_.EMatcher2;

            if (eMatcher1.NumPositions != 1)
            {
                string errorMessage = "Pattern 1: Number of patterns matched is not equal to one";
                VisionLogger.Log(LogType.Exception, "PatternMatcherManager", errorMessage);
                VisionNotifier.AddNotification(errorMessage);
                goto Fail;
            }

            if (eMatcher2.NumPositions != 1)
            {
                string errorMessage = "Pattern 2: Number of patterns matched is not equal to one";
                VisionLogger.Log(LogType.Exception, "PatternMatcherManager", errorMessage);
                VisionNotifier.AddNotification(errorMessage);
                goto Fail;
            }

            EROIBW8 matcherEROI_1 = MatcherEROI.GetROI(0);

            float OriginalXPos_pattern1 = eMatcher1.GetPosition(0).CenterX + (matcherEROI_1.OrgX);
            float OriginalYPos_pattern1 = eMatcher1.GetPosition(0).CenterY + (matcherEROI_1.OrgY);
            float OriginalXPos_pattern2 = eMatcher2.GetPosition(0).CenterX + (matcherEROI_1.OrgX);
            float OriginalYPos_pattern2 = eMatcher2.GetPosition(0).CenterY + (matcherEROI_1.OrgY);
            float WaferCenterXPos       = WaferCenterPoint.X;
            float WaferCenterYPos       = WaferCenterPoint.Y;

            PointF p1 = new PointF(OriginalXPos_pattern1, OriginalYPos_pattern1);
            PointF p2 = new PointF(OriginalXPos_pattern2, OriginalYPos_pattern2);
            float  PatternDefaultAngleOffset = (float)CalculateAngleBetween3Points.Execute(
                p1,
                p2,
                WaferCenterPoint,
                0,
                true,
                patternOrientation);

            // Replace value
            PatternMatcherParameters_.OriginalXPos_pattern1 = OriginalXPos_pattern1;
            PatternMatcherParameters_.OriginalYPos_pattern1 = OriginalYPos_pattern1;
            PatternMatcherParameters_.OriginalXPos_pattern2 = OriginalXPos_pattern2;
            PatternMatcherParameters_.OriginalYPos_pattern2 = OriginalYPos_pattern2;
            PatternMatcherParameters_.WaferCenterXPos       = WaferCenterXPos;
            PatternMatcherParameters_.WaferCenterYPos       = WaferCenterYPos;
            PatternMatcherParameters_.DefaultAngleOffset    = PatternDefaultAngleOffset;
            return(true);

Fail:
            return(false);
        }