コード例 #1
0
        public override void FindModel()
        {
            HImage img = InputImg;

            if (SearchRegion == null || !SearchRegion.IsInitialized())
            {
                SearchRegion = img.GetDomain();
            }

            if (createNewModelID)
            {
                if (!CreateNccModel())
                {
                    return;
                }
            }

            if (!nCCModel.IsInitialized())
            {
                throw new Exception("无创建的模板");
            }

            HRegion domain          = img.GetDomain();
            HRegion differentdomain = domain.Difference(SearchRegion);
            HImage  searchImg       = img.PaintRegion(differentdomain, 0.0, "fill");
            HImage  cropImg         = searchImg.ReduceDomain(SearchRegion);

            domain.Dispose();
            differentdomain.Dispose();

            OutputResult.Reset();


            try
            {
                double t1, t2;
                t1 = HSystem.CountSeconds();
                HOperatorSet.FindNccModel(cropImg, nCCModel, nCCParam.mStartingAngle, nCCParam.mAngleExtent, nCCParam.MinScore,
                                          nCCParam.NumMatches, nCCParam.mMaxOverlap, nCCParam.SubPixel, 0, out OutputResult.Row, out OutputResult.Col, out OutputResult.Angle, out OutputResult.Score);

                OutputResult.TemplateHand = nCCModel;
                t2 = HSystem.CountSeconds();
                OutputResult.Time  = 1000.0 * (t2 - t1);
                OutputResult.Count = OutputResult.Row.Length;
            }
            catch (HOperatorException ex)
            {
                if (ex.GetErrorCode() != 9400)
                {
                    throw ex;
                }
            }

            searchImg.Dispose();
            cropImg.Dispose();
        }
コード例 #2
0
        public override void FindModel()
        {
            OutputResult.Reset();

            HImage img = InputImg;

            if (!img.IsInitialized() || img == null)
            {
                return;
            }

            if (SearchRegion == null || !SearchRegion.IsInitialized())
            {
                SearchRegion = img.GetDomain();
            }

            if (createNewModelID)
            {
                if (!CreateModel())
                {
                    return;
                }
            }

            if (!shapeModel.IsInitialized())
            {
                throw new Exception("无创建的模板");
            }

            if (!img.IsInitialized())
            {
                throw new Exception("图片无效");
            }

            //HRegion domain = img.GetDomain();
            //HRegion differentdomain = domain.Difference(SearchRegion);
            //HImage searchImg = img.PaintRegion(differentdomain, 0.0, "fill");
            //HImage cropImg = searchImg.ReduceDomain(SearchRegion);
            //domain.Dispose();
            //differentdomain.Dispose();

            HImage cropImg = img.ReduceDomain(SearchRegion);

            try
            {
                double t1, t2;
                t1 = HSystem.CountSeconds();
                HOperatorSet.FindScaledShapeModel(cropImg, shapeModel, shapeParam.mStartingAngle, shapeParam.mAngleExtent, shapeParam.mMinScale, shapeParam.mMaxScale,
                                                  shapeParam.mMinScore, shapeParam.mNumMatches, shapeParam.mMaxOverlap, shapeParam.mSubpixel, 0, shapeParam.mGreediness,
                                                  out OutputResult.Row, out OutputResult.Col, out OutputResult.Angle, out OutputResult.Scale, out OutputResult.Score);

                OutputResult.TemplateHand = shapeModel;
                t2 = HSystem.CountSeconds();
                OutputResult.Time  = 1000.0 * (t2 - t1);
                OutputResult.Count = OutputResult.Row.Length;
            }
            catch (HOperatorException ex)
            {
                if (ex.GetErrorCode() == 6001)
                {
                    //searchImg.Dispose();
                    cropImg.Dispose();
                    GC.Collect();
                    return;
                }
                if (ex.GetErrorCode() != 9400)
                {
                    throw ex;
                }
            }

            //searchImg.Dispose();
            cropImg.Dispose();
        }