Пример #1
0
        /// <summary>
        /// Finds the model in the test image. If the model
        /// hasn't been created or needs to be recreated (due to
        /// user changes made to the GUI components),
        /// then the model is created first.
        /// </summary>

        public bool detectShapeModel()
        {
            string log = "detectShapeModel:";
            HTuple levels, rtmp;

            rtmp = new HTuple();
            double t2, t1;
            bool   isSuccess = false;

            if (mTestImage == null)
            {
                return(false);
            }

            //if(createNewModelID/* && !onExternalModelID*/)
            //    if(!createShapeModel())
            //        return false;

            try
            {
                tResult.isGrayModel = false;
                int secondLevel = parameterSet.mNumLevel - 2;
                secondLevel = secondLevel > 1 ? secondLevel : 1;
                levels      = new HTuple(new int[] { parameterSet.mNumLevel, secondLevel });
                t1          = HSystem.CountSeconds();
                mTestImage.FindShapeModel(ModelID,
                                          parameterSet.mStartingAngle,
                                          parameterSet.mAngleExtent,
                                          parameterSet.mMinScore,
                                          parameterSet.mNumMatches,
                                          parameterSet.mMaxOverlap,
                                          new HTuple(parameterSet.mSubpixel),
                                          levels,
                                          parameterSet.mGreediness,
                                          out tResult.mRow,
                                          out tResult.mCol,
                                          out tResult.mAngle,
                                          out tResult.mScore);

                tResult.mRow        = tResult.mRow / parameterSet.mImageSizeScale;
                tResult.mCol        = tResult.mCol / parameterSet.mImageSizeScale;
                tResult.mImageScale = parameterSet.mImageSizeScale;
                isSuccess           = tResult.mRow.Length > 0;
                if (!isSuccess && IsEnableGrayTemplate && GrayTemplate != null && GrayTemplate.IsInitialized())
                {
                    log += "ÐÎ×´Æ¥Åäʧ°Ü";
                    double row, col;
                    mTestImage.BestMatchMg(GrayTemplate, parameterSet.mMaxError, parameterSet.mSubpixel, parameterSet.mNumLevel, "all", out row, out col, out tResult.mError);
                    isSuccess = row > 0 && col > 0;
                    if (isSuccess)
                    {
                        log                += ",»Ò¶ÈÆ¥ÅäOK";
                        tResult.mRow        = row;
                        tResult.mCol        = col;
                        tResult.mAngle      = 0;
                        tResult.mScore      = 0.701;
                        tResult.isGrayModel = true;
                    }
                    else
                    {
                        tResult.mRow   = 0;
                        tResult.mCol   = 0;
                        tResult.mAngle = 0;
                        tResult.mScore = 0;
                        log           += ",»Ò¶ÈÆ¥ÅäNG,error=" + tResult.mError.ToString();
                    }

                    Logger.Pop(log);
                }
                t2 = HSystem.CountSeconds();
                //tResult.mAngle = 0;
                tResult.mTime     = 1000.0 * (t2 - t1);
                tResult.count     = tResult.mRow.Length;
                tResult.mScaleCol = tResult.mScaleRow;
            }
            catch (HOperatorException e)
            {
                if (!onTimer)
                {
                    exceptionText = e.Message;
                    NotifyParamObserver(MatchingParam.H_ERR_MESSAGE);
                }

                return(false);
            }

            NotifyIconObserver(MatchingAssistant.UPDATE_DETECTION_RESULT);
            return(isSuccess);
        }